blob: 06a0b4ee32473fa19b73bbf1f35938d3fed69d02 [file] [log] [blame]
Martin v. Löwisd63a3b82011-09-28 07:41:54 +02001
2size_t
3UNIOP(strlen)(const UNIOP_t *u)
4{
5 int res = 0;
6 while(*u++)
7 res++;
8 return res;
9}
10
11UNIOP_t*
12UNIOP(strcpy)(UNIOP_t *s1, const UNIOP_t *s2)
13{
14 UNIOP_t *u = s1;
15 while ((*u++ = *s2++));
16 return s1;
17}
18
19UNIOP_t*
20UNIOP(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
29UNIOP_t*
30UNIOP(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
38int
39UNIOP(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
52int
53UNIOP(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
69UNIOP_t*
70UNIOP(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
79UNIOP_t*
80UNIOP(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