avr-libc: string.h Source File

avr-libc 2.0.0 Standard C library for AVR-GCC |

## AVR Libc Home Page |  | ## AVR Libc Development Pages
## Main Page | ## User Manual | ## Library Reference | ## FAQ | ## Example Projects

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 /* $Id: string.h 2503 2016-02-07 22:59:47Z joerg_wunsch $ */
32
33 /*
34 string.h
35
36 Contributors:
37 Created by Marek Michalkiewicz <marekm@linux.org.pl>
38 */
39
40 #ifndef _STRING_H_
41 #define _STRING_H_ 1
42
43 #ifndef __DOXYGEN__
44 #define __need_NULL
45 #define __need_size_t
46 #include <stddef.h>
47
48 #ifndef __ATTR_PURE__
49 #define __ATTR_PURE__ __attribute__((__pure__))
50 #endif
51
52 #ifndef __ATTR_CONST__
53 # define __ATTR_CONST__ __attribute__((__const__))
54 #endif
55 #endif /* !__DOXYGEN__ */
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 /** \file */
62 /** \defgroup avr_string <string.h>: Strings
63 \code #include <string.h> \endcode
64
65 The string functions perform string operations on NULL terminated
66 strings.
67
68 \note If the strings you are working on resident in program space (flash),
69 you will need to use the string functions described in \ref avr_pgmspace. */
70
71
72 /** \ingroup avr_string
73
74 This macro finds the first (least significant) bit set in the
75 input value.
76
77 This macro is very similar to the function ffs() except that
78 it evaluates its argument at compile-time, so it should only
79 be applied to compile-time constant expressions where it will
80 reduce to a constant itself.
81 Application of this macro to expressions that are not constant
82 at compile-time is not recommended, and might result in a huge
83 amount of code generated.
84
85 \returns The _FFS() macro returns the position of the first
86 (least significant) bit set in the word val, or 0 if no bits are set.
87 The least significant bit is position 1. Only 16 bits of argument
88 are evaluted.
89 */
90 #if defined(__DOXYGEN__)
91 #define _FFS(x)
92 #else /* !DOXYGEN */
93 #define _FFS(x) \
94 (1 \
95 + (((x) & 1) == 0) \
96 + (((x) & 3) == 0) \
97 + (((x) & 7) == 0) \
98 + (((x) & 017) == 0) \
99 + (((x) & 037) == 0) \
100 + (((x) & 077) == 0) \
101 + (((x) & 0177) == 0) \
102 + (((x) & 0377) == 0) \
103 + (((x) & 0777) == 0) \
104 + (((x) & 01777) == 0) \
105 + (((x) & 03777) == 0) \
106 + (((x) & 07777) == 0) \
107 + (((x) & 017777) == 0) \
108 + (((x) & 037777) == 0) \
109 + (((x) & 077777) == 0) \
110 - (((x) & 0177777) == 0) * 16)
111 #endif /* DOXYGEN */
112
113 extern int ffs (int __val) __ATTR_CONST__;
114 extern int ffsl (long __val) __ATTR_CONST__;
115 __extension__ extern int ffsll (long long __val) __ATTR_CONST__;
116 extern void *memccpy(void *, const void *, int, size_t);
117 extern void *memchr(const void *, int, size_t) __ATTR_PURE__;
118 extern int memcmp(const void *, const void *, size_t) __ATTR_PURE__;
119 extern void *memcpy(void *, const void *, size_t);
120 extern void *memmem(const void *, size_t, const void *, size_t) __ATTR_PURE__;
121 extern void *memmove(void *, const void *, size_t);
122 extern void *memrchr(const void *, int, size_t) __ATTR_PURE__;
123 extern void *memset(void *, int, size_t);
124 extern char *strcat(char *, const char *);
125 extern char *strchr(const char *, int) __ATTR_PURE__;
126 extern char *strchrnul(const char *, int) __ATTR_PURE__;
127 extern int strcmp(const char *, const char *) __ATTR_PURE__;
128 extern char *strcpy(char *, const char *);
129 extern int strcasecmp(const char *, const char *) __ATTR_PURE__;
130 extern char *strcasestr(const char *, const char *) __ATTR_PURE__;
131 extern size_t strcspn(const char *__s, const char *__reject) __ATTR_PURE__;
132 extern char *strdup(const char *s1);
133 extern size_t strlcat(char *, const char *, size_t);
134 extern size_t strlcpy(char *, const char *, size_t);
135 extern size_t strlen(const char *) __ATTR_PURE__;
136 extern char *strlwr(char *);
137 extern char *strncat(char *, const char *, size_t);
138 extern int strncmp(const char *, const char *, size_t) __ATTR_PURE__;
139 extern char *strncpy(char *, const char *, size_t);
140 extern int strncasecmp(const char *, const char *, size_t) __ATTR_PURE__;
141 extern size_t strnlen(const char *, size_t) __ATTR_PURE__;
142 extern char *strpbrk(const char *__s, const char *__accept) __ATTR_PURE__;
143 extern char *strrchr(const char *, int) __ATTR_PURE__;
144 extern char *strrev(char *);
145 extern char *strsep(char **, const char *);
146 extern size_t strspn(const char *__s, const char *__accept) __ATTR_PURE__;
147 extern char *strstr(const char *, const char *) __ATTR_PURE__;
148 extern char *strtok(char *, const char *);
149 extern char *strtok_r(char *, const char *, char **);
150 extern char *strupr(char *);
151
152 #ifndef __DOXYGEN__
153 /* libstdc++ compatibility, dummy declarations */
154 extern int strcoll(const char *s1, const char *s2);
155 extern char *strerror(int errnum);
156 extern size_t strxfrm(char *dest, const char *src, size_t n);
157 #endif /* !__DOXYGEN__ */
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif /* _STRING_H_ */
164
strtok
char * strtok(char *, const char *)
Parses the string s into tokens.
Definition: strtok.c:59
strlcpy
size_t strlcpy(char *, const char *, size_t)
Copy a string.
Definition: strlcpy.c:49
strdup
char * strdup(const char *s1)
Duplicate a string.
Definition: strdup.c:57
strlcat
size_t strlcat(char *, const char *, size_t)
Concatenate two strings.
Definition: strlcat.c:50