Martin v. Löwis | d63a3b8 | 2011-09-28 07:41:54 +0200 | [diff] [blame] | 1 | |
| 2 | size_t |
| 3 | UNIOP(strlen)(const UNIOP_t *u) |
| 4 | { |
| 5 | int res = 0; |
| 6 | while(*u++) |
| 7 | res++; |
| 8 | return res; |
| 9 | } |
| 10 | |
| 11 | UNIOP_t* |
| 12 | UNIOP(strcpy)(UNIOP_t *s1, const UNIOP_t *s2) |
| 13 | { |
| 14 | UNIOP_t *u = s1; |
| 15 | while ((*u++ = *s2++)); |
| 16 | return s1; |
| 17 | } |
| 18 | |
| 19 | UNIOP_t* |
| 20 | UNIOP(strncpy)(UNIOP_t *s1, const UNIOP_t *s2, size_t n) |
| 21 | { |
| 22 | UNIOP_t *u = s1; |
| 23 | while ((*u++ = *s2++)) |
| 24 | if (n-- == 0) |
| 25 | break; |
| 26 | return s1; |
| 27 | } |
| 28 | |
| 29 | UNIOP_t* |
| 30 | UNIOP(strcat)(UNIOP_t *s1, const UNIOP_t *s2) |
| 31 | { |
| 32 | UNIOP_t *u1 = s1; |
| 33 | u1 += UNIOP(strlen(u1)); |
| 34 | UNIOP(strcpy(u1, s2)); |
| 35 | return s1; |
| 36 | } |
| 37 | |
| 38 | int |
| 39 | UNIOP(strcmp)(const UNIOP_t *s1, const UNIOP_t *s2) |
| 40 | { |
| 41 | while (*s1 && *s2 && *s1 == *s2) |
| 42 | s1++, s2++; |
| 43 | if (*s1 && *s2) |
| 44 | return (*s1 < *s2) ? -1 : +1; |
| 45 | if (*s1) |
| 46 | return 1; |
| 47 | if (*s2) |
| 48 | return -1; |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | int |
| 53 | UNIOP(strncmp)(const UNIOP_t *s1, const UNIOP_t *s2, size_t n) |
| 54 | { |
| 55 | register UNIOP_t u1, u2; |
| 56 | for (; n != 0; n--) { |
| 57 | u1 = *s1; |
| 58 | u2 = *s2; |
| 59 | if (u1 != u2) |
| 60 | return (u1 < u2) ? -1 : +1; |
| 61 | if (u1 == '\0') |
| 62 | return 0; |
| 63 | s1++; |
| 64 | s2++; |
| 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | UNIOP_t* |
| 70 | UNIOP(strchr)(const UNIOP_t *s, UNIOP_t c) |
| 71 | { |
| 72 | const UNIOP_t *p; |
| 73 | for (p = s; *p; p++) |
| 74 | if (*p == c) |
| 75 | return (UNIOP_t*)p; |
| 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | UNIOP_t* |
| 80 | UNIOP(strrchr)(const UNIOP_t *s, UNIOP_t c) |
| 81 | { |
| 82 | const UNIOP_t *p; |
| 83 | p = s + UNIOP(strlen)(s); |
| 84 | while (p != s) { |
| 85 | p--; |
| 86 | if (*p == c) |
| 87 | return (UNIOP_t*)p; |
| 88 | } |
| 89 | return NULL; |
| 90 | } |
| 91 | |