From: Owen Shepherd Date: Tue, 7 Oct 2014 22:23:56 +0000 (+0100) Subject: Modify various POSIX platform files so you can build on top of glibc for testing X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=37f62a3ac31302556f0cdad12b2250a6fc7872f1 Modify various POSIX platform files so you can build on top of glibc for testing --- diff --git a/opt/pthreads/_PDCLIB_threadconfig.h b/opt/pthreads/_PDCLIB_threadconfig.h index 75e6f3a..b855def 100644 --- a/opt/pthreads/_PDCLIB_threadconfig.h +++ b/opt/pthreads/_PDCLIB_threadconfig.h @@ -16,7 +16,16 @@ typedef __darwin_pthread_once_t _PDCLIB_once_flag; #define _PDCLIB_ONCE_FLAG_INIT {_PTHREAD_ONCE_SIG_init, {0}} #else -#error Need to interrogate the C library headers for your platform +/* Just include pthread.h */ +#include +#define _PDCLIB_THR_T pthread_t +#define _PDCLIB_CND_T pthread_cond_t +#define _PDCLIB_MTX_T pthread_mutex_t +#define _PDCLIB_TSS_DTOR_ITERATIONS 5 +#define _PDCLIB_TSS_T pthread_key_t +typedef pthread_once_t _PDCLIB_once_flag; +#define _PDCLIB_ONCE_FLAG_INIT PTHREAD_ONCE_INIT + #endif _PDCLIB_END_EXTERN_C diff --git a/opt/pthreads/mtx_init.c b/opt/pthreads/mtx_init.c index 90c67e6..fd1ad71 100644 --- a/opt/pthreads/mtx_init.c +++ b/opt/pthreads/mtx_init.c @@ -1,4 +1,5 @@ #ifndef REGTEST +#define _POSIX_C_SOURCE 2008098L #include #include diff --git a/opt/pthreads/mtx_timedlock.c b/opt/pthreads/mtx_timedlock.c index ed490a8..6cd1b86 100644 --- a/opt/pthreads/mtx_timedlock.c +++ b/opt/pthreads/mtx_timedlock.c @@ -1,15 +1,17 @@ #ifndef REGTEST +#define _POSIX_C_SOURCE 2008098L #include // On Mac OS X, supress system definition of struct timespec #ifdef __APPLE__ #define _STRUCT_TIMESPEC struct timespec #endif #include +#include #include /* Can only implement if timeouts are supported. * - * Namely, Mac OS X does not implement timeouts + * Namely, Mac OS X does not implement timeouts */ #if defined(_POSIX_TIMEOUTS) && (_POSIX_TIMEOUTS - 200112L) >= 0L int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) diff --git a/platform/posix/Config.jam b/platform/posix/Config.jam index 52d0e62..be1dd25 100644 --- a/platform/posix/Config.jam +++ b/platform/posix/Config.jam @@ -7,8 +7,13 @@ rule PDCLibTargetHeaders { if $(OS) = "MACOSX" { # Need to link libSystem } else { - PDCLIB_TEST_LINKFLAGS += -nostdlib ; - PDCLIB_TEST_LINKLIBS += -lgcc ; + #PDCLIB_TEST_LINKFLAGS += -nostdlib ; + PDCLIB_TEST_LINKLIBS += -lgcc -lpthread ; } -PDCLIB_OPTIONS = pthreads notime dlmalloc basecodecs c_locale ; \ No newline at end of file +PDCLIB_OPTIONS = + pthreads + notime + dlmalloc + basecodecs + c_locale ; diff --git a/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c b/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c index c63e780..4d9f16a 100644 --- a/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c +++ b/platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c @@ -9,11 +9,18 @@ */ #ifndef REGTEST +#ifdef __linux__ +#define _GNU_SOURCE +#endif #include #include #include #include <_PDCLIB_glue.h> +#ifndef MAP_ANON +#define MAP_ANON MAP_ANOYNMOUS +#endif + void * _PDCLIB_allocpages( size_t n ) { void *addr = mmap( diff --git a/platform/posix/functions/stdio/_PDCLIB_fileops.c b/platform/posix/functions/stdio/_PDCLIB_fileops.c index 20138b7..2b75c41 100644 --- a/platform/posix/functions/stdio/_PDCLIB_fileops.c +++ b/platform/posix/functions/stdio/_PDCLIB_fileops.c @@ -5,13 +5,15 @@ */ #ifndef REGTEST +#define _FILE_OFFSET_BITS 64 #include #include #include <_PDCLIB_glue.h> #include #include +typedef int64_t off_t; -static bool readf( _PDCLIB_fd_t fd, void * buf, size_t length, +static bool readf( _PDCLIB_fd_t fd, void * buf, size_t length, size_t * numBytesRead ) { ssize_t res = read(fd.sval, buf, length); @@ -23,7 +25,7 @@ static bool readf( _PDCLIB_fd_t fd, void * buf, size_t length, } } -static bool writef( _PDCLIB_fd_t fd, const void * buf, size_t length, +static bool writef( _PDCLIB_fd_t fd, const void * buf, size_t length, size_t * numBytesWritten ) { ssize_t res = write(fd.sval, buf, length); diff --git a/platform/posix/functions/stdio/_PDCLIB_open.c b/platform/posix/functions/stdio/_PDCLIB_open.c index 17bd022..ac2fd76 100644 --- a/platform/posix/functions/stdio/_PDCLIB_open.c +++ b/platform/posix/functions/stdio/_PDCLIB_open.c @@ -1,4 +1,4 @@ -/* _PDCLIB_open(_PDCLIB_fd_t*, const _PDCLIB_fileops_t**, +/* _PDCLIB_open(_PDCLIB_fd_t*, const _PDCLIB_fileops_t**, char const*, unsigned int) This file is part of the Public Domain C Library (PDCLib). @@ -9,9 +9,10 @@ #include <_PDCLIB_io.h> #include + extern const _PDCLIB_fileops_t _PDCLIB_fileops; -bool _PDCLIB_open( +bool _PDCLIB_open( _PDCLIB_fd_t* fd, const _PDCLIB_fileops_t** ops, char const * filename, unsigned int mode ) { @@ -40,8 +41,7 @@ bool _PDCLIB_open( return -1; } - fd->sval = open(filename, osmode, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + fd->sval = open(filename, osmode, 0664); if(fd->sval == -1) { return false; } diff --git a/platform/posix/functions/stdio/tmpfile.c b/platform/posix/functions/stdio/tmpfile.c index deb992c..ad7aa7e 100644 --- a/platform/posix/functions/stdio/tmpfile.c +++ b/platform/posix/functions/stdio/tmpfile.c @@ -13,13 +13,15 @@ #include #include #include - #include <_PDCLIB_glue.h> - -#include -#include -#include #include +#ifdef __linux__ +/* get O_CLOEXEC without sys/types.h being awful */ +#include +int open(const char *fname, int flags, ...); +#else +#include +#endif extern const _PDCLIB_fileops_t _PDCLIB_fileops; @@ -52,7 +54,7 @@ FILE* _PDCLIB_nothrow tmpfile( void ) (file might exist but not readable). Replace with something more appropriate. */ - fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR ); + fd = open( filename, O_CREAT | O_EXCL | O_RDWR, 0600 ); if ( fd != -1 ) { break; @@ -61,9 +63,9 @@ FILE* _PDCLIB_nothrow tmpfile( void ) close( urandom ); FILE* rc = _PDCLIB_fvopen(((_PDCLIB_fd_t){ .sval = fd}), &_PDCLIB_fileops, - _PDCLIB_FWRITE | _PDCLIB_FRW | + _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_DELONCLOSE, filename); - if( rc == NULL ) + if( rc == NULL ) { close( fd ); return NULL; diff --git a/platform/posix/includes/errno.h b/platform/posix/includes/errno.h deleted file mode 100644 index 5e6f8a0..0000000 --- a/platform/posix/includes/errno.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _PDCLIB_ERRNO_H -#define _PDCLIB_ERRNO_H -#include -#endif diff --git a/platform/posix/internals/_PDCLIB_config.h b/platform/posix/internals/_PDCLIB_config.h index 576b347..ae30e0a 100644 --- a/platform/posix/internals/_PDCLIB_config.h +++ b/platform/posix/internals/_PDCLIB_config.h @@ -121,9 +121,15 @@ struct _PDCLIB_lldiv_t #define _PDCLIB_fast32 int #define _PDCLIB_FAST32_CONV +#ifdef __LP64__ +#define _PDCLIB_FAST64 LONG +#define _PDCLIB_fast64 long +#define _PDCLIB_FAST64_CONV l +#else #define _PDCLIB_FAST64 LLONG #define _PDCLIB_fast64 long long #define _PDCLIB_FAST64_CONV ll +#endif /* -------------------------------------------------------------------------- */ /* What follows are a couple of "special" typedefs and their limits. Again, */ @@ -173,17 +179,17 @@ struct _PDCLIB_imaxdiv_t _PDCLIB_intmax rem; }; -/* : time_t - * The C standard doesn't define what representation of time is stored in +/* : time_t + * The C standard doesn't define what representation of time is stored in * time_t when returned by time() , but POSIX defines it to be seconds since the - * UNIX epoch and most appplications expect that. + * UNIX epoch and most appplications expect that. * - * time_t is also used as the tv_sec member of struct timespec, which *is* + * time_t is also used as the tv_sec member of struct timespec, which *is* * defined as a linear count of seconds. * * time_t is defined as a "real type", so may be a floating point type, but with * the presence of the nanosecond accurate struct timespec, and with the lack of - * any functions for manipulating more accurate values of time_t, this is + * any functions for manipulating more accurate values of time_t, this is * probably not useful. */ #define _PDCLIB_time long @@ -191,12 +197,12 @@ struct _PDCLIB_imaxdiv_t /* : clock_t * * A count of "clock ticks", where the length of a clock tick is unspecified by - * the standard. The implementation is required to provide a macro, + * the standard. The implementation is required to provide a macro, * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one * second. * * clock_t may be any real type (i.e. integral or floating), and its type on - * various systems differs. + * various systems differs. * * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000 */ @@ -207,8 +213,8 @@ struct _PDCLIB_imaxdiv_t * * The TIME_UTC parameter is passed to the timespec_get function in order to get * the system time in UTC since an implementation defined epoch (not necessarily - * the same as that used for time_t). That said, on POSIX the obvious - * implementation of timespec_get for TIME_UTC is to wrap + * the same as that used for time_t). That said, on POSIX the obvious + * implementation of timespec_get for TIME_UTC is to wrap * clock_gettime(CLOCK_REALTIME, ...), which is defined as time in UTC since the * same epoch. *