compiled newlib, need to hook up the system calls

This commit is contained in:
2026-06-28 17:58:58 -05:00
parent 43bc0df81a
commit 97357f3170
337 changed files with 47955 additions and 114 deletions

View File

@@ -0,0 +1,44 @@
/* memchr( const void *, int, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
void * memchr( const void * s, int c, size_t n )
{
const unsigned char * p = ( const unsigned char * ) s;
while ( n-- )
{
if ( *p == ( unsigned char ) c )
{
return ( void * ) p;
}
++p;
}
return NULL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
TESTCASE( memchr( abcde, 'c', 5 ) == &abcde[2] );
TESTCASE( memchr( abcde, 'a', 1 ) == &abcde[0] );
TESTCASE( memchr( abcde, 'a', 0 ) == NULL );
TESTCASE( memchr( abcde, '\0', 5 ) == NULL );
TESTCASE( memchr( abcde, '\0', 6 ) == &abcde[5] );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,46 @@
/* memcmp( const void *, const void *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
int memcmp( const void * s1, const void * s2, size_t n )
{
const unsigned char * p1 = ( const unsigned char * ) s1;
const unsigned char * p2 = ( const unsigned char * ) s2;
while ( n-- )
{
if ( *p1 != *p2 )
{
return *p1 - *p2;
}
++p1;
++p2;
}
return 0;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
const char xxxxx[] = "xxxxx";
TESTCASE( memcmp( abcde, abcdx, 5 ) < 0 );
TESTCASE( memcmp( abcde, abcdx, 4 ) == 0 );
TESTCASE( memcmp( abcde, xxxxx, 0 ) == 0 );
TESTCASE( memcmp( xxxxx, abcde, 1 ) > 0 );
return 0;
}
#endif

View File

@@ -0,0 +1,42 @@
/* memcpy( void *, const void *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n )
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
while ( n-- )
{
*dest++ = *src++;
}
return s1;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xxxxxxxxxxx";
TESTCASE( memcpy( s, abcde, 6 ) == s );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
TESTCASE( memcpy( s + 5, abcde, 5 ) == s + 5 );
TESTCASE( s[9] == 'e' );
TESTCASE( s[10] == 'x' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,92 @@
/* memcpy_s( void *, rsize_t, const void *, rsize_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t memcpy_s( void * _PDCLIB_restrict s1, rsize_t s1max, const void * _PDCLIB_restrict s2, rsize_t n )
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && n <= RSIZE_MAX && n <= s1max )
{
while ( n-- )
{
if ( dest == s2 || src == s1 )
{
goto runtime_constraint_violation;
}
*dest++ = *src++;
}
return 0;
}
runtime_constraint_violation:
if ( s1 != NULL && s1max <= RSIZE_MAX )
{
memset( s1, 0, s1max );
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xxxxxxxxxxx";
set_constraint_handler_s( test_handler );
TESTCASE( memcpy_s( s, 11, abcde, 6 ) == 0 );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
TESTCASE( memcpy_s( s + 5, 6, abcde, 5 ) == 0 );
TESTCASE( s[9] == 'e' );
TESTCASE( s[10] == 'x' );
s[5] = 'x';
TESTCASE( memcpy_s( s, 5, abcde, 6 ) != 0 );
TESTCASE( memcmp( s, "\0\0\0\0\0x", 6 ) == 0 );
TESTCASE( memcpy_s( s, 3, s + 2, 3 ) != 0 );
TESTCASE( memcpy_s( s + 2, 3, s, 3 ) != 0 );
/* Overlapping */
TESTCASE( memcpy_s( s, 4, s + 3, 4 ) != 0 );
TESTCASE( memcpy_s( s + 3, 4, s, 4 ) != 0 );
TESTCASE( HANDLER_CALLS == 5 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,55 @@
/* memmove( void *, const void *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
void * memmove( void * s1, const void * s2, size_t n )
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
if ( dest <= src )
{
while ( n-- )
{
*dest++ = *src++;
}
}
else
{
src += n;
dest += n;
while ( n-- )
{
*--dest = *--src;
}
}
return s1;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xxxxabcde";
TESTCASE( memmove( s, s + 4, 5 ) == s );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == 'b' );
TESTCASE( memmove( s + 4, s, 5 ) == s + 4 );
TESTCASE( s[4] == 'a' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,87 @@
/* memmove_s( void *, rsize_t, const void *, rsize_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t memmove_s( void * s1, rsize_t s1max, const void * s2, rsize_t n )
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
if ( s1 == NULL || s2 == NULL || s1max > RSIZE_MAX || n > RSIZE_MAX || n > s1max )
{
if ( s1 != NULL && s1max <= RSIZE_MAX )
{
memset( s1, 0, s1max );
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
while ( n )
{
if ( dest == s2 || src == s1 )
{
src += n;
dest += n;
while ( n-- )
{
*--dest = *--src;
}
return 0;
}
*dest++ = *src++;
--n;
}
return 0;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xxxxabcde";
set_constraint_handler_s( test_handler );
TESTCASE( memmove_s( s, 10, s + 4, 5 ) == 0 );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == 'b' );
TESTCASE( memmove_s( s + 4, 6, s, 5 ) == 0 );
TESTCASE( s[4] == 'a' );
TESTCASE( HANDLER_CALLS == 0 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,42 @@
/* memset( void *, int, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
void * memset( void * s, int c, size_t n )
{
unsigned char * p = ( unsigned char * ) s;
while ( n-- )
{
*p++ = ( unsigned char ) c;
}
return s;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xxxxxxxxx";
TESTCASE( memset( s, 'o', 10 ) == s );
TESTCASE( s[9] == 'o' );
TESTCASE( memset( s, '_', ( 0 ) ) == s );
TESTCASE( s[0] == 'o' );
TESTCASE( memset( s, '_', 1 ) == s );
TESTCASE( s[0] == '_' );
TESTCASE( s[1] == 'o' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,73 @@
/* memset_s( void *, rsize_t, int, rsize_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t memset_s( void * s, rsize_t smax, int c, rsize_t n )
{
unsigned char * p = ( unsigned char * ) s;
if ( s == NULL || smax > RSIZE_MAX || n > RSIZE_MAX || n > smax )
{
if ( s != NULL && smax <= RSIZE_MAX )
{
memset( s, c, smax );
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
while ( n-- )
{
*p++ = ( unsigned char ) c;
}
return 0;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xxxxxxxxx";
set_constraint_handler_s( test_handler );
TESTCASE( memset_s( s, 10, 'o', 10 ) == 0 );
TESTCASE( s[9] == 'o' );
TESTCASE( memset_s( s, 10, '_', ( 0 ) ) == 0 );
TESTCASE( s[0] == 'o' );
TESTCASE( memset_s( s, 10, '_', 1 ) == 0 );
TESTCASE( s[0] == '_' );
TESTCASE( s[1] == 'o' );
TESTCASE( HANDLER_CALLS == 0 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,55 @@
/* strcat( char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
{
char * rc = s1;
if ( *s1 )
{
while ( *++s1 )
{
/* EMPTY */
}
}
while ( ( *s1++ = *s2++ ) )
{
/* EMPTY */
}
return rc;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xx\0xxxxxx";
TESTCASE( strcat( s, abcde ) == s );
TESTCASE( s[2] == 'a' );
TESTCASE( s[6] == 'e' );
TESTCASE( s[7] == '\0' );
TESTCASE( s[8] == 'x' );
s[0] = '\0';
TESTCASE( strcat( s, abcdx ) == s );
TESTCASE( s[4] == 'x' );
TESTCASE( s[5] == '\0' );
TESTCASE( strcat( s, "\0" ) == s );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,103 @@
/* strcat_s( char *, rsize_t, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t strcat_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2 )
{
char * dest = s1;
const char * src = s2;
if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && s1max != 0 )
{
while ( *dest )
{
if ( s1max-- == 0 || dest++ == s2 )
{
goto runtime_constraint_violation;
}
}
do
{
if ( s1max-- == 0 || dest == s2 || src == s1 )
{
goto runtime_constraint_violation;
}
} while ( ( *dest++ = *src++ ) );
return 0;
}
runtime_constraint_violation:
if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX )
{
s1[0] = '\0';
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xx\0xxxxxx";
set_constraint_handler_s( test_handler );
TESTCASE( strcat_s( s, 10, abcde ) == 0 );
TESTCASE( s[2] == 'a' );
TESTCASE( s[6] == 'e' );
TESTCASE( s[7] == '\0' );
TESTCASE( s[8] == 'x' );
s[0] = '\0';
TESTCASE( strcat_s( s, 10, abcdx ) == 0 );
TESTCASE( s[4] == 'x' );
TESTCASE( s[5] == '\0' );
TESTCASE( strcat_s( s, 10, "\0" ) == 0 );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
TESTCASE( strcat_s( s, 6, "" ) == 0 );
TESTCASE( strcat_s( s, 5, "" ) != 0 );
TESTCASE( strcat_s( s, 7, "x" ) == 0 );
TESTCASE( s[5] == 'x' );
TESTCASE( s[6] == '\0' );
/* Overlapping */
TESTCASE( strcat_s( s, 7, s + 6 ) != 0 );
s[3] = '\0';
TESTCASE( strcat_s( s + 3, 4, s ) != 0 );
TESTCASE( HANDLER_CALLS == 3 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,41 @@
/* strchr( const char *, int )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strchr( const char * s, int c )
{
do
{
if ( *s == ( char ) c )
{
return ( char * ) s;
}
} while ( *s++ );
return NULL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char abccd[] = "abccd";
TESTCASE( strchr( abccd, 'x' ) == NULL );
TESTCASE( strchr( abccd, 'a' ) == &abccd[0] );
TESTCASE( strchr( abccd, 'd' ) == &abccd[4] );
TESTCASE( strchr( abccd, '\0' ) == &abccd[5] );
TESTCASE( strchr( abccd, 'c' ) == &abccd[2] );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,42 @@
/* strcmp( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
int strcmp( const char * s1, const char * s2 )
{
while ( ( *s1 ) && ( *s1 == *s2 ) )
{
++s1;
++s2;
}
return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char cmpabcde[] = "abcde";
char cmpabcd_[] = "abcd\xfc";
char empty[] = "";
TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
TESTCASE( strcmp( abcde, abcdx ) < 0 );
TESTCASE( strcmp( abcdx, abcde ) > 0 );
TESTCASE( strcmp( empty, abcde ) < 0 );
TESTCASE( strcmp( abcde, empty ) > 0 );
TESTCASE( strcmp( abcde, cmpabcd_ ) < 0 );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,37 @@
/* strcoll( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
#include <locale.h>
int strcoll( const char * s1, const char * s2 )
{
/* FIXME: This should access _PDCLIB_lc_collate. */
return strcmp( s1, s2 );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char cmpabcde[] = "abcde";
char empty[] = "";
TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
TESTCASE( strcmp( abcde, abcdx ) < 0 );
TESTCASE( strcmp( abcdx, abcde ) > 0 );
TESTCASE( strcmp( empty, abcde ) < 0 );
TESTCASE( strcmp( abcde, empty ) > 0 );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,42 @@
/* strcpy( char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
{
char * rc = s1;
while ( ( *s1++ = *s2++ ) )
{
/* EMPTY */
}
return rc;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xxxxx";
TESTCASE( strcpy( s, "" ) == s );
TESTCASE( s[0] == '\0' );
TESTCASE( s[1] == 'x' );
TESTCASE( strcpy( s, abcde ) == s );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,89 @@
/* strcpy_s( char *, rsize_t, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t strcpy_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2 )
{
char * dest = s1;
const char * src = s2;
if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && s1max != 0 )
{
while ( s1max-- )
{
if ( dest == s2 || src == s1 )
{
goto runtime_constraint_violation;
}
if ( ( *dest++ = *src++ ) == '\0' )
{
return 0;
}
}
}
runtime_constraint_violation:
if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX )
{
s1[0] = '\0';
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xxxxx";
set_constraint_handler_s( test_handler );
TESTCASE( strcpy_s( s, 6, "" ) == 0 );
TESTCASE( s[0] == '\0' );
TESTCASE( s[1] == 'x' );
TESTCASE( strcpy_s( s, 6, abcde ) == 0 );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
/* Overrun. */
TESTCASE( strcpy_s( s, 6, "abcdef" ) != 0 );
/* Overlapping. */
TESTCASE( strcpy_s( s, 3, s + 2 ) != 0 );
TESTCASE( strcpy_s( s + 2, 3, s ) != 0 );
TESTCASE( HANDLER_CALLS == 3 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,54 @@
/* strcspn( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
size_t strcspn( const char * s1, const char * s2 )
{
size_t len = 0;
const char * p;
while ( s1[len] )
{
p = s2;
while ( *p )
{
if ( s1[len] == *p++ )
{
return len;
}
}
++len;
}
return len;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
TESTCASE( strcspn( abcde, "x" ) == 5 );
TESTCASE( strcspn( abcde, "xyz" ) == 5 );
TESTCASE( strcspn( abcde, "zyx" ) == 5 );
TESTCASE( strcspn( abcdx, "x" ) == 4 );
TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
TESTCASE( strcspn( abcde, "a" ) == 0 );
TESTCASE( strcspn( abcde, "abc" ) == 0 );
TESTCASE( strcspn( abcde, "cba" ) == 0 );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,41 @@
/* strerror( int )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
#include <locale.h>
/* TODO: Doing this via a static array is not the way to do it. */
char * strerror( int errnum )
{
if ( errnum >= _PDCLIB_ERRNO_MAX || errnum < 0 )
{
return _PDCLIB_EUNKNOWN_TEXT;
}
else
{
return _PDCLIB_lc_messages->errno_texts[errnum];
}
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#include <stdio.h>
#include <errno.h>
int main( void )
{
TESTCASE( strerror( ERANGE ) != strerror( EDOM ) );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,69 @@
/* strerror_s( char *, rsize_t, errno_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef REGTEST
#include <locale.h>
errno_t strerror_s( char * s, rsize_t maxsize, errno_t errnum )
{
size_t len = strerrorlen_s( errnum );
if ( s == NULL || maxsize > RSIZE_MAX || maxsize == 0 )
{
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
if ( len < maxsize )
{
strcpy( s, strerror( errnum ) );
}
else
{
strncpy( s, strerror( errnum ), maxsize - 1 );
if ( maxsize > 3 )
{
strcpy( &s[ maxsize - 4 ], "..." );
}
else
{
s[ maxsize - 1 ] = '\0';
}
}
return 0;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#include <stdio.h>
#include <errno.h>
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[14];
TESTCASE( strerror_s( s, 14, _PDCLIB_ERRNO_MAX ) == 0 );
TESTCASE( strcmp( s, "unknown error" ) == 0 );
TESTCASE( strerror_s( s, 13, _PDCLIB_ERRNO_MAX ) == 0 );
TESTCASE( strcmp( s, "unknown e..." ) == 0 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,29 @@
/* strerrorlen_s( errno_t error )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#ifndef REGTEST
size_t strerrorlen_s( errno_t errnum )
{
return strlen( strerror( errnum ) );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
TESTCASE( NO_TESTDRIVER );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,36 @@
/* strlen( const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
size_t strlen( const char * s )
{
size_t rc = 0;
while ( s[rc] )
{
++rc;
}
return rc;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
TESTCASE( strlen( abcde ) == 5 );
TESTCASE( strlen( "" ) == 0 );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,64 @@
/* strncat( char *, const char *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
{
char * rc = s1;
while ( *s1 )
{
++s1;
}
while ( n && ( *s1++ = *s2++ ) )
{
--n;
}
if ( n == 0 )
{
*s1 = '\0';
}
return rc;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xx\0xxxxxx";
TESTCASE( strncat( s, abcde, 10 ) == s );
TESTCASE( s[2] == 'a' );
TESTCASE( s[6] == 'e' );
TESTCASE( s[7] == '\0' );
TESTCASE( s[8] == 'x' );
s[0] = '\0';
TESTCASE( strncat( s, abcdx, 10 ) == s );
TESTCASE( s[4] == 'x' );
TESTCASE( s[5] == '\0' );
TESTCASE( strncat( s, "\0", 10 ) == s );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
TESTCASE( strncat( s, abcde, 0 ) == s );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
TESTCASE( strncat( s, abcde, 3 ) == s );
TESTCASE( s[5] == 'a' );
TESTCASE( s[7] == 'c' );
TESTCASE( s[8] == '\0' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,118 @@
/* strncat_s( char *, rsize_t, const char *, rsize_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t strncat_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2, rsize_t n )
{
char * dest = s1;
const char * src = s2;
if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && n <= RSIZE_MAX && s1max != 0 )
{
while ( *dest )
{
if ( --s1max == 0 || dest++ == s2 )
{
goto runtime_constraint_violation;
}
}
do
{
if ( n-- == 0 )
{
*dest = '\0';
return 0;
}
if ( s1max-- == 0 || dest == s2 || src == s1 )
{
goto runtime_constraint_violation;
}
} while ( ( *dest++ = *src++ ) );
return 0;
}
runtime_constraint_violation:
if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX )
{
s1[0] = '\0';
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xx\0xxxxxx";
set_constraint_handler_s( test_handler );
TESTCASE( strncat_s( s, 10, abcde, 10 ) == 0 );
TESTCASE( s[2] == 'a' );
TESTCASE( s[6] == 'e' );
TESTCASE( s[7] == '\0' );
TESTCASE( s[8] == 'x' );
s[0] = '\0';
TESTCASE( strncat_s( s, 10, abcdx, 10 ) == 0 );
TESTCASE( s[4] == 'x' );
TESTCASE( s[5] == '\0' );
TESTCASE( strncat_s( s, 10, "\0", 10 ) == 0 );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
TESTCASE( strncat_s( s, 10, abcde, 0 ) == 0 );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
TESTCASE( strncat_s( s, 10, abcde, 3 ) == 0 );
TESTCASE( s[5] == 'a' );
TESTCASE( s[7] == 'c' );
TESTCASE( s[8] == '\0' );
TESTCASE( strncat_s( s, 9, "", 0 ) == 0 );
TESTCASE( strncat_s( s, 8, "", 0 ) != 0 );
TESTCASE( strncat_s( s, 8, "x", 0 ) != 0 );
TESTCASE( strncat_s( s, 9, "x", 0 ) == 0 );
TESTCASE( strncat_s( s, 10, "x", 1 ) == 0 );
TESTCASE( s[8] == 'x' );
TESTCASE( s[9] == '\0' );
/* Overlapping */
TESTCASE( strcat_s( s, 7, s + 6 ) != 0 );
s[3] = '\0';
TESTCASE( strcat_s( s + 3, 4, s ) != 0 );
TESTCASE( HANDLER_CALLS == 4 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,55 @@
/* strncmp( const char *, const char *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
int strncmp( const char * s1, const char * s2, size_t n )
{
while ( n && *s1 && ( *s1 == *s2 ) )
{
++s1;
++s2;
--n;
}
if ( n == 0 )
{
return 0;
}
else
{
return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
}
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char cmpabcde[] = "abcde\0f";
char cmpabcd_[] = "abcde\xfc";
char empty[] = "";
char x[] = "x";
TESTCASE( strncmp( abcde, cmpabcde, 5 ) == 0 );
TESTCASE( strncmp( abcde, cmpabcde, 10 ) == 0 );
TESTCASE( strncmp( abcde, abcdx, 5 ) < 0 );
TESTCASE( strncmp( abcdx, abcde, 5 ) > 0 );
TESTCASE( strncmp( empty, abcde, 5 ) < 0 );
TESTCASE( strncmp( abcde, empty, 5 ) > 0 );
TESTCASE( strncmp( abcde, abcdx, 4 ) == 0 );
TESTCASE( strncmp( abcde, x, 0 ) == 0 );
TESTCASE( strncmp( abcde, x, 1 ) < 0 );
TESTCASE( strncmp( abcde, cmpabcd_, 10 ) < 0 );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,59 @@
/* strncpy( char *, const char *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
{
char * rc = s1;
while ( n && ( *s1++ = *s2++ ) )
{
/* Cannot do "n--" in the conditional as size_t is unsigned and we have
to check it again for >0 in the next loop below, so we must not risk
underflow.
*/
--n;
}
/* Checking against 1 as we missed the last --n in the loop above. */
while ( n-- > 1 )
{
*s1++ = '\0';
}
return rc;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xxxxxxx";
TESTCASE( strncpy( s, "", 1 ) == s );
TESTCASE( s[0] == '\0' );
TESTCASE( s[1] == 'x' );
TESTCASE( strncpy( s, abcde, 6 ) == s );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'x' );
TESTCASE( strncpy( s, abcde, 7 ) == s );
TESTCASE( s[6] == '\0' );
TESTCASE( strncpy( s, "xxxx", 3 ) == s );
TESTCASE( s[0] == 'x' );
TESTCASE( s[2] == 'x' );
TESTCASE( s[3] == 'd' );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,95 @@
/* strncpy_s( char *, rsize_t, const char *, rsize_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef REGTEST
errno_t strncpy_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2, rsize_t n )
{
char * dest = s1;
const char * src = s2;
if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && n <= RSIZE_MAX && s1max != 0 )
{
while ( s1max-- )
{
if ( dest == s2 || src == s1 )
{
goto runtime_constraint_violation;
}
if ( n-- == 0 || ( *dest++ = *src++ ) == '\0' )
{
return 0;
}
}
}
runtime_constraint_violation:
if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX )
{
s1[0] = '\0';
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
static int HANDLER_CALLS = 0;
static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error )
{
++HANDLER_CALLS;
}
#endif
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "xxxxxxx";
set_constraint_handler_s( test_handler );
TESTCASE( strncpy_s( s, 8, "", 1 ) == 0 );
TESTCASE( s[0] == '\0' );
TESTCASE( s[1] == 'x' );
TESTCASE( strncpy_s( s, 8, abcde, 6 ) == 0 );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'x' );
TESTCASE( strncpy_s( s, 8, abcde, 7 ) == 0 );
/* Different from strncpy()! */
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'x' );
TESTCASE( strncpy_s( s, 8, "xxxx", 3 ) == 0 );
TESTCASE( s[0] == 'x' );
TESTCASE( s[2] == 'x' );
TESTCASE( s[3] == 'd' );
/* Overrun. */
TESTCASE( strncpy_s( s, 8, "abcdefgh", 9 ) != 0 );
TESTCASE( strncpy_s( s, 8, "abcdefgh", 9 ) != 0 );
TESTCASE( HANDLER_CALLS == 2 );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,53 @@
/* strpbrk( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strpbrk( const char * s1, const char * s2 )
{
const char * p1 = s1;
const char * p2;
while ( *p1 )
{
p2 = s2;
while ( *p2 )
{
if ( *p1 == *p2++ )
{
return ( char * ) p1;
}
}
++p1;
}
return NULL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
TESTCASE( strpbrk( abcde, "x" ) == NULL );
TESTCASE( strpbrk( abcde, "xyz" ) == NULL );
TESTCASE( strpbrk( abcdx, "x" ) == &abcdx[4] );
TESTCASE( strpbrk( abcdx, "xyz" ) == &abcdx[4] );
TESTCASE( strpbrk( abcdx, "zyx" ) == &abcdx[4] );
TESTCASE( strpbrk( abcde, "a" ) == &abcde[0] );
TESTCASE( strpbrk( abcde, "abc" ) == &abcde[0] );
TESTCASE( strpbrk( abcde, "cba" ) == &abcde[0] );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,47 @@
/* strrchr( const char *, int )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strrchr( const char * s, int c )
{
size_t i = 0;
while ( s[i++] )
{
/* EMPTY */
}
do
{
if ( s[--i] == ( char ) c )
{
return ( char * ) s + i;
}
} while ( i );
return NULL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char abccd[] = "abccd";
TESTCASE( strrchr( abcde, '\0' ) == &abcde[5] );
TESTCASE( strrchr( abcde, 'e' ) == &abcde[4] );
TESTCASE( strrchr( abcde, 'a' ) == &abcde[0] );
TESTCASE( strrchr( abccd, 'c' ) == &abccd[3] );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,55 @@
/* strspn( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
size_t strspn( const char * s1, const char * s2 )
{
size_t len = 0;
const char * p;
while ( s1[ len ] )
{
p = s2;
while ( *p )
{
if ( s1[len] == *p )
{
break;
}
++p;
}
if ( ! *p )
{
return len;
}
++len;
}
return len;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
TESTCASE( strspn( abcde, "abc" ) == 3 );
TESTCASE( strspn( abcde, "b" ) == 0 );
TESTCASE( strspn( abcde, abcde ) == 5 );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,56 @@
/* strstr( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
char * strstr( const char * s1, const char * s2 )
{
const char * p1 = s1;
const char * p2;
while ( *s1 )
{
p2 = s2;
while ( *p2 && ( *p1 == *p2 ) )
{
++p1;
++p2;
}
if ( ! *p2 )
{
return ( char * ) s1;
}
++s1;
p1 = s1;
}
return NULL;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "abcabcabcdabcde";
TESTCASE( strstr( s, "x" ) == NULL );
TESTCASE( strstr( s, "xyz" ) == NULL );
TESTCASE( strstr( s, "a" ) == &s[0] );
TESTCASE( strstr( s, "abc" ) == &s[0] );
TESTCASE( strstr( s, "abcd" ) == &s[6] );
TESTCASE( strstr( s, "abcde" ) == &s[10] );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,64 @@
/* strtok( char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#ifndef REGTEST
#define __STDC_WANT_LIB_EXT1__ 1
#endif
#include <string.h>
#ifndef REGTEST
char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
{
static char * tmp = NULL;
static rsize_t max;
if ( s1 != NULL )
{
/* new string */
tmp = s1;
max = strlen( tmp );
}
return _PDCLIB_strtok( s1, &max, s2, &tmp );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "_a_bc__d_";
TESTCASE( strtok( s, "_" ) == &s[1] );
TESTCASE( s[1] == 'a' );
TESTCASE( s[2] == '\0' );
TESTCASE( strtok( NULL, "_" ) == &s[3] );
TESTCASE( s[3] == 'b' );
TESTCASE( s[4] == 'c' );
TESTCASE( s[5] == '\0' );
TESTCASE( strtok( NULL, "_" ) == &s[7] );
TESTCASE( s[6] == '_' );
TESTCASE( s[7] == 'd' );
TESTCASE( s[8] == '\0' );
TESTCASE( strtok( NULL, "_" ) == NULL );
strcpy( s, "ab_cd" );
TESTCASE( strtok( s, "_" ) == &s[0] );
TESTCASE( s[0] == 'a' );
TESTCASE( s[1] == 'b' );
TESTCASE( s[2] == '\0' );
TESTCASE( strtok( NULL, "_" ) == &s[3] );
TESTCASE( s[3] == 'c' );
TESTCASE( s[4] == 'd' );
TESTCASE( s[5] == '\0' );
TESTCASE( strtok( NULL, "_" ) == NULL );
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,72 @@
/* strtok_s( char *, rsize_t *, const char *, char ** )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#ifndef REGTEST
char * strtok_s( char * _PDCLIB_restrict s1, rsize_t * _PDCLIB_restrict s1max, const char * _PDCLIB_restrict s2, char ** _PDCLIB_restrict ptr )
{
return _PDCLIB_strtok( s1, s1max, s2, ptr );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ )
char s[] = "_a_bc__d_";
char str1[] = "?a???b,,,#c";
char str2[] = "\t \t";
rsize_t max = sizeof( s );
rsize_t max1 = sizeof( str1 );
rsize_t max2 = sizeof( str2 );
char * p;
char * ptr1;
char * ptr2;
TESTCASE( _PDCLIB_strtok( s, &max, "_", &p ) == &s[1] );
TESTCASE( s[1] == 'a' );
TESTCASE( s[2] == '\0' );
TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[3] );
TESTCASE( s[3] == 'b' );
TESTCASE( s[4] == 'c' );
TESTCASE( s[5] == '\0' );
TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[7] );
TESTCASE( s[6] == '_' );
TESTCASE( s[7] == 'd' );
TESTCASE( s[8] == '\0' );
TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == NULL );
strcpy( s, "ab_cd" );
max = strlen( s );
TESTCASE( _PDCLIB_strtok( s, &max, "_", &p ) == &s[0] );
TESTCASE( s[0] == 'a' );
TESTCASE( s[1] == 'b' );
TESTCASE( s[2] == '\0' );
TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[3] );
TESTCASE( s[3] == 'c' );
TESTCASE( s[4] == 'd' );
TESTCASE( s[5] == '\0' );
TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == NULL );
TESTCASE( _PDCLIB_strtok( str1, &max1, "?", &ptr1 ) == &str1[1] );
TESTCASE( _PDCLIB_strtok( NULL, &max1, ",", &ptr1 ) == &str1[3] );
TESTCASE( _PDCLIB_strtok( str2, &max2, " \t", &ptr2 ) == NULL );
TESTCASE( _PDCLIB_strtok( NULL, &max1, "#,", &ptr1 ) == &str1[10] );
TESTCASE( _PDCLIB_strtok( NULL, &max1, "?", &ptr1 ) == NULL );
#else
/* Most libraries do not implement this function. */
TESTCASE( NO_TESTDRIVER );
#endif
return TEST_RESULTS;
}
#endif

View File

@@ -0,0 +1,54 @@
/* strxfrm( char *, const char *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
#include <locale.h>
size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
{
size_t len = strlen( s2 );
if ( len < n )
{
/* Cannot use strncpy() here as the filling of s1 with '\0' is not part
of the spec.
*/
/* FIXME: This should access _PDCLIB_lc_collate. */
while ( n-- && ( *s1++ = ( unsigned char )*s2++ ) )
{
/* EMPTY */
}
}
return len;
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char s[] = "xxxxxxxxxxx";
TESTCASE( strxfrm( NULL, "123456789012", 0 ) == 12 );
TESTCASE( strxfrm( s, "123456789012", 12 ) == 12 );
/*
The following test case is true in *this* implementation, but doesn't have to.
TESTCASE( s[0] == 'x' );
*/
TESTCASE( strxfrm( s, "1234567890", 11 ) == 10 );
TESTCASE( s[0] == '1' );
TESTCASE( s[9] == '0' );
TESTCASE( s[10] == '\0' );
return TEST_RESULTS;
}
#endif