diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c index 99e14075fd433e30cdb09e02a47395395459de96..03b3fb3cb0793c4d63610fefc0a69a65bcfc5cf8 100644 --- a/src/xpdev/genwrap.c +++ b/src/xpdev/genwrap.c @@ -123,7 +123,7 @@ void DLLCALL unix_beep(int freq, int dur) { static int console_fd=-1; -#if !defined(__OpenBSD__) +#if !defined(__OpenBSD__) && !defined(__GNU__) if(console_fd == -1) console_fd = open("/dev/console", O_NOCTTY); diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h index e4111b21e95ea11dbac71c04a36a48103b530a6c..47c850ad45a2f08cb51877be5478dae330dd7df0 100644 --- a/src/xpdev/genwrap.h +++ b/src/xpdev/genwrap.h @@ -106,6 +106,8 @@ extern "C" { #define PLATFORM_DESC "Solaris" #elif defined(__sun__) #define PLATFORM_DESC "SunOS" +#elif defined(__gnu__) + #define PLATFORM_DESC "GNU/Hurd" #elif defined(__unix__) #define PLATFORM_DESC "Unix" #else diff --git a/src/xpdev/sem.c b/src/xpdev/sem.c new file mode 100644 index 0000000000000000000000000000000000000000..825653e603a34807149e4041aa681c7a42fa5130 --- /dev/null +++ b/src/xpdev/sem.c @@ -0,0 +1,45 @@ +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include "genwrap.h" +#include "sem.h" + +int sem_init(sem_t *sem, int pshared, unsigned int value) { + sem=malloc(sizeof(sem_t)); + if(sem==NULL) { + errno=ENOSPC; + return(-1); + } + if(pipe((int *)sem)) { + errno=EPERM; + return(-1); + } + return(0); +} + +int sem_destroy(sem_t *sem) { + close(sem->read); + close(sem->write); + sem=NULL; + return(0); +} + +int sem_post(sem_t *sem) { + if(sem==NULL) { + errno=EINVAL; + return(-1); + } + write(sem->write,"-",1)==1; + return(0); +} + +int sem_wait(sem_t *sem) { + char buf; + if(sem==NULL) { + errno=EINVAL; + return(-1); + } + while(read(sem->read,&buf,1)<1) + SLEEP(1); + return(0); +} diff --git a/src/xpdev/sem.h b/src/xpdev/sem.h new file mode 100644 index 0000000000000000000000000000000000000000..9dbdd9eb902814f2d0d85945382b65f043e331a0 --- /dev/null +++ b/src/xpdev/sem.h @@ -0,0 +1,10 @@ +typedef struct { + int read; + int write; +} sem_t; + +int sem_init(sem_t *sem, int pshared, unsigned int value); +int sem_destroy(sem_t *sem); +int sem_post(sem_t *sem); +int sem_wait(sem_t *sem); + diff --git a/src/xpdev/threadwrap.h b/src/xpdev/threadwrap.h index accb941133ebffc187966ebeef838a50a4280801..a72f5b0cbc65b6eb0347fa27e7e4bb12cfb483f1 100644 --- a/src/xpdev/threadwrap.h +++ b/src/xpdev/threadwrap.h @@ -48,7 +48,11 @@ extern "C" { #if defined(__unix__) #include <pthread.h> /* POSIX threads and mutexes */ +#if defined(_NEED_SEM) + #include "sem.h" +#else #include <semaphore.h> /* POSIX semaphores */ +#endif ulong _beginthread(void( *start_address )( void * ) ,unsigned stack_size, void *arglist);