Changeset 109a998 in mainline
- Timestamp:
- 2011-04-30T05:52:19Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e686889c
- Parents:
- 64b5d15
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/compat/string.c
r64b5d15 r109a998 36 36 */ 37 37 static char *strzero(const char *s) { 38 for (; *s != '\0'; ++ s) ;; 38 while (*s != '\0') 39 s ++; 40 39 41 return (char*) s; 40 42 } … … 44 46 assert (src != NULL); 45 47 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; 47 58 } 48 59 … … 51 62 assert (src != NULL); 52 63 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) { 56 67 /* 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 60 77 return dest; 61 78 } … … 141 158 const unsigned char *s = mem; 142 159 143 for ( ; n != 0; -- n) {160 for (int i = 0; i < n; ++ i) { 144 161 if (*s == (unsigned char) c) { 145 162 return (void *) s; … … 216 233 /* returns true if s2 is a prefix of s1 */ 217 234 static 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 } 219 239 return *s2 == '\0'; 220 240 } … … 228 248 229 249 while (*s1 != '\0') { 230 s1 = strchr(s1, *s2);231 232 if (s1 == NULL)233 return NULL;234 235 250 if (begins_with(s1, s2)) 236 251 return (char *) s1;
Note:
See TracChangeset
for help on using the changeset viewer.