Changeset 109a998 in mainline


Ignore:
Timestamp:
2011-04-30T05:52:19Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e686889c
Parents:
64b5d15
Message:

libcompat: Small changes to the <string.h> implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/compat/string.c

    r64b5d15 r109a998  
    3636 */
    3737static char *strzero(const char *s) {
    38         for (; *s != '\0'; ++ s) ;;
     38        while (*s != '\0')
     39                s ++;
     40
    3941        return (char*) s;
    4042}
     
    4446        assert (src != NULL);
    4547
    46         return (char *) memcpy(dest, src, strlen(src) + 1);
     48        char *dptr = dest;
     49
     50        while (*src != '\0') {
     51                *dptr = *src;
     52                src ++;
     53                dptr ++;
     54        }
     55       
     56        *dptr = '\0';
     57        return dest;
    4758}
    4859
     
    5162        assert (src != NULL);
    5263
    53         size_t len = strlen(src) + 1;
    54         memcpy(dest, src, (n < len ? n : len));
    55         if (n > len) {
     64        char *dptr = dest;
     65
     66        for (int i = 0; i < n; ++ i) {
    5667                /* the standard requires that nul characters
    57                    are appended to the length of n */
    58                 memset(dest + len, '\0', n - len);
    59         }
     68                 * are appended to the length of n, in case src is shorter
     69                 */
     70                *dptr = *src;
     71                if (*src != '\0') {
     72                        src ++;
     73                }
     74                dptr ++;
     75        }
     76       
    6077        return dest;
    6178}
     
    141158        const unsigned char *s = mem;
    142159       
    143         for (; n != 0; -- n) {
     160        for (int i = 0; i < n; ++ i) {
    144161                if (*s == (unsigned char) c) {
    145162                        return (void *) s;
     
    216233/* returns true if s2 is a prefix of s1 */
    217234static bool begins_with(const char *s1, const char *s2) {
    218         for (; *s1 == *s2 && *s2 != '\0'; ++ s1, ++ s2) ;;
     235        while (*s1 == *s2 && *s2 != '\0') {
     236                s1 ++;
     237                s2 ++;
     238        }
    219239        return *s2 == '\0';
    220240}
     
    228248
    229249        while (*s1 != '\0') {
    230                 s1 = strchr(s1, *s2);
    231                
    232                 if (s1 == NULL)
    233                         return NULL;
    234                
    235250                if (begins_with(s1, s2))
    236251                        return (char *) s1;
Note: See TracChangeset for help on using the changeset viewer.