From: solar Date: Thu, 15 Dec 2005 12:34:01 +0000 (+0000) Subject: Initial checkin. X-Git-Tag: v0.4~39 X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=8a210237d6ac0dfb36ca14b5aebe8be2b967b9e6 Initial checkin. --- diff --git a/functions/_PDCLIB/seed.c b/functions/_PDCLIB/seed.c new file mode 100644 index 0000000..df0c55d --- /dev/null +++ b/functions/_PDCLIB/seed.c @@ -0,0 +1,23 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* _PDCLIB_seed + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +unsigned long int _PDCLIB_seed = 1; + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + BEGIN_TESTS; + /* no tests for raw data */ + return TEST_RESULTS; +} + +#endif diff --git a/functions/stdlib/rand.c b/functions/stdlib/rand.c new file mode 100644 index 0000000..1ad3e91 --- /dev/null +++ b/functions/stdlib/rand.c @@ -0,0 +1,38 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* rand() + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +int rand() +{ + _PDCLIB_seed = _PDCLIB_seed * 1103515245 + 12345; + return (unsigned int) ( _PDCLIB_seed / 65536 ) % 32768; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + int rnd1, rnd2; + BEGIN_TESTS; + TESTCASE( ( rnd1 = rand() ) < RAND_MAX ); + TESTCASE( ( rnd2 = rand() ) < RAND_MAX ); + srand( 1 ); + TESTCASE( rand() == rnd1 ); + TESTCASE( rand() == rnd2 ); + return TEST_RESULTS; +} + +#endif diff --git a/functions/stdlib/srand.c b/functions/stdlib/srand.c new file mode 100644 index 0000000..f207de8 --- /dev/null +++ b/functions/stdlib/srand.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* srand( unsigned int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +void srand( unsigned int seed ) +{ + _PDCLIB_seed = seed; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + BEGIN_TESTS; + /* tested in rand.c */ + return TEST_RESULTS; +} + +#endif diff --git a/includes/stdio.h b/includes/stdio.h new file mode 100644 index 0000000..df9bfe4 --- /dev/null +++ b/includes/stdio.h @@ -0,0 +1,30 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* Input/output + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* TODO: This is a dummy header to avoid errors when mixing PDCLIB */ +/* with glibc . */ + +#ifndef _PDCLIB_STDIO_H +#define _PDCLIB_STDIO_H _PDCLIB_STDIO_H + +#ifndef _PDCLIB_AUX_H +#define _PDCLIB_AUX_H _PDCLIB_AUX_H +#include <_PDCLIB_aux.h> +#endif + +typedef void * FILE; + +extern void * stderr; + +int printf( const char * _PDCLIB_restrict format, ... ); +int fputs( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream ); +int puts( const char * _PDCLIB_restrict s ); + +#endif diff --git a/includes/stdlib.h b/includes/stdlib.h new file mode 100644 index 0000000..6c31a46 --- /dev/null +++ b/includes/stdlib.h @@ -0,0 +1,80 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* General utilities + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_STDLIB_H +#define _PDCLIB_STDLIB_H _PDCLIB_STDLIB_H + +#ifndef _PDCLIB_AUX_H +#define _PDCLIB_AUX_H _PDCLIB_AUX_H +#include <_PDCLIB_aux.h> +#endif + +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +typedef struct _PDCLIB_div_t div_t; +typedef struct _PDCLIB_ldiv_t ldiv_t; +typedef struct _PDCLIB_lldiv_t lldiv_t; + +#define NULL _PDCLIB_NULL +#define EXIT_SUCCESS _PDCLIB_SUCCESS; +#define EXIT_FAILURE _PDCLIB_FAILURE; + +/* Numeric conversion functions */ + +int atoi( const char * nptr ); +long int atol( const char * nptr ); +long long int atoll( const char * nptr ); + +long int strtol( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); +long long int strtoll( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); +unsigned long int strtoul( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); +unsigned long long int strtoull( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); + +/* Pseudo-random sequence generation functions */ + +extern unsigned long int _PDCLIB_seed; + +#define RAND_MAX 32767 + +int rand(); +void srand( unsigned int seed ); + +/* Memory management functions */ + + +/* Communication with the environment */ + +void abort(); +void exit(); + +/* Searching and sorting */ + + +/* Integer arithmetic functions */ + +int abs( int j ); +long int labs( long int j ); +long long int llabs( long long int j ); + +div_t div( int numer, int denom ); +ldiv_t ldiv( long int numer, long int denom ); +lldiv_t lldiv( long long int numer, long long int denom ); + +/* Multibyte / wide character conversion functions */ + +/* TODO: Macro MB_CUR_MAX */ + +/* Multibyte / wide string conversion functions */ + + +#endif