]> pd.if.org Git - pdclib.old/commitdiff
Modify various POSIX platform files so you can build on top of glibc for testing
authorOwen Shepherd <owen.shepherd@e43.eu>
Tue, 7 Oct 2014 22:23:56 +0000 (23:23 +0100)
committerOwen Shepherd <owen.shepherd@e43.eu>
Tue, 7 Oct 2014 22:23:56 +0000 (23:23 +0100)
opt/pthreads/_PDCLIB_threadconfig.h
opt/pthreads/mtx_init.c
opt/pthreads/mtx_timedlock.c
platform/posix/Config.jam
platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c
platform/posix/functions/stdio/_PDCLIB_fileops.c
platform/posix/functions/stdio/_PDCLIB_open.c
platform/posix/functions/stdio/tmpfile.c
platform/posix/includes/errno.h [deleted file]
platform/posix/internals/_PDCLIB_config.h

index 75e6f3a69230cb25eb6bf5ab421962b4a99312c9..b855def3d15f14563ae6a2f653af5d815d935b9a 100644 (file)
@@ -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 <pthread.h>
+#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
index 90c67e62109b0549b2a5f1ee5000c367e66d23ad..fd1ad71d2f6a47b010f1bf4cff031a778277c186 100644 (file)
@@ -1,4 +1,5 @@
 #ifndef REGTEST
+#define _POSIX_C_SOURCE 2008098L
 #include <threads.h>
 #include <pthread.h>
 
index ed490a874cf836346d24ecb29badd5896201d5b8..6cd1b866ac50982ff88f199bf7221804c9fff46c 100644 (file)
@@ -1,15 +1,17 @@
 #ifndef REGTEST
+#define _POSIX_C_SOURCE 2008098L
 #include <threads.h>
 // On Mac OS X, supress system definition of struct timespec
 #ifdef __APPLE__
     #define _STRUCT_TIMESPEC struct timespec
 #endif
 #include <unistd.h>
+#include <errno.h>
 #include <pthread.h>
 
 /* 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)
index 52d0e62e35826f17c6298f3f0d985e6ee4b409d0..be1dd25aa3fc14252ba727cb9e617a48a9d5712c 100644 (file)
@@ -7,8 +7,13 @@ rule PDCLibTargetHeaders {
 if $(OS) = "MACOSX" {\r
     # Need to link libSystem\r
 } else {\r
-    PDCLIB_TEST_LINKFLAGS += -nostdlib ;\r
-    PDCLIB_TEST_LINKLIBS += -lgcc ;\r
+    #PDCLIB_TEST_LINKFLAGS += -nostdlib ;\r
+    PDCLIB_TEST_LINKLIBS += -lgcc -lpthread ;\r
 }\r
 \r
-PDCLIB_OPTIONS = pthreads notime dlmalloc basecodecs c_locale ;
\ No newline at end of file
+PDCLIB_OPTIONS =\r
+    pthreads\r
+    notime\r
+    dlmalloc\r
+    basecodecs\r
+    c_locale ;\r
index c63e7809ad0c2275e3e0d3fb73355c79c5631dc9..4d9f16a45e18d34e996df8a79b419d5065531030 100644 (file)
@@ -9,11 +9,18 @@
 */
 
 #ifndef REGTEST
+#ifdef __linux__
+#define _GNU_SOURCE
+#endif
 #include <stdint.h>
 #include <stddef.h>
 #include <sys/mman.h>
 #include <_PDCLIB_glue.h>
 
+#ifndef MAP_ANON
+#define MAP_ANON MAP_ANOYNMOUS
+#endif
+
 void * _PDCLIB_allocpages( size_t n )
 {
     void *addr = mmap(
index 20138b722d4c5effd64393664cd866d229930969..2b75c415f7247357c15c2aaab2d67d89972d1bc5 100644 (file)
@@ -5,13 +5,15 @@
 */
 
 #ifndef REGTEST
+#define _FILE_OFFSET_BITS 64
 #include <stdio.h>
 #include <stdint.h>
 #include <_PDCLIB_glue.h>
 #include <errno.h>
 #include <unistd.h>
+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);
index 17bd022e4f51f805a961f2b49d8c8a73f4612bed..ac2fd76121067cf8a33c3a01ec9ce071a9ac3901 100644 (file)
@@ -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 <fcntl.h>
 
+
 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;
     }
index deb992ccbc80e2133e6eb1a102823ba838c06784..ad7aa7e78de86073deb0e0854e15372372696ed2 100644 (file)
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-
 #include <_PDCLIB_glue.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
+#ifdef __linux__
+/* get O_CLOEXEC without sys/types.h being awful */
+#include <asm/fcntl.h>
+int open(const char *fname, int flags, ...);
+#else
+#include <fcntl.h>
+#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 (file)
index 5e6f8a0..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef _PDCLIB_ERRNO_H
-#define _PDCLIB_ERRNO_H
-#include <sys/errno.h>
-#endif
index 576b347c253df2a2984c38426dca97b0f0c0c197..ae30e0a3622f4757cc17ba8a35c7ab0573265c7a 100644 (file)
@@ -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.h>: time_t 
- * The C standard doesn't define what representation of time is stored in 
+/* <time.h>: 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
 /* <time.h>: 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.
  *