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