]> pd.if.org Git - pdclib/blob - includes/string.h
Removed redundant include.
[pdclib] / includes / string.h
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* String handling <string.h>
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #ifndef _PDCLIB_STRING_H
12 #define _PDCLIB_STRING_H _PDCLIB_STRING_H
13
14 #ifndef _PDCLIB_INT_H
15 #define _PDCLIB_INT_H _PDCLIB_INT_H
16 #include <_PDCLIB_int.h>
17 #endif
18
19 #ifndef _PDCLIB_SIZE_T_DEFINED
20 #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED
21 typedef _PDCLIB_size_t size_t;
22 #endif
23
24 #define NULL _PDCLIB_NULL
25
26 /* String function conventions */
27
28 /*
29    In any of the following functions taking a size_t n to specify the length of
30    an array or size of a memory region, n may be 0, but the pointer arguments to
31    the call shall still be valid unless otherwise stated.
32 */
33
34 /* Copying functions */
35
36 /* Copy a number of n characters from the memory area pointed to by s2 to the
37    area pointed to by s1. If the two areas overlap, behaviour is undefined.
38    Returns the value of s1.
39 */
40 void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n );
41
42 /* Copy a number of n characters from the memory area pointed to by s2 to the
43    area pointed to by s1. The two areas may overlap.
44    Returns the value of s1.
45 */
46 void * memmove( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n );
47
48 /* Copy the character array s2 (including terminating '\0' byte) into the
49    character array s1.
50    Returns the value of s1.
51 */
52 char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 );
53
54 /* Copy a maximum of n characters from the character array s2 into the character
55    array s1. If s2 is shorter than n characters, '\0' bytes will be appended to
56    the copy in s1 until n characters have been written. If s2 is longer than n
57    characters, NO terminating '\0' will be written to s1. If the arrays overlap,
58    behaviour is undefined.
59    Returns the value of s1.
60 */
61 char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n );
62
63 /* Concatenation functions */
64
65 /* Append the contents of the character array s2 (including terminating '\0') to
66    the character array s1 (first character of s2 overwriting the '\0' of s1). If
67    the arrays overlap, behaviour is undefined.
68    Returns the value of s1.
69 */
70 char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 );
71
72 /* Append a maximum of n characters from the character array s1 to the character
73    array s1 (first character of s2 overwriting the '\0' of s1). A terminating
74    '\0' is ALWAYS appended, even if the full n characters have already been
75    written. If the arrays overlap, behaviour is undefined.
76    Returns the value of s1.
77 */
78 char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n );
79
80 /* Comparison functions */
81
82 /* Compare the first n characters of the memory areas pointed to by s1 and s2.
83    Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
84    s1 > s2.
85 */
86 int memcmp( const void * s1, const void * s2, size_t n );
87
88 /* Compare the character arrays s1 and s2.
89    Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
90    s1 > s2.
91 */
92 int strcmp( const char * s1, const char * s2 );
93
94 /* Compare the character arrays s1 and s2, interpreted as specified by the
95    LC_COLLATE category of the current locale.
96    Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
97    s1 > s2.
98    TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support
99    locales.
100 */
101 int strcoll( const char * s1, const char * s2 );
102
103 /* Compare no more than the first n characters of the character arrays s1 and
104    s2.
105    Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
106    s1 > s2.
107 */
108 int strncmp( const char * s1, const char * s2, size_t n );
109
110 /* Transform the character array s2 as appropriate for the LC_COLLATE setting of
111    the current locale. If length of resulting string is less than n, store it in
112    the character array pointed to by s1. Return the length of the resulting
113    string.
114 */
115 size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n );
116
117 /* Search functions */
118
119 /* Search the first n characters in the memory area pointed to by s for the
120    character c (interpreted as unsigned char).
121    Returns a pointer to the first instance found, or NULL.
122 */
123 void * memchr( const void * s, int c, size_t n );
124
125 /* Search the character array s (including terminating '\0') for the character c
126    (interpreted as char).
127    Returns a pointer to the first instance found, or NULL.
128 */
129 char * strchr( const char * s, int c );
130
131 /* Determine the length of the initial substring of character array s1 which
132    consists only of characters not from the character array s2.
133    Returns the length of that substring.
134 */
135 size_t strcspn( const char * s1, const char * s2 );
136
137 /* Search the character array s1 for any character from the character array s2.
138    Returns a pointer to the first occurrence, or NULL.
139 */
140 char * strpbrk( const char * s1, const char * s2 );
141
142 /* Search the character array s (including terminating '\0') for the character c
143    (interpreted as char).
144    Returns a pointer to the last instance found, or NULL.
145 */
146 char * strrchr( const char * s, int c );
147
148 /* Determine the length of the initial substring of character array s1 which
149    consists only of characters from the character array s2.
150    Returns the length of that substring.
151 */
152 size_t strspn( const char * s1, const char * s2 );
153
154 /* Search the character array s1 for the substring in character array s2.
155    Returns a pointer to that sbstring, or NULL. If s2 is of length zero,
156    returns s1.
157 */
158 char * strstr( const char * s1, const char * s2 );
159
160 /* In a series of subsequent calls, parse a C string into tokens.
161    On the first call to strtok(), the first argument is a pointer to the to-be-
162    parsed C string. On subsequent calls, the first argument is NULL unless you
163    want to start parsing a new string. s2 holds an array of seperator characters
164    which can differ from call to call. Leading seperators are skipped, the first
165    trailing seperator overwritten with '\0'.
166    Returns a pointer to the next token.
167    WARNING: This function uses static storage, and as such is not reentrant.
168 */
169 char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 );
170
171 /* Miscellaneous functions */
172
173 /* Write the character c (interpreted as unsigned char) to the first n
174    characters of the memory area pointed to by s.
175    Returns s.
176 */
177 void * memset( void * s, int c, size_t n );
178
179 /* Map an error number to a (locale-specific) error message string. Error
180    numbers are typically errno values, but any number is mapped to a message.
181    TODO: PDCLib does not yet support locales.
182    TODO: strerror() not yet implemented.
183 char * strerror( int errnum );
184 */
185
186 /* Returns the length of the string s (excluding terminating '\0').
187 */
188 size_t strlen( const char * s );
189
190 #endif