#ifndef __STDC_VERSION__
#define _PDCLIB_C_VERSION 90
+#define _PDCLIB_restrict
#elif __STDC_VERSION__ == 199409L
#define _PDCLIB_C_VERSION 95
+#define _PDCLIB_restrict
#elif __STDC_VERSION__ == 199901L
#define _PDCLIB_C_VERSION 99
+#define _PDCLIB_restrict restrict
#else
#error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, and 9899:1999).
#endif
#ifndef __STDC_HOSTED__
-#error Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)!
+#warning Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)!
#elif __STDC_HOSTED__ == 0
#define _PDCLIB_HOSTED 0
#elif __STDC_HOSTED__ == 1
#warning PDCLib might not be fully conforming to either C89 or C95 prior to v2.x.
#endif
-#if _PDCLIB_HOSTED != 0
-#warning Up to the 1.x release, PDCLib is only complete as a freestanding environment.
-#warning PDCLib might not be fully conforming as a hosted environment.
-#endif
-
/* -------------------------------------------------------------------------- */
/* Helper macros: */
/* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending */
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+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;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+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 *p2 - *p1;
+ }
+ ++p1;
+ ++p2;
+ }
+ return 0;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+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;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+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;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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 <_PDCLIB_aux.h>
+
+char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
+{
+ char * rc = s1;
+ if ( *s1 )
+ {
+ while ( *++s1 );
+ }
+ while ( (*s1++ = *s2++) );
+ return rc;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+char * strchr( const char * s, int c )
+{
+ do
+ {
+ if ( *s == (char) c )
+ {
+ return (char *) s;
+ }
+ } while ( *s++ );
+ return NULL;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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.
+*/
+
+int strcmp( const char * s1, const char * s2 )
+{
+ while ( ( *s1 ) && ( *s1 == *s2 ) )
+ {
+ ++s1;
+ ++s2;
+ }
+ return ( *s1 - *s2 );
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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.
+*/
+
+/* TODO: Dummy function, PDCLib does not support locales yet. */
+
+int strcmp( const char * s1, const char * s2 );
+
+int strcoll( const char * s1, const char * s2 )
+{
+ return strcmp( s1, s2 );
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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 <_PDCLIB_aux.h>
+
+char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
+{
+ char * rc = s1;
+ while ( ( *s1++ = *s2++ ) );
+ return rc;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+size_t strcspn( const char * src_1, const char * src_2 )
+{
+ size_t len = 0;
+ const char * src_p;
+ while ( src_1[len] != '\0' )
+ {
+ src_p = src_2;
+ while ( *src_p != '\0' )
+ {
+ if ( src_1[len] == *src_p++ )
+ {
+ return len;
+ }
+ }
+ ++len;
+ }
+ return len;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+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;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+int strncmp( const char * s1, const char * s2, size_t n )
+{
+ while ( n && ( *s1 == *s2 ) )
+ {
+ ++s1;
+ ++s2;
+ --n;
+ }
+ if ( ( n == 0 ) )
+ {
+ return 0;
+ }
+ else
+ {
+ return ( *s1 - *s2 );
+ }
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
+{
+ char * rc = s1;
+ while ( ( n > 0 ) && ( *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.
+ */
+ --n;
+ }
+ while ( n-- )
+ {
+ *s1++ = '\0';
+ }
+ return rc;
+}
--- /dev/null
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 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>
+
+/* TODO: Dummy function, no locale support yet. */
+
+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.
+ */
+ while ( n-- && ( *s1++ = *s2++ ) );
+ }
+ return len;
+}