aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/SAM7S256/Include/string.h
blob: 1fb9d2d24507c6a47e3eee39e069e5da387fdf4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/* string.h standard header */
#ifndef _STRING
#define _STRING

#ifndef _SYSTEM_BUILD
#pragma system_include
#endif

#ifndef _YVALS
  #include <yvals.h>
#endif
#include <ysizet.h>
_C_STD_BEGIN

                /* macros */
#ifndef NULL
  #define NULL  _NULL
#endif /* NULL */

                /* declarations */
_C_LIB_DECL
__INTRINSIC int memcmp(const void *, const void *, size_t);
__INTRINSIC void * memcpy(void *, const void *, size_t);
__INTRINSIC void * memmove(void *, const void *, size_t);
__INTRINSIC void * memset(void *, int, size_t);
__INTRINSIC char * strcat(char *, const char *);
__INTRINSIC int strcmp(const char *, const char *);
__INTRINSIC int strcoll(const char *, const char *);
__INTRINSIC char * strcpy(char *, const char *);
__INTRINSIC size_t strcspn(const char *, const char *);
__INTRINSIC char * strerror(int);
__INTRINSIC size_t strlen(const char *);
__INTRINSIC char * strncat(char *, const char *, size_t);
__INTRINSIC int strncmp(const char *, const char *, size_t);
__INTRINSIC char * strncpy(char *, const char *, size_t);
__INTRINSIC size_t strspn(const char *, const char *);
__INTRINSIC char * strtok(char *, const char *);
__INTRINSIC size_t strxfrm(char *, const char *, size_t);
_END_C_LIB_DECL

                /* The implementations. */
_C_LIB_DECL
__INTRINSIC void *_Memchr(const void *, int, size_t);
__INTRINSIC char *_Strchr(const char *, int);
__INTRINSIC char *_Strerror(int, char *);
__INTRINSIC char *_Strpbrk(const char *, const char *);
__INTRINSIC char *_Strrchr(const char *, int);
__INTRINSIC char *_Strstr(const char *, const char *);
_END_C_LIB_DECL

/* IAR, we can't use the stratagem that Dinkum uses for memchr,... */
#ifdef __cplusplus
  __INTRINSIC const void *memchr(const void *_S, int _C, size_t _N);
  __INTRINSIC const char *strchr(const char *_S, int _C);
  __INTRINSIC const char *strpbrk(const char *_S, const char *_P);
  __INTRINSIC const char *strrchr(const char *_S, int _C);
  __INTRINSIC const char *strstr(const char *_S, const char *_P);
  __INTRINSIC void *memchr(void *_S, int _C, size_t _N);
  __INTRINSIC char *strchr(char *_S, int _C);
  __INTRINSIC char *strpbrk(char *_S, const char *_P);
  __INTRINSIC char *strrchr(char *_S, int _C);
  __INTRINSIC char *strstr(char *_S, const char *_P);
#else /* !__cplusplus */
  __INTRINSIC void *memchr(const void *_S, int _C, size_t _N);
  __INTRINSIC char *strchr(const char *_S, int _C);
  __INTRINSIC char *strpbrk(const char *_S, const char *_P);
  __INTRINSIC char *strrchr(const char *_S, int _C);
  __INTRINSIC char *strstr(const char *_S, const char *_P);
#endif /* __cplusplus */

#ifndef _NO_DEFINITIONS_IN_HEADER_FILES
                /* inlines and overloads, for C and C++ */
  _STD_BEGIN
  #ifdef __cplusplus
                /* First the const overloads for C++. */
    #pragma inline 
    const void *memchr(const void *_S, int _C, size_t _N)
    {
      return (_Memchr(_S, _C, _N)); 
    }

    #pragma inline 
    const char *strchr(const char *_S, int _C)
    {
      return (_Strchr(_S, _C)); 
    }

    #pragma inline 
    const char *strpbrk(const char *_S, const char *_P)
    {
      return (_Strpbrk(_S, _P)); 
    }

    #pragma inline 
    const char *strrchr(const char *_S, int _C)
    {
      return (_Strrchr(_S, _C)); 
    }

    #pragma inline 
    const char *strstr(const char *_S, const char *_P)
    {
      return (_Strstr(_S, _P)); 
    }
                /* Then the non-const overloads for C++. */
    #pragma inline 
    void *memchr(void *_S, int _C, size_t _N)
    {
      return (_Memchr(_S, _C, _N)); 
    }

    #pragma inline 
    char *strchr(char *_S, int _C)
    {
      return (_Strchr(_S, _C)); 
    }

    #pragma inline 
    char *strpbrk(char *_S, const char *_P)
    {
      return (_Strpbrk(_S, _P)); 
    }

    #pragma inline 
    char *strrchr(char *_S, int _C)
    {
      return (_Strrchr(_S, _C)); 
    }

    #pragma inline 
    char *strstr(char *_S, const char *_P)
    {
      return (_Strstr(_S, _P)); 
    }

  #else /* !__cplusplus */
                /* Then the overloads for C. */
    #pragma inline 
    void *memchr(const void *_S, int _C, size_t _N)
    {
      return (_Memchr(_S, _C, _N)); 
    }

    #pragma inline 
    char *strchr(const char *_S, int _C)
    {
      return (_Strchr(_S, _C)); 
    }

    #pragma inline 
    char *strpbrk(const char *_S, const char *_P)
    {
      return (_Strpbrk(_S, _P)); 
    }

    #pragma inline 
    char *strrchr(const char *_S, int _C)
    {
      return (_Strrchr(_S, _C)); 
    }

    #pragma inline 
    char *strstr(const char *_S, const char *_P)
    {
      return (_Strstr(_S, _P)); 
    }
  #endif /* __cplusplus */

  #pragma inline 
  char *strerror(int _Err)
  {
    return (_Strerror(_Err, 0)); 
  }

  #ifdef _STRING_MORE_INLINES
    #pragma inline 
    int memcmp(const void *s1, const void *s2, size_t n) 
      /* Copied from memcmp.c */
    {       /* compare unsigned char s1[n], s2[n] */
      const unsigned char *su1 = (const unsigned char *)s1;
      const unsigned char *su2 = (const unsigned char *)s2;

      for (; 0 < n; ++su1, ++su2, --n)
        if (*su1 != *su2)
          return (*su1 < *su2 ? -1 : +1);
      return (0);
    }

    #pragma inline 
    void *memcpy(void *s1, const void *s2, size_t n)
      /* Copied from memcpy.c */
    {       /* copy char s2[n] to s1[n] in any order */
      char *su1 = (char *)s1;
      const char *su2 = (const char *)s2;
  
      for (; 0 < n; ++su1, ++su2, --n)
        *su1 = *su2;
      return (s1);
    }

    #pragma inline 
    void *memset(void *s, int c, size_t n) /* Copied from memset.c */
    {       /* store c throughout unsigned char s[n] */
      const unsigned char uc = c;
      unsigned char *su = (unsigned char *)s;
        
      for (; 0 < n; ++su, --n)
        *su = uc;
      return (s);
    }

    #pragma inline 
    char *strcat(char *s1, const char *s2) /* Copied from strcat.c */
    {       /* copy char s2[] to end of s1[] */
      char *s;
  
      for (s = s1; *s != '\0'; ++s)
        ;                   /* find end of s1[] */
      for (; (*s = *s2) != '\0'; ++s, ++s2)
        ;                   /* copy s2[] to end */
      return (s1);
    }

    #pragma inline 
    int strcmp(const char *s1, const char *s2) /* Copied from strcmp.c */
    {       /* compare unsigned char s1[], s2[] */
      for (; *s1 == *s2; ++s1, ++s2)
        if (*s1 == '\0')
          return (0);
      return (*(unsigned char *)s1 < *(unsigned char *)s2
              ? -1 : +1);
    }

    #pragma inline 
    char *strcpy(char *s1, const char *s2) /* Copied from strcpy.c */
    {       /* copy char s2[] to s1[] */
      char *s = s1;
  
      for (s = s1; (*s++ = *s2++) != '\0'; )
        ;
      return (s1);
    }

    #pragma inline 
    size_t strcspn(const char *s1, const char *s2)
      /* Copied from strcspn.c */
    {       /* find index of first s1[i] that matches any s2[] */
      const char *sc1, *sc2;

      for (sc1 = s1; *sc1 != '\0'; ++sc1)
        for (sc2 = s2; *sc2 != '\0'; ++sc2)
          if (*sc1 == *sc2)
            return (sc1 - s1);
      return (sc1 - s1);    /* terminating nulls match */
    }

    #pragma inline 
    size_t strlen(const char *s) /* Copied from strlen.c */
    {       /* find length of s[] */
      const char *sc;

      for (sc = s; *sc != '\0'; ++sc)
        ;
      return (sc - s);
    }

    #pragma inline 
    char *strncat(char *s1, const char *s2, size_t n) 
      /* Copied from strncat.c */
    {       /* copy char s2[max n] to end of s1[] */
      char *s;
  
      for (s = s1; *s != '\0'; ++s)
        ;   /* find end of s1[] */
      for (; 0 < n && *s2 != '\0'; --n)
        *s++ = *s2++;       /* copy at most n chars from s2[] */
      *s = '\0';
      return (s1);
    }

    #pragma inline 
    int strncmp(const char *s1, const char *s2, size_t n) 
      /* Copied from strncmp.c */
    {       /* compare unsigned char s1[max n], s2[max n] */
      for (; 0 < n; ++s1, ++s2, --n)
        if (*s1 != *s2)
          return (  *(unsigned char *)s1
                  < *(unsigned char *)s2 ? -1 : +1);
        else if (*s1 == '\0')
          return (0);
      return (0);
    }

    #pragma inline 
    char *strncpy(char *s1, const char *s2, size_t n) 
      /* Copied from strncpy.c */
    {       /* copy char s2[max n] to s1[n] */
      char *s;
        
      for (s = s1; 0 < n && *s2 != '\0'; --n)
        *s++ = *s2++;       /* copy at most n chars from s2[] */
      for (; 0 < n; --n)
        *s++ = '\0';
      return (s1);
    }

    #pragma inline 
    size_t strspn(const char *s1, const char *s2) /* Copied from strspn.c */
    {       /* find index of first s1[i] that matches no s2[] */
      const char *sc1, *sc2;
        
      for (sc1 = s1; *sc1 != '\0'; ++sc1)
        for (sc2 = s2; ; ++sc2)
          if (*sc2 == '\0')
            return (sc1 - s1);
          else if (*sc1 == *sc2)
            break;
      return (sc1 - s1);    /* null doesn't match */
    }

    #pragma inline 
    void *_Memchr(const void *s, int c, size_t n) /* Copied from memchr.c */
    {       /* find first occurrence of c in s[n] */
      const unsigned char uc = c;
      const unsigned char *su = (const unsigned char *)s;
        
      for (; 0 < n; ++su, --n)
        if (*su == uc)
          return ((void *)su);
      return (0);
    }

    #pragma inline 
    char *_Strchr(const char *s, int c) /* Copied from strchr.c */
    {       /* find first occurrence of c in char s[] */
      const char ch = c;
        
      for (; *s != ch; ++s)
        if (*s == '\0')
          return (0);
      return ((char *)s);
    }

    #pragma inline 
    char *_Strpbrk(const char *s1, const char *s2) 
      /* Copied from strpbrk.c */
    {       /* find index of first s1[i] that matches any s2[] */
      const char *sc1, *sc2;
  
      for (sc1 = s1; *sc1 != '\0'; ++sc1)
        for (sc2 = s2; *sc2 != '\0'; ++sc2)
          if (*sc1 == *sc2)
            return ((char *)sc1);
      return (0);   /* terminating nulls match */
    }

    #pragma inline 
    char *_Strrchr(const char *s, int c) /* Copied from strrchr.c */
    {       /* find last occurrence of c in char s[] */
      const char ch = c;
      const char *sc;
  
      for (sc = 0; ; ++s)
      {     /* check another char */
        if (*s == ch)
          sc = s;
        if (*s == '\0')
          return ((char *)sc);
      }
    }

    #pragma inline 
    char *_Strstr(const char *s1, const char *s2) /* Copied from strstr.c */
    {       /* find first occurrence of s2[] in s1[] */
      if (*s2 == '\0')
        return ((char *)s1);
      for (; (s1 = _Strchr(s1, *s2)) != 0; ++s1)
      {     /* match rest of prefix */
        const char *sc1, *sc2;
          
        for (sc1 = s1, sc2 = s2; ; )
          if (*++sc2 == '\0')
            return ((char *)s1);
          else if (*++sc1 != *sc2)
            break;
      }
      return (0);
    }
  #endif /* _STRING_MORE_INLINES */
  _STD_END
#endif /* _NO_DEFINITIONS_IN_HEADER_FILES */

#endif /* _STRING */

#if defined(_STD_USING) && defined(__cplusplus)
  using _CSTD memchr; using _CSTD memcmp;
  using _CSTD memcpy; using _CSTD memmove; using _CSTD memset;
  using _CSTD strcat; using _CSTD strchr; using _CSTD strcmp;
  using _CSTD strcoll; using _CSTD strcpy; using _CSTD strcspn;
  using _CSTD strerror; using _CSTD strlen; using _CSTD strncat;
  using _CSTD strncmp; using _CSTD strncpy; using _CSTD strpbrk;
  using _CSTD strrchr; using _CSTD strspn; using _CSTD strstr;
  using _CSTD strtok; using _CSTD strxfrm;
#endif /* defined(_STD_USING) && defined(__cplusplus) */

/*
 * Copyright (c) 1992-2002 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V3.12:0576 */