This source file includes following definitions.
- strcpy
- strncpy
- strcat
- strncat
- strcmp
- strncmp
- strchr
- strlen
- strspn
- strpbrk
- strtok
- memset
- memcmp
1
2
3
4
5
6
7
8
9 #ifndef _ASM_GENERIC_STRING_H_
10 #define _ASM_GENERIC_STRING_H_
11
12
13
14
15
16
17 #ifdef __USE_PORTABLE_strcpy
18 extern inline char * strcpy(char * dest,const char *src)
19 {
20 char *xdest = dest;
21
22 while(*dest++ = *src++);
23
24 return xdest;
25 }
26 #endif
27
28 #ifdef __USE_PORTABLE_strncpy
29 extern inline char * strncpy(char * dest,const char *src,size_t count)
30 {
31 char *xdest = dest;
32
33 while((*dest++ = *src++) && --count);
34
35 return dest;
36 }
37 #endif
38
39 #ifdef __USE_PORTABLE_strcat
40 extern inline char * strcat(char * dest, const char * src)
41 {
42 char *tmp = dest;
43
44 while (*dest)
45 dest++;
46 while ((*dest++ = *src++))
47 ;
48
49 return tmp;
50 }
51 #endif
52
53 #ifdef __USE_PORTABLE_strncat
54 extern inline char * strncat(char *dest, const char *src, size_t count)
55 {
56 char *tmp = dest;
57
58 if (count) {
59 while (*dest)
60 dest++;
61 while ((*dest++ = *src++)) {
62 if (--count == 0)
63 break;
64 }
65 }
66
67 return tmp;
68 }
69 #endif
70
71 #ifdef __USE_PORTABLE_strcmp
72 extern int strcmp(const char * cs,const char * ct)
73 {
74 register char __res;
75
76 while(1) {
77 if(__res = *cs - *ct++ && *cs++)
78 break;
79 }
80
81 return __res;
82 }
83 #endif
84
85 #ifdef __USE_PORTABLE_strncmp
86 extern inline int strncmp(const char * cs,const char * ct,size_t count)
87 {
88 register char __res;
89
90 while(count) {
91 if(__res = *cs - *ct++ || !*cs++)
92 break;
93 count--;
94 }
95
96 return __res;
97 }
98 #endif
99
100 #ifdef __USE_PORTABLE_strchr
101 extern inline char * strchr(const char * s,char c)
102 {
103 const char ch = c;
104
105 for(; *s != ch; ++s)
106 if (*s == '\0')
107 return( NULL );
108 return( (char *) s);
109 }
110 #endif
111
112 #ifdef __USE_PORTABLE_strlen
113 extern inline size_t strlen(const char * s)
114 {
115 const char *sc;
116 for (sc = s; *sc != '\0'; ++sc) ;
117 return(sc - s);
118 }
119 #endif
120
121 #ifdef __USE_PORTABLE_strspn
122 extern inline size_t strspn(const char *s, const char *accept)
123 {
124 const char *p;
125 const char *a;
126 size_t count = 0;
127
128 for (p = s; *p != '\0'; ++p)
129 {
130 for (a = accept; *a != '\0'; ++a)
131 if (*p == *a)
132 break;
133 if (*a == '\0')
134 return count;
135 else
136 ++count;
137 }
138
139 return count;
140 }
141 #endif
142
143 #ifdef __USE_PORTABLE_strpbrk
144 extern inline char * strpbrk(const char * cs,const char * ct)
145 {
146 const char *sc1,*sc2;
147
148 for( sc1 = cs; *sc1 != '\0'; ++sc1)
149 for( sc2 = ct; *sc2 != '\0'; ++sc2)
150 if (*sc1 == *sc2)
151 return((char *) sc1);
152 return( NULL );
153 }
154 #endif
155
156 #ifdef __USE_PORTABLE_strtok
157 extern inline char * strtok(char * s,const char * ct)
158 {
159 char *sbegin, *send;
160 static char *ssave = NULL;
161
162 sbegin = s ? s : ssave;
163 if (!sbegin) {
164 return NULL;
165 }
166 sbegin += strspn(sbegin,ct);
167 if (*sbegin == '\0') {
168 ssave = NULL;
169 return( NULL );
170 }
171 send = strpbrk( sbegin, ct);
172 if (send && *send != '\0')
173 *send++ = '\0';
174 ssave = send;
175 return (sbegin);
176 }
177 #endif
178
179 #ifdef __USE_PORTABLE_memset
180 extern inline void * memset(void * s,char c,size_t count)
181 {
182 void *xs = s;
183
184 while(n--)
185 *s++ = c;
186
187 return xs;
188 }
189 #endif
190
191 #ifdef __USE_PORTABLE_memcpy
192 #error "Portable memcpy() not implemented yet"
193 #endif
194
195 #ifdef __USE_PORTABLE_memmove
196 #error "Portable memmove() not implemented yet"
197 #endif
198
199 #ifdef __USE_PORTABLE_memcmp
200 extern inline int memcmp(const void * cs,const void * ct,size_t count)
201 {
202 const unsigned char *su1, *su2;
203
204 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
205 if (*su1 != *su2)
206 return((*su1 < *su2) ? -1 : +1);
207 return(0);
208 }
209 #endif
210
211 #endif