AVR-LibC  2.3.0
Standard C library for AVR-GCC
 

AVR-LibC Manual

AVR-LibC Sources

Main Page

User Manual

Lib­rary Refe­rence

FAQ

Exam­ple Pro­jects

Index

Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1/* Copyright (c) 2002,2007 Marek Michalkiewicz
2 All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in
12 the documentation and/or other materials provided with the
13 distribution.
14
15 * Neither the name of the copyright holders nor the names of
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE. */
30
31/*
32 string.h
33
34 Contributors:
35 Created by Marek Michalkiewicz <marekm@linux.org.pl>
36 */
37
38#ifndef _STRING_H_
39#define _STRING_H_ 1
40
41#ifndef __DOXYGEN__
42#define __need_NULL
43#define __need_size_t
44#include <stddef.h>
45#include <bits/attribs.h>
46
47#endif /* !__DOXYGEN__ */
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/** \file */
54/** \defgroup avr_string <string.h>: Strings
55 \code #include <string.h> \endcode
56
57 The string functions perform string operations on \c NULL terminated
58 strings.
59
60 \note
61 If the strings you are working on reside in program memory (flash),
62 then you will need to use the string functions provided by one
63 of the following headers:
64 - \ref avr_pgmspace
65 - \ref avr_flash
66 \note
67 When the strings are defined with #PROGMEM or #PROGMEM_FAR,
68 then use the first header. When they are defined with #__flash
69 or #__flashx, then use the second one.
70*/
71
72
73/** \ingroup avr_string
74
75 This macro finds the first (least significant) bit set in the
76 input value.
77
78 This macro is very similar to the function ffs() except that
79 it evaluates its argument at compile-time, so it should only
80 be applied to compile-time constant expressions where it will
81 reduce to a constant itself.
82 Application of this macro to expressions that are not constant
83 at compile-time is not recommended, and might result in a huge
84 amount of code generated.
85
86 \returns The _FFS() macro returns the position of the first
87 (least significant) bit set in the word val, or 0 if no bits are set.
88 The least significant bit is position 1. Only 16 bits of argument
89 are evaluated.
90*/
91#if defined(__DOXYGEN__)
92#define _FFS(x)
93#else /* !DOXYGEN */
94#define _FFS(x) \
95 (1 \
96 + (((x) & 1) == 0) \
97 + (((x) & 3) == 0) \
98 + (((x) & 7) == 0) \
99 + (((x) & 017) == 0) \
100 + (((x) & 037) == 0) \
101 + (((x) & 077) == 0) \
102 + (((x) & 0177) == 0) \
103 + (((x) & 0377) == 0) \
104 + (((x) & 0777) == 0) \
105 + (((x) & 01777) == 0) \
106 + (((x) & 03777) == 0) \
107 + (((x) & 07777) == 0) \
108 + (((x) & 017777) == 0) \
109 + (((x) & 037777) == 0) \
110 + (((x) & 077777) == 0) \
111 - (((x) & 0177777) == 0) * 16)
112#endif /* DOXYGEN */
113
114/** \ingroup avr_string
115 \fn int ffs(int val);
116
117 \brief This function finds the first (least significant) bit set in the input value.
118
119 \returns The ffs() function returns the position of the first
120 (least significant) bit set in the word \p val, or 0 if no bits are set.
121 The least significant bit is position 1.
122
123 \note For expressions that are constant at compile time, consider
124 using the \ref _FFS macro instead.
125*/
126extern int ffs(int __val) __ATTR_CONST__;
127
128/** \ingroup avr_string
129 \fn int ffsl(long val);
130
131 \brief Same as ffs(), for an argument of type long. */
132extern int ffsl(long __val) __ATTR_CONST__;
133
134/** \ingroup avr_string
135 \fn int ffsll(long long val);
136
137 \brief Same as ffs(), for an argument of type <tt>long long</tt>. */
138__extension__ extern int ffsll(long long __val) __ATTR_CONST__;
139
140/** \ingroup avr_string
141 \fn void *memccpy(void *dest, const void *src, int val, size_t len)
142 \brief Copy memory area.
143
144 The memccpy() function copies no more than \p len bytes from memory
145 area \p src to memory area \p dest, stopping when the character \p val
146 is found.
147
148 \returns The memccpy() function returns a pointer to the next character
149 in \p dest after \p val, or \c NULL if \p val was not found in the first
150 \p len characters of \p src. */
151extern void *memccpy(void *, const void *, int, size_t);
152
153/** \ingroup avr_string
154 \fn void *memchr(const void *src, int val, size_t len)
155 \brief Scan memory for a character.
156
157 The memchr() function scans the first len bytes of the memory area pointed
158 to by src for the character val. The first byte to match val (interpreted
159 as an unsigned character) stops the operation.
160
161 \returns The memchr() function returns a pointer to the matching byte or
162 NULL if the character does not occur in the given memory area. */
163extern void *memchr(const void *, int, size_t) __ATTR_PURE__;
164
165/** \ingroup avr_string
166 \fn int memcmp(const void *s1, const void *s2, size_t len)
167 \brief Compare memory areas
168
169 The memcmp() function compares the first len bytes of the memory areas s1
170 and s2. The comparision is performed using unsigned char operations.
171
172 \returns The memcmp() function returns an integer less than, equal to, or
173 greater than zero if the first len bytes of s1 is found, respectively, to be
174 less than, to match, or be greater than the first len bytes of s2.
175
176 \note Be sure to store the result in a 16 bit variable since you may get
177 incorrect results if you use an unsigned char or char due to truncation.
178
179 \warning This function is not -mint8 compatible, although if you only care
180 about testing for equality, this function should be safe to use. */
181extern int memcmp(const void *, const void *, size_t) __ATTR_PURE__;
182
183/** \ingroup avr_string
184 \fn void *memcpy(void *dest, const void *src, size_t len)
185 \brief Copy a memory area.
186
187 The memcpy() function copies len bytes from memory area src to memory area
188 dest. The memory areas may not overlap. Use memmove() if the memory
189 areas do overlap.
190
191 \returns The memcpy() function returns a pointer to dest. */
192extern void *memcpy(void *, const void *, size_t);
193
194/** \ingroup avr_string
195 \fn void *memmem(const void *s1, size_t len1, const void *s2, size_t len2)
196
197 The memmem() function finds the start of the first occurrence of the
198 substring \p s2 of length \p len2 in the memory area \p s1 of length
199 \p len1.
200
201 \return The memmem() function returns a pointer to the beginning of
202 the substring, or \c NULL if the substring is not found. If \p len2
203 is zero, the function returns \p s1. */
204extern void *memmem(const void *, size_t, const void *, size_t) __ATTR_PURE__;
205
206/** \ingroup avr_string
207 \fn void *memmove(void *dest, const void *src, size_t len)
208 \brief Copy memory area.
209
210 The memmove() function copies len bytes from memory area src to memory area
211 dest. The memory areas may overlap.
212
213 \returns The memmove() function returns a pointer to dest. */
214extern void *memmove(void *, const void *, size_t);
215
216/** \ingroup avr_string
217 \fn void *memrchr(const void *src, int val, size_t len)
218
219 The memrchr() function is like the memchr() function, except that it
220 searches backwards from the end of the \p len bytes pointed to by \p
221 src instead of forwards from the front. (Glibc, GNU extension.)
222
223 \return The memrchr() function returns a pointer to the matching
224 byte or \c NULL if the character does not occur in the given memory
225 area. */
226extern void *memrchr(const void *, int, size_t) __ATTR_PURE__;
227
228/** \ingroup avr_string
229 \fn void *memset(void *dest, int val, size_t len)
230 \brief Fill memory with a constant byte.
231
232 The memset() function fills the first len bytes of the memory area pointed
233 to by dest with the constant byte val.
234
235 \returns The memset() function returns a pointer to the memory area dest. */
236extern void *memset(void *, int, size_t);
237
238/** \ingroup avr_string
239 \fn char *strcat(char *dest, const char *src)
240 \brief Concatenate two strings.
241
242 The strcat() function appends the src string to the dest string
243 overwriting the '\\0' character at the end of dest, and then adds a
244 terminating '\\0' character. The strings may not overlap, and the dest
245 string must have enough space for the result.
246
247 \returns The strcat() function returns a pointer to the resulting string
248 dest. */
249extern char *strcat(char *, const char *);
250
251/** \ingroup avr_string
252 \fn char *strchr(const char *src, int val)
253 \brief Locate character in string.
254
255 \returns The strchr() function returns a pointer to the first occurrence of
256 the character \p val in the string \p src, or \c NULL if the character
257 is not found.
258 <br><br>
259 Here "character" means "byte" -- these functions do not work with
260 wide or multi-byte characters. */
261#ifdef __DOXYGEN__
262extern char *strchr(const char *, int) __ATTR_PURE__;
263#else
264extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
265char * strchr(const char *__hay, int __val)
266{
267 register char *__r24 __asm("24");
268 register int __r22 __asm("22") = __val;
269 __asm ("%~call strchr"
270 : "=r" (__r24) : "0" (__hay), "r" (__r22) : "30", "31");
271 return __r24;
272}
273#endif /* DOXYGEN */
274
275/** \ingroup avr_string
276 \fn char *strchrnul(const char *s, int c)
277
278 The strchrnul() function is like strchr() except that if \p c is not
279 found in \p s, then it returns a pointer to the null byte at the end
280 of \p s, rather than \c NULL. (Glibc, GNU extension.)
281
282 \return The strchrnul() function returns a pointer to the matched
283 character, or a pointer to the null byte at the end of \p s (i.e.,
284 \c s+strlen(s)) if the character is not found. */
285extern char *strchrnul(const char *, int) __ATTR_PURE__;
286
287/** \ingroup avr_string
288 \fn int strcmp(const char *s1, const char *s2)
289 \brief Compare two strings.
290
291 The strcmp() function compares the two strings \p s1 and \p s2.
292
293 \returns The strcmp() function returns an integer less than, equal
294 to, or greater than zero if \p s1 is found, respectively, to be less
295 than, to match, or be greater than \p s2. A consequence of the
296 ordering used by strcmp() is that if \p s1 is an initial substring
297 of \p s2, then \p s1 is considered to be "less than" \p s2. */
298extern int strcmp(const char *, const char *) __ATTR_PURE__;
299
300/** \ingroup avr_string
301 \fn char *strcpy(char *dest, const char *src)
302 \brief Copy a string.
303
304 The strcpy() function copies the string pointed to by src (including the
305 terminating '\\0' character) to the array pointed to by dest. The strings
306 may not overlap, and the destination string dest must be large enough to
307 receive the copy.
308
309 \returns The strcpy() function returns a pointer to the destination
310 string dest.
311
312 \see strncpy(), stpcpy(), strcpy_P(), strcpy_F(). */
313extern char *strcpy(char *, const char *);
314
315/** \ingroup avr_string
316 \fn char *stpcpy(char *dest, const char *src)
317 \brief Copy a string.
318
319 The stpcpy() function copies the string pointed to by \p src
320 (including the terminating '\\0' character) to the array pointed
321 to by \p dest.
322 The strings may not overlap, and the destination string \p dest must
323 be large enough to receive the copy.
324
325 \returns The stpcpy() function returns a pointer to the <b>end</b> of
326 the string \p dest (that is, the address of the terminating null byte)
327 rather than the beginning.
328
329 \since AVR-LibC v2.3 */
330extern char *stpcpy(char *, const char *);
331
332/** \ingroup avr_string
333 \fn int strcasecmp(const char *s1, const char *s2)
334 \brief Compare two strings ignoring case.
335
336 The strcasecmp() function compares the two strings \p s1 and \p s2,
337 ignoring the case of the characters.
338
339 \returns The strcasecmp() function returns an integer less than,
340 equal to, or greater than zero if \p s1 is found, respectively, to
341 be less than, to match, or be greater than \p s2. A consequence of
342 the ordering used by strcasecmp() is that if \p s1 is an initial
343 substring of \p s2, then \p s1 is considered to be "less than"
344 \p s2. */
345extern int strcasecmp(const char *, const char *) __ATTR_PURE__;
346
347/** \ingroup avr_string
348 \fn char *strcasestr(const char *s1, const char *s2)
349
350 The strcasestr() function finds the first occurrence of the
351 substring \p s2 in the string \p s1. This is like strstr(), except
352 that it ignores case of alphabetic symbols in searching for the
353 substring. (Glibc, GNU extension.)
354
355 \return The strcasestr() function returns a pointer to the beginning
356 of the substring, or \c NULL if the substring is not found. If \p s2
357 points to a string of zero length, the function returns \p s1. */
358extern char *strcasestr(const char *, const char *) __ATTR_PURE__;
359
360/** \ingroup avr_string
361 \fn size_t strcspn(const char *s, const char *reject)
362
363 The strcspn() function calculates the length of the initial segment
364 of \p s which consists entirely of characters not in \p reject.
365
366 \return The strcspn() function returns the number of characters in
367 the initial segment of \p s which are not in the string \p reject.
368 The terminating zero is not considered as a part of string. */
369extern size_t strcspn(const char *__s, const char *__reject) __ATTR_PURE__;
370
371/** \ingroup avr_string
372 \fn char *strdup(const char *s1)
373 \brief Duplicate a string.
374
375 The strdup() function allocates memory and copies into it the string
376 addressed by \p s1, including the terminating null character.
377
378 \warning The strdup() function calls \ref a_malloc "malloc()" to allocate
379 the memory
380 for the duplicated string! The user is responsible for freeing the
381 memory by calling free().
382
383 \returns The strdup() function returns a pointer to the resulting string
384 dest. If malloc() cannot allocate enough storage for the string, strdup()
385 will return \c NULL.
386
387 \warning Be sure to check the return value of the strdup() function to
388 make sure that the function has succeeded in allocating the memory!
389*/
390extern char *strdup(const char *s1);
391
392/** \ingroup avr_string
393 \fn char *strndup(const char *s, size_t len)
394 \brief Duplicate a string.
395
396 The strndup() function is similar to strdup(), but copies at most
397 \p len bytes. If \p s is longer than \p len, only \p len bytes are copied,
398 and a terminating null byte (<tt>'\0'</tt>) is added.
399
400 Memory for the new string is obtained with malloc(), and can be freed
401 with free().
402
403 \returns The strndup() function returns the location of the newly malloc'ed
404 memory, or \c NULL if the allocation failed.
405*/
406extern char *strndup(const char *s, size_t n);
407
408/** \ingroup avr_string
409 \fn size_t strlcat(char *dst, const char *src, size_t siz)
410 \brief Concatenate two strings.
411
412 Appends \p src to string \p dst of size \p siz (unlike strncat(),
413 \p siz is the full size of \p dst, not space left). At most \p siz-1
414 characters will be copied. Always \p '\\0' terminated (unless \p siz <=
415 \p strlen(dst)).
416
417 \returns The strlcat() function returns strlen(src) + MIN(siz,
418 strlen(initial dst)). If retval >= siz, truncation occurred. */
419extern size_t strlcat(char *, const char *, size_t);
420
421/** \ingroup avr_string
422 \fn size_t strlcpy(char *dst, const char *src, size_t siz)
423 \brief Copy a string.
424
425 Copy \p src to string \p dst of size \p siz. At most \p siz-1
426 characters will be copied. Always '\\0' terminated (unless \p siz == 0).
427
428 \returns The strlcpy() function returns strlen(src). If retval >= siz,
429 truncation occurred. */
430extern size_t strlcpy(char *, const char *, size_t);
431
432/** \ingroup avr_string
433 \fn size_t strlen(const char *src)
434 \brief Calculate the length of a string.
435
436 The strlen() function calculates the length of the string \p src, not
437 including the terminating '\\0' character.
438
439 \returns The strlen() function returns the number of characters in
440 \p src. */
441extern size_t strlen(const char *) __ATTR_PURE__;
442
443/** \ingroup avr_string
444 \fn char *strlwr(char *s)
445 \brief Convert a string to lower case.
446
447 The strlwr() function will convert a string to lower case. Only the upper
448 case alphabetic characters [A .. Z] are converted. Non-alphabetic
449 characters will not be changed.
450
451 \returns The strlwr() function returns a pointer to the converted
452 string. Conversion is perfomed in-place. */
453extern char *strlwr(char *);
454
455/** \ingroup avr_string
456 \fn char *strncat(char *dest, const char *src, size_t len)
457 \brief Concatenate two strings.
458
459 The strncat() function is similar to strcat(), except that only the first
460 \p len characters of \p src are appended to \p dest.
461
462 \returns The strncat() function returns a pointer to the resulting string
463 \p dest. */
464extern char *strncat(char *, const char *, size_t);
465
466/** \ingroup avr_string
467 \fn int strncmp(const char *s1, const char *s2, size_t len)
468 \brief Compare two strings.
469
470 The strncmp() function is similar to strcmp(), except it only compares the
471 first (at most) \p len characters of \p s1 and \p s2.
472
473 \returns The strncmp() function returns an integer less than, equal to, or
474 greater than zero if \p s1 (or the first \p len bytes thereof) is found,
475 respectively, to be less than, to match, or be greater than \p s2. */
476extern int strncmp(const char *, const char *, size_t) __ATTR_PURE__;
477
478/** \ingroup avr_string
479 \fn char *strncpy(char *dest, const char *src, size_t len)
480 \brief Copy a string.
481
482 The strncpy() function is similar to strcpy(), except that not more than
483 \p len bytes of \p src are copied. Thus, if there is no null byte among
484 the first \p len bytes of \p src, the result will not be null-terminated.
485
486 In the case where the length of \p src is less than that of \p len,
487 the remainder of \p dest will be padded with nulls (<tt>'\0'</tt>).
488
489 \returns The strncpy() function returns a pointer to the destination
490 string \p dest. */
491extern char *strncpy(char *, const char *, size_t);
492
493/** \ingroup avr_string
494 \fn int strncasecmp(const char *s1, const char *s2, size_t len)
495 \brief Compare two strings ignoring case.
496
497 The strncasecmp() function is similar to strcasecmp(), except it
498 only compares the first \p len characters of \p s1.
499
500 \returns The strncasecmp() function returns an integer less than,
501 equal to, or greater than zero if \p s1 (or the first \p len bytes
502 thereof) is found, respectively, to be less than, to match, or be
503 greater than \p s2. A consequence of the ordering used by
504 strncasecmp() is that if \p s1 is an initial substring of \p s2,
505 then \p s1 is considered to be "less than" \p s2. */
506extern int strncasecmp(const char *, const char *, size_t) __ATTR_PURE__;
507
508/** \ingroup avr_string
509 \fn size_t strnlen(const char *src, size_t len)
510 \brief Determine the length of a fixed-size string.
511
512 The strnlen() function returns the number of characters in the string
513 pointed to by \p src, not including the terminating '\\0' character, but at
514 most \p len. In doing this, strnlen() looks only at the first \p len
515 characters at \p src and never beyond \p src + \p len.
516
517 \returns The strnlen function returns strlen(src), if that is less than
518 \p len, or \p len if there is no '\\0' character among the first \p len
519 characters pointed to by \p src. */
520extern size_t strnlen(const char *, size_t) __ATTR_PURE__;
521
522/** \ingroup avr_string
523 \fn char *strpbrk(const char *s, const char *accept)
524
525 The strpbrk() function locates the first occurrence in the string
526 \p s of any of the characters in the string \p accept.
527
528 \return The strpbrk() function returns a pointer to the character
529 in \p s that matches one of the characters in \p accept, or \c NULL
530 if no such character is found. The terminating zero is not
531 considered as a part of string: if one or both args are empty, the
532 result will be \c NULL. */
533extern char *strpbrk(const char *__s, const char *__accept) __ATTR_PURE__;
534
535/** \ingroup avr_string
536 \fn char *strrchr(const char *src, int val)
537 \brief Locate character in string.
538
539 The strrchr() function returns a pointer to the last occurrence of the
540 character val in the string src.
541
542 Here "character" means "byte" -- these functions do not work with wide or
543 multi-byte characters.
544
545 \returns The strrchr() function returns a pointer to the matched character
546 or \c NULL if the character is not found. */
547extern char *strrchr(const char *, int) __ATTR_PURE__;
548
549/** \ingroup avr_string
550 \fn char *strrev(char *s)
551 \brief Reverse a string.
552
553 The strrev() function reverses the order of the string.
554
555 \returns The strrev() function returns a pointer to the beginning of the
556 reversed string. */
557extern char *strrev(char *);
558
559/** \ingroup avr_string
560 \fn char *strsep(char **sp, const char *delim)
561 \brief Parse a string into tokens.
562
563 The strsep() function locates, in the string referenced by \p *sp,
564 the first occurrence of any character in the string \p delim (or the
565 terminating '\\0' character) and replaces it with a '\\0'. The
566 location of the next character after the delimiter character (or \c
567 NULL, if the end of the string was reached) is stored in \p *sp. An
568 ``empty'' field, i.e. one caused by two adjacent delimiter
569 characters, can be detected by comparing the location referenced by
570 the pointer returned in \p *sp to '\\0'.
571
572 \return The strsep() function returns a pointer to the original
573 value of \p *sp. If \p *sp is initially \c NULL, strsep() returns
574 \c NULL. */
575extern char *strsep(char **, const char *);
576
577/** \ingroup avr_string
578 \fn size_t strspn(const char *s, const char *accept)
579
580 The strspn() function calculates the length of the initial segment
581 of \p s which consists entirely of characters in \p accept.
582
583 \return The strspn() function returns the number of characters in
584 the initial segment of \p s which consist only of characters from \p
585 accept. The terminating zero is not considered as a part of string. */
586extern size_t strspn(const char *__s, const char *__accept) __ATTR_PURE__;
587
588/** \ingroup avr_string
589 \fn char *strstr(const char *s1, const char *s2)
590 \brief Locate a substring.
591
592 The strstr() function finds the first occurrence of the substring \p
593 s2 in the string \p s1. The terminating '\\0' characters are not
594 compared.
595
596 \returns The strstr() function returns a pointer to the beginning of
597 the substring, or \c NULL if the substring is not found. If \p s2
598 points to a string of zero length, the function returns \p s1. */
599extern char *strstr(const char *, const char *) __ATTR_PURE__;
600
601/** \ingroup avr_string
602 \fn char *strtok(char *s, const char *delim)
603 \brief Parses the string s into tokens.
604
605 strtok parses the string s into tokens. The first call to strtok
606 should have s as its first argument. Subsequent calls should have
607 the first argument set to \c NULL. If a token ends with a delimiter, this
608 delimiting character is overwritten with a '\\0' and a pointer to the next
609 character is saved for the next call to strtok. The delimiter string
610 delim may be different for each call.
611
612 \returns The strtok() function returns a pointer to the next token or
613 \c NULL when no more tokens are found.
614
615 \note strtok() is NOT reentrant. For a reentrant version of this function
616 see \c strtok_r().
617*/
618extern char *strtok(char *, const char *);
619
620/** \ingroup avr_string
621 \fn char *strtok_r(char *string, const char *delim, char **last)
622 \brief Parses string into tokens.
623
624 strtok_r parses string into tokens. The first call to strtok_r
625 should have string as its first argument. Subsequent calls should have
626 the first argument set to \c NULL. If a token ends with a delimiter, this
627 delimiting character is overwritten with a '\\0' and a pointer to the next
628 character is saved for the next call to strtok_r. The delimiter string
629 \p delim may be different for each call. \p last is a user allocated char*
630 pointer. It must be the same while parsing the same string. strtok_r is
631 a reentrant version of strtok().
632
633 \returns The strtok_r() function returns a pointer to the next token or
634 \c NULL when no more tokens are found. */
635extern char *strtok_r(char *, const char *, char **);
636
637/** \ingroup avr_string
638 \fn char *strupr(char *s)
639 \brief Convert a string to upper case.
640
641 The strupr() function will convert a string to upper case. Only the lower
642 case alphabetic characters [a .. z] are converted. Non-alphabetic
643 characters will not be changed.
644
645 \returns The strupr() function returns a pointer to the converted
646 string. The pointer is the same as that passed in since the operation is
647 perform in place. */
648extern char *strupr(char *);
649
650#ifndef __DOXYGEN__
651/* libstdc++ compatibility, dummy declarations */
652extern int strcoll(const char *s1, const char *s2);
653extern char *strerror(int errnum);
654extern size_t strxfrm(char *dest, const char *src, size_t n);
655
656/* strlen is common so we model its GPR footprint. */
657extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
658size_t strlen(const char *__s)
659{
660 if (__builtin_constant_p (__builtin_strlen (__s)))
661 {
662 return __builtin_strlen (__s);
663 }
664 else
665 {
666 register const char *__r24 __asm("24") = __s;
667 register size_t __res __asm("24");
668 __asm ("%~call %x2" : "=r" (__res) : "r" (__r24), "i" (strlen)
669 : "30", "31", "memory");
670 return __res;
671 }
672}
673
674/* strcpy is common so we model its GPR footprint. */
675extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
676char* strcpy(char *__x, const char *__z)
677{
678 char *__ret = __x;
679 __asm volatile ("%~call __strcpy"
680 : "+x" (__x), "+z" (__z) :: "memory");
681 return __ret;
682}
683
684extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
685char* stpcpy(char *__x, const char *__z)
686{
687 __asm volatile ("%~call __strcpy"
688 : "+x" (__x), "+z" (__z) :: "memory");
689 return __x - 1;
690}
691
692/* strcmp is common so we model its GPR footprint. */
693extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
694int strcmp(const char *__x, const char *__z)
695{
696 register int __ret __asm("24");
697 __asm ("%~call __strcmp"
698 : "=r" (__ret), "+x" (__x), "+z" (__z) :: "memory");
699 return __ret;
700}
701
702#endif /* !__DOXYGEN__ */
703
704#ifdef __cplusplus
705}
706#endif
707
708#endif /* _STRING_H_ */
int strncasecmp(const char *, const char *, size_t)
Compare two strings ignoring case.
void * memchr(const void *, int, size_t)
Scan memory for a character.
int memcmp(const void *, const void *, size_t)
Compare memory areas.
char * strlwr(char *)
Convert a string to lower case.
char * strstr(const char *, const char *)
Locate a substring.
char * strcat(char *, const char *)
Concatenate two strings.
size_t strlen(const char *)
Calculate the length of a string.
int strcmp(const char *, const char *)
Compare two strings.
char * strchrnul(const char *, int)
char * strpbrk(const char *__s, const char *__accept)
char * strrchr(const char *, int)
Locate character in string.
char * strcpy(char *, const char *)
Copy a string.
void * memcpy(void *, const void *, size_t)
Copy a memory area.
size_t strlcat(char *, const char *, size_t)
Concatenate two strings.
Definition: strlcat.c:49
size_t strlcpy(char *, const char *, size_t)
Copy a string.
Definition: strlcpy.c:48
char * strtok(char *, const char *)
Parses the string s into tokens.
Definition: strtok.c:39
int strncmp(const char *, const char *, size_t)
Compare two strings.
char * strncpy(char *, const char *, size_t)
Copy a string.
char * strdup(const char *s1)
Duplicate a string.
Definition: strdup.c:35
void * memmove(void *, const void *, size_t)
Copy memory area.
void * memccpy(void *, const void *, int, size_t)
Copy memory area.
void * memset(void *, int, size_t)
Fill memory with a constant byte.
int strcasecmp(const char *, const char *)
Compare two strings ignoring case.
char * strchr(const char *, int)
Locate character in string.
char * strupr(char *)
Convert a string to upper case.
int ffs(int __val)
This function finds the first (least significant) bit set in the input value.
char * strtok_r(char *, const char *, char **)
Parses string into tokens.
void * memrchr(const void *, int, size_t)
char * stpcpy(char *, const char *)
Copy a string.
void * memmem(const void *, size_t, const void *, size_t)
char * strcasestr(const char *, const char *)
int ffsl(long __val)
Same as ffs(), for an argument of type long.
char * strrev(char *)
Reverse a string.
size_t strcspn(const char *__s, const char *__reject)
int ffsll(long long __val)
Same as ffs(), for an argument of type long long.
size_t strnlen(const char *, size_t)
Determine the length of a fixed-size string.
size_t strspn(const char *__s, const char *__accept)
char * strndup(const char *s, size_t n)
Duplicate a string.
Definition: strndup.c:32
char * strncat(char *, const char *, size_t)
Concatenate two strings.
char * strsep(char **, const char *)
Parse a string into tokens.