/* String handling <string.h>12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#ifndef _PDCLIB_STRING_H7#define _PDCLIB_STRING_H _PDCLIB_STRING_H8#include "_PDCLIB_int.h"910#ifdef __cplusplus11extern "C" {12#endif1314#ifndef _PDCLIB_SIZE_T_DEFINED15#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED16typedef _PDCLIB_size_t size_t;17#endif1819#ifndef _PDCLIB_NULL_DEFINED20#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED21#define NULL _PDCLIB_NULL22#endif2324/* String function conventions */2526/*27In any of the following functions taking a size_t n to specify the length of28an array or size of a memory region, n may be 0, but the pointer arguments to29the call shall still be valid unless otherwise stated.30*/3132/* Copying functions */3334/* Copy a number of n characters from the memory area pointed to by s2 to the35area pointed to by s1. If the two areas overlap, behaviour is undefined.36Returns the value of s1.37*/38void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ) _PDCLIB_nothrow;3940/* Copy a number of n characters from the memory area pointed to by s2 to the41area pointed to by s1. The two areas may overlap.42Returns the value of s1.43*/44void * memmove( void * s1, const void * , size_t n ) _PDCLIB_nothrow;4546/* Copy the character array s2 (including terminating '\0' byte) into the47character array s1.48Returns the value of s1.49*/50char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ) _PDCLIB_nothrow;5152/* Copy a maximum of n characters from the character array s2 into the character53array s1. If s2 is shorter than n characters, '\0' bytes will be appended to54the copy in s1 until n characters have been written. If s2 is longer than n55characters, NO terminating '\0' will be written to s1. If the arrays overlap,56behaviour is undefined.57Returns the value of s1.58*/59char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) _PDCLIB_nothrow;6061/* Concatenation functions */6263/* Append the contents of the character array s2 (including terminating '\0') to64the character array s1 (first character of s2 overwriting the '\0' of s1). If65the arrays overlap, behaviour is undefined.66Returns the value of s1.67*/68char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ) _PDCLIB_nothrow;6970/* Append a maximum of n characters from the character array s1 to the character71array s1 (first character of s2 overwriting the '\0' of s1). A terminating72'\0' is ALWAYS appended, even if the full n characters have already been73written. If the arrays overlap, behaviour is undefined.74Returns the value of s1.75*/76char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) _PDCLIB_nothrow;7778/* Comparison functions */7980/* Compare the first n characters of the memory areas pointed to by s1 and s2.81Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if82s1 > s2.83*/84int memcmp( const void * s1, const void * s2, size_t n ) _PDCLIB_nothrow;8586/* Compare the character arrays s1 and s2.87Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if88s1 > s2.89*/90int strcmp( const char * s1, const char * s2 ) _PDCLIB_nothrow;9192/* Compare the character arrays s1 and s2, interpreted as specified by the93LC_COLLATE category of the current locale.94Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if95s1 > s2.96TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support97locales.98*/99int strcoll( const char * s1, const char * s2 ) _PDCLIB_nothrow;100101/* Compare no more than the first n characters of the character arrays s1 and102s2.103Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if104s1 > s2.105*/106int strncmp( const char * s1, const char * s2, size_t n ) _PDCLIB_nothrow;107108/* Transform the character array s2 as appropriate for the LC_COLLATE setting of109the current locale. If length of resulting string is less than n, store it in110the character array pointed to by s1. Return the length of the resulting111string.112*/113size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) _PDCLIB_nothrow;114115/* Search functions */116117/* Search the first n characters in the memory area pointed to by s for the118character c (interpreted as unsigned char).119Returns a pointer to the first instance found, or NULL.120*/121void * memchr( const void * s, int c, size_t n ) _PDCLIB_nothrow;122123/* Search the character array s (including terminating '\0') for the character c124(interpreted as char).125Returns a pointer to the first instance found, or NULL.126*/127char * strchr( const char * s, int c ) _PDCLIB_nothrow;128129/* Determine the length of the initial substring of character array s1 which130consists only of characters not from the character array s2.131Returns the length of that substring.132*/133size_t strcspn( const char * s1, const char * s2 ) _PDCLIB_nothrow;134135/* Search the character array s1 for any character from the character array s2.136Returns a pointer to the first occurrence, or NULL.137*/138char * strpbrk( const char * s1, const char * s2 ) _PDCLIB_nothrow;139140/* Search the character array s (including terminating '\0') for the character c141(interpreted as char).142Returns a pointer to the last instance found, or NULL.143*/144char * strrchr( const char * s, int c ) _PDCLIB_nothrow;145146/* Determine the length of the initial substring of character array s1 which147consists only of characters from the character array s2.148Returns the length of that substring.149*/150size_t strspn( const char * s1, const char * s2 ) _PDCLIB_nothrow;151152/* Search the character array s1 for the substring in character array s2.153Returns a pointer to that sbstring, or NULL. If s2 is of length zero,154returns s1.155*/156char * strstr( const char * s1, const char * s2 ) _PDCLIB_nothrow;157158/* In a series of subsequent calls, parse a C string into tokens.159On the first call to strtok(), the first argument is a pointer to the to-be-160parsed C string. On subsequent calls, the first argument is NULL unless you161want to start parsing a new string. s2 holds an array of seperator characters162which can differ from call to call. Leading seperators are skipped, the first163trailing seperator overwritten with '\0'.164Returns a pointer to the next token.165WARNING: This function uses static storage, and as such is not reentrant.166*/167char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ) _PDCLIB_nothrow;168169/* Miscellaneous functions */170171/* Write the character c (interpreted as unsigned char) to the first n172characters of the memory area pointed to by s.173Returns s.174*/175void * memset( void * s, int c, size_t n ) _PDCLIB_nothrow;176177/* Map an error number to a (locale-specific) error message string. Error178numbers are typically errno values, but any number is mapped to a message.179TODO: PDCLib does not yet support locales.180*/181char * strerror( int errnum ) _PDCLIB_nothrow;182183/* Returns the length of the string s (excluding terminating '\0').184*/185size_t strlen( const char * s ) _PDCLIB_nothrow;186187#if _PDCLIB_POSIX_MIN(2008098L)188/* Returns the length of the string s (excluding terminating '\0') or maxlen if189* no terminating '\0' is found in the first maxlen characters.190*/191size_t strnlen( const char * s, size_t maxlen ) _PDCLIB_nothrow;192#endif193194#if _PDCLIB_POSIX_MIN(2008098L) || _PDCLIB_XOPEN_MIN(0)195char * strdup( const char* src ) _PDCLIB_nothrow;196char * strndup( const char* src, size_t n ) _PDCLIB_nothrow;197#endif198199#if _PDCLIB_BSD_SOURCE200size_t strlcpy(201char *_PDCLIB_restrict _Dst,202const char *_PDCLIB_restrict _Src,203size_t _DstSize) _PDCLIB_nothrow;204205size_t strlcat(206char *_PDCLIB_restrict _Dst,207const char *_PDCLIB_restrict _Src,208size_t _DstSize) _PDCLIB_nothrow;209#endif210211#ifdef __cplusplus212}213#endif214215#endif216217218