/* $Id$ */ /* Release $Name$ */ /* String handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ #ifndef _PDCLIB_AUX_H #define _PDCLIB_AUX_H _PDCLIB_AUX_H #include <_PDCLIB_aux.h> #endif #ifndef _PDCLIB_INT_H #define _PDCLIB_INT_H _PDCLIB_INT_H #include <_PDCLIB_int.h> #endif #if _PDCLIB_HOSTED == 1 #warning As of the current release, PDCLib is not a conforming hosted environment. #warning might be incomplete. #endif typedef _PDCLIB_size_t size_t; /* String function conventions */ /* In any of the following functions taking a size_t n to specify the length of an array or size of a memory region, n may be 0, but the pointer arguments to the call shall still be valid unless otherwise stated. */ /* Copying functions */ /* Copy a number of n characters from the memory area pointed to by s2 to the area pointed to by s1. If the two areas overlap, behaviour is undefined. Returns the value of s1. */ void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); /* Copy a number of n characters from the memory area pointed to by s2 to the area pointed to by s1. The two areas may overlap. Returns the value of s1. */ void * memmove( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); /* Copy the character array s2 (including terminating '\0' byte) into the character array s1. Returns the value of s1. */ char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); /* Copy a maximum of n characters from the character array s2 into the character array s1. If s2 is shorter than n characters, '\0' bytes will be appended to the copy in s1 until n characters have been written. If s2 is longer than n characters, NO terminating '\0' will be written to s1. If the arrays overlap, behaviour is undefined. Returns the value of s1. */ char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); /* Concatenation functions */ /* Append the contents of the character array s2 (including terminating '\0') to the character array s1 (first character of s2 overwriting the '\0' of s1). If the arrays overlap, behaviour is undefined. Returns the value of s1. */ char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); /* Append a maximum of n characters from the character array s1 to the character array s1 (first character of s2 overwriting the '\0' of s1). A terminating '\0' is ALWAYS appended, even if the full n characters have already been written. If the arrays overlap, behaviour is undefined. Returns the value of s1. */ char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); /* Comparison functions */ /* Compare the first n characters of the memory areas pointed to by s1 and s2. Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if s1 > s2. */ int memcmp( const void * s1, const void * s2, size_t n ); /* Compare the character arrays s1 and s2. Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if s1 > s2. */ int strcmp( const char * s1, const char * s2 ); /* Compare the character arrays s1 and s2, interpreted as specified by the LC_COLLATE category of the current locale. Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if s1 > s2. TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support locales. */ int strcoll( const char * s1, const char * s2 ); /* Compare no more than the first n characters of the character arrays s1 and s2. Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if s1 > s2. */ int strncmp( const char * s1, const char * s2, size_t n ); /* Transform the character array s2 as appropriate for the LC_COLLATE setting of the current locale. If length of resulting string is less than n, store it in the character array pointed to by s1. Return the length of the resulting string. */ size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); /* Search functions */ /* Search the first n characters in the memory area pointed to by s for the character c (interpreted as unsigned char). Returns a pointer to the first instance found, or NULL. */ void * memchr( const void * s, int c, size_t n ); /* Search the character array s (including terminating '\0') for the character c (interpreted as char). Returns a pointer to the first instance found, or NULL. */ char * strchr( const char * s, int c );