#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
#ifndef REGTEST
+#define _POSIX_C_SOURCE 2008098L
#include <threads.h>
#include <pthread.h>
#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)
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
*/
#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(
*/
#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);
}
}
-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);
-/* _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).
#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 )
{
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;
}
#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;
(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;
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;
+++ /dev/null
-#ifndef _PDCLIB_ERRNO_H
-#define _PDCLIB_ERRNO_H
-#include <sys/errno.h>
-#endif
#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, */
_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
/* <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
*/
*
* 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.
*