Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7afb4a5 in mainline


Ignore:
Timestamp:
2009-04-09T21:28:50Z (12 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master
Children:
095003a8
Parents:
92fd52d7
Message:

Nuke strchr() and strrchr().

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/getopt.c

    r92fd52d7 r7afb4a5  
    242242        }
    243243        if ((optchar = (int)*place++) == (int)':' ||
    244             (oli = strchr(options + (IGNORE_FIRST ? 1 : 0), optchar)) == NULL) {
     244            (oli = str_chr(options + (IGNORE_FIRST ? 1 : 0), optchar)) == NULL) {
    245245                /* option letter unknown or ':' */
    246246                if (!*place)
     
    378378                        return -1;
    379379                }
    380                 if ((has_equal = strchr(current_argv, '=')) != NULL) {
     380                if ((has_equal = str_chr(current_argv, '=')) != NULL) {
    381381                        /* argument found (--option=arg) */
    382382                        current_argv_len = has_equal - current_argv;
  • uspace/lib/libc/generic/string.c

    r92fd52d7 r7afb4a5  
    536536 *
    537537 * @return Pointer to character in @a str or NULL if not found.
    538  *
    539538 */
    540539const char *str_chr(const char *str, wchar_t ch)
     
    549548       
    550549        return NULL;
     550}
     551
     552/** Find last occurence of character in string.
     553 *
     554 * @param str String to search.
     555 * @param ch  Character to look for.
     556 *
     557 * @return Pointer to character in @a str or NULL if not found.
     558 */
     559const char *str_rchr(const char *str, wchar_t ch)
     560{
     561        wchar_t acc;
     562        size_t off = 0;
     563        char *res;
     564
     565        res = NULL;
     566        while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
     567                if (acc == ch)
     568                        res = (str + off);
     569        }
     570
     571        return res;
    551572}
    552573
     
    626647       
    627648        return (tolower(a[c]) - tolower(b[c]));
    628 }
    629 
    630 /** Return pointer to the first occurence of character c in string.
    631  *
    632  * @param str           Scanned string.
    633  * @param c             Searched character (taken as one byte).
    634  * @return              Pointer to the matched character or NULL if it is not
    635  *                      found in given string.
    636  */
    637 char *strchr(const char *str, int c)
    638 {
    639         while (*str != '\0') {
    640                 if (*str == (char) c)
    641                         return (char *) str;
    642                 str++;
    643         }
    644 
    645         return NULL;
    646 }
    647 
    648 /** Return pointer to the last occurence of character c in string.
    649  *
    650  * @param str           Scanned string.
    651  * @param c             Searched character (taken as one byte).
    652  * @return              Pointer to the matched character or NULL if it is not
    653  *                      found in given string.
    654  */
    655 char *strrchr(const char *str, int c)
    656 {
    657         char *retval = NULL;
    658 
    659         while (*str != '\0') {
    660                 if (*str == (char) c)
    661                         retval = (char *) str;
    662                 str++;
    663         }
    664 
    665         return (char *) retval;
    666649}
    667650
     
    870853
    871854        /* Skip over leading delimiters. */
    872         while (*s && (strchr(delim, *s) != NULL)) ++s;
     855        while (*s && (str_chr(delim, *s) != NULL)) ++s;
    873856        start = s;
    874857
    875858        /* Skip over token characters. */
    876         while (*s && (strchr(delim, *s) == NULL)) ++s;
     859        while (*s && (str_chr(delim, *s) == NULL)) ++s;
    877860        end = s;
    878861        *next = (*s ? s + 1 : s);
  • uspace/lib/libc/include/string.h

    r92fd52d7 r7afb4a5  
    7474
    7575extern const char *str_chr(const char *str, wchar_t ch);
     76extern const char *str_rchr(const char *str, wchar_t ch);
    7677
    7778extern bool wstr_linsert(wchar_t *str, wchar_t ch, count_t pos, count_t max_pos);
     
    9293extern char *strdup(const char *);
    9394
    94 extern char *strchr(const char *, int);
    95 extern char *strrchr(const char *, int);
    96 
    9795extern long int strtol(const char *, char **, int);
    9896extern unsigned long strtoul(const char *, char **, int);
  • uspace/srv/fs/fat/fat_dentry.c

    r92fd52d7 r7afb4a5  
    6767        if (!(rc = stricmp(name, component)))
    6868                return rc;
    69         if (!strchr(name, '.')) {
     69        if (!str_chr(name, '.')) {
    7070                /*
    7171                 * There is no '.' in the name, so we know that there is enough
  • uspace/srv/loader/main.c

    r92fd52d7 r7afb4a5  
    276276       
    277277        /* Set the task name. */
    278         cp = strrchr(pathname, '/');
     278        cp = str_rchr(pathname, '/');
    279279        cp = (cp == NULL) ? pathname : (cp + 1);
    280280        task_set_name(cp);
Note: See TracChangeset for help on using the changeset viewer.