From f65e3805a741b0362f086c0a7343a0c22523a087 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Mon, 11 Oct 2021 17:44:26 +0900 Subject: [PATCH] Use os2compat_ prefix for types and function needing additional headers This avoid multiple symbols detected at link time when using other libs having the same symbols. modified: io/scandir.c modified: io/scandir.h modified: memory/mmap.c modified: memory/mmap.h modified: network/getaddrinfo.c modified: network/getaddrinfo.h modified: network/if_nameindex.c modified: network/if_nameindex.h modified: network/poll.c modified: network/poll.h modified: network/shutdown.h modified: testcase/Makefile modified: thread/semaphore.c modified: thread/semaphore.h --- io/scandir.c | 14 ++++++------ io/scandir.h | 17 ++++++++------ memory/mmap.c | 24 ++++++++++--------- memory/mmap.h | 52 ++++++++++++++++++++++++++++++++++-------- network/getaddrinfo.c | 30 ++++++++++++------------ network/getaddrinfo.h | 37 +++++++++++++++++++++--------- network/if_nameindex.c | 26 ++++++++++----------- network/if_nameindex.h | 19 ++++++++++----- network/poll.c | 4 ++-- network/poll.h | 10 +++++--- network/shutdown.h | 4 +++- testcase/Makefile | 8 +++---- thread/semaphore.c | 16 ++++++------- thread/semaphore.h | 23 +++++++++++++------ 14 files changed, 181 insertions(+), 103 deletions(-) diff --git a/io/scandir.c b/io/scandir.c index ab32d5c..2ddcfee 100644 --- a/io/scandir.c +++ b/io/scandir.c @@ -1,7 +1,7 @@ /* * scandir() and alphasort() implementation for OS/2 kLIBC * - * Copyright (C) 2016 KO Myung-Hun + * Copyright (C) 2016-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -23,10 +23,10 @@ * * @remark OS/2 kLIBC declares scandir() differently from POSIX */ -int scandir( const char *dir, struct dirent ***namelist, - int ( *sel )(/* const */ struct dirent * ), - int ( *compare )( const /* struct dirent ** */ void *, - const /* struct dirent ** */ void *)) +int os2compat_scandir( const char *dir, struct dirent ***namelist, + int ( *sel )(/* const */ struct dirent * ), + int ( *compare )( const /* struct dirent ** */ void *, + const /* struct dirent ** */ void *)) { DIR *dp; struct dirent **list = NULL; @@ -133,8 +133,8 @@ int scandir( const char *dir, struct dirent ***namelist, * @remark OS/2 kLIBC requires parameters of compare function differently * from POSIX */ -int alphasort( const /* struct dirent **d1 */ void *p1, - const /* struct dirent **d2 */ void *p2 ) +int os2compat_alphasort( const /* struct dirent **d1 */ void *p1, + const /* struct dirent **d2 */ void *p2 ) { struct dirent **d1 = ( struct dirent ** )p1; struct dirent **d2 = ( struct dirent ** )p2; diff --git a/io/scandir.h b/io/scandir.h index e34a446..a1bff17 100644 --- a/io/scandir.h +++ b/io/scandir.h @@ -1,7 +1,7 @@ /* * scandir() and alphasort() implementation for OS/2 kLIBC * - * Copyright (C) 2016 KO Myung-Hun + * Copyright (C) 2016-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -19,13 +19,16 @@ extern "C" { #endif -int scandir( const char *dir, struct dirent ***namelist, - int ( *sel )(/* const */ struct dirent * ), - int ( *compare )( const /* struct dirent ** */ void *, - const /* struct dirent ** */ void *)); +int os2compat_scandir( const char *dir, struct dirent ***namelist, + int ( *sel )(/* const */ struct dirent * ), + int ( *compare )( const /* struct dirent ** */ void *, + const /* struct dirent ** */ void *)); -int alphasort( const /* struct dirent **d1 */ void *p1, - const /* struct dirent **d2 */ void *p2); +int os2compat_alphasort( const /* struct dirent **d1 */ void *p1, + const /* struct dirent **d2 */ void *p2); + +#define scandir os2compat_scandir +#define alphasort os2compat_alphasort #ifdef __cplusplus } diff --git a/memory/mmap.c b/memory/mmap.c index ac464dd..143ae19 100644 --- a/memory/mmap.c +++ b/memory/mmap.c @@ -1,7 +1,7 @@ /* * mmap() simple implementation for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -723,7 +723,8 @@ static int mmapGetSharedNameFromFd( int fd, char *name, size_t size ) * length read may be different. * @todo demand paging. */ -void *mmap( void *addr, size_t len, int prot, int flags, int fildes, off_t off ) +void *os2compat_mmap( void *addr, size_t len, int prot, int flags, int fildes, + off_t off ) { os2_mmap *new_mmap; int pagesize; @@ -929,17 +930,17 @@ void *mmap( void *addr, size_t len, int prot, int flags, int fildes, off_t off ) if( readFromFile( fildes, read_off, read_buf, read_len ) == -1 ) { saved_errno = errno; - munmap( ret, len ); + os2compat_munmap( ret, len ); errno = saved_errno; return MAP_FAILED; } } - if( mprotect( ret, len, prot )) + if( os2compat_mprotect( ret, len, prot )) { saved_errno = errno; - munmap( ret, len ); + os2compat_munmap( ret, len ); errno = saved_errno; return MAP_FAILED; @@ -952,7 +953,7 @@ void *mmap( void *addr, size_t len, int prot, int flags, int fildes, off_t off ) * Unmap mapped memory by mmap(). * @remark Partial unmapping is not supported. */ -int munmap( void *addr, size_t len ) +int os2compat_munmap( void *addr, size_t len ) { os2_mmap *mm; @@ -969,7 +970,7 @@ int munmap( void *addr, size_t len ) { if(( mm->flags & ( MAP_ANON | MAP_SHARED )) == MAP_SHARED && ( mm->prot & PROT_WRITE ) - && msync( mm->addr, mm->len, MS_SYNC ) == -1 ) + && os2compat_msync( mm->addr, mm->len, MS_SYNC ) == -1 ) return -1; if( mm->flags & MAP_SHARED ) @@ -990,7 +991,7 @@ int munmap( void *addr, size_t len ) * Set memory protection flags. * @bug Set READ flag if PROT_NONE. OS/2 has no equivalent attributes to it. */ -int mprotect( void *addr, size_t len, int prot ) +int os2compat_mprotect( void *addr, size_t len, int prot ) { os2_mmap *mm; @@ -1018,15 +1019,16 @@ int mprotect( void *addr, size_t len, int prot ) * Anonymous mmap(). * @see mmap(). */ -void *mmap_anon( void *addr, size_t len, int prot, int flags, off_t off ) +void *os2compat_mmap_anon( void *addr, size_t len, int prot, int flags, + off_t off ) { - return mmap( addr, len, prot, flags | MAP_ANON, -1, off ); + return os2compat_mmap( addr, len, prot, flags | MAP_ANON, -1, off ); } /** * Synchronize memory with a file */ -int msync( void *addr, size_t len, int flags ) +int os2compat_msync( void *addr, size_t len, int flags ) { os2_mmap *mm; diff --git a/memory/mmap.h b/memory/mmap.h index c0234ae..e5ee2fa 100644 --- a/memory/mmap.h +++ b/memory/mmap.h @@ -1,7 +1,7 @@ /* * mmap() simple implementation for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -13,53 +13,87 @@ #ifndef OS2COMPAT_MMAP_H #define OS2COMPAT_MMAP_H +#include #include /* * Protections are chosen from these bits, or-ed together */ +#ifndef PROT_NONE #define PROT_NONE 0x00 /* no permissions */ +#endif +#ifndef PROT_READ #define PROT_READ 0x01 /* pages can be read */ +#endif +#ifndef PROT_WRITE #define PROT_WRITE 0x02 /* pages can be written */ +#endif +#ifndef PROT_EXEC #define PROT_EXEC 0x04 /* pages can be executed */ +#endif /* * Flags contain sharing type and options. * Sharing types; choose one. */ +#ifndef MAP_SHARED #define MAP_SHARED 0x0001 /* share changes */ +#endif +#ifndef MAP_PRIVATE #define MAP_PRIVATE 0x0002 /* changes are private */ +#endif +#ifndef MAP_FIXED #define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ +#endif /* * Mapping type */ +#ifndef MAP_FILE #define MAP_FILE 0x0000 /* map from file (default) */ +#endif +#ifndef MAP_ANON #define MAP_ANON 0x1000 /* allocated from memory, swap space */ +#endif +#ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON +#endif /* Return value of `mmap' in case of an error. */ +#ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) +#endif /* * Synchronization flags */ +#ifndef MS_SYNC #define MS_SYNC 0x0000 /* Perform synchronous writes */ +#endif +#ifndef MS_ASYNC #define MS_ASYNC 0x0001 /* Perform asynchronous writes */ +#endif +#ifndef MS_INVALIDATE #define MS_INVALIDATE 0x0002 /* Invalidate cached data */ +#endif #ifdef __cplusplus extern "C" { #endif -#ifndef _MMAP_DECLARED -#define _MMAP_DECLARED -void *mmap( void *addr, size_t len, int prot, int flags, int fildes, off_t off ); -#endif -int munmap( void *addr, size_t len ); -int mprotect( void *addr, size_t len, int prot ); -void *mmap_anon( void *addr, size_t len, int prot, int flags, off_t off ); -int msync( void *addr, size_t len, int flags ); +void *os2compat_mmap( void *addr, size_t len, int prot, int flags, int fildes, + off_t off ); +int os2compat_munmap( void *addr, size_t len ); +int os2compat_mprotect( void *addr, size_t len, int prot ); +void *os2compat_mmap_anon( void *addr, size_t len, int prot, int flags, + off_t off ); +int os2compat_msync( void *addr, size_t len, int flags ); + +#define mmap os2compat_mmap +#define munmap os2compat_munmap +#define mprotect os2compat_mprotect +#define mmap_anon os2compat_mmap_anon +#define msync os2compat_msync #ifdef __cplusplus } diff --git a/network/getaddrinfo.c b/network/getaddrinfo.c index 917674f..bac2f7b 100644 --- a/network/getaddrinfo.c +++ b/network/getaddrinfo.c @@ -1,7 +1,7 @@ /* * getaddrinfo() implementation for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This file was modifed from src/os2/getaddrinfo.c of VLC. * @@ -75,7 +75,7 @@ static const char gai_unknownerr[] = "Unrecognized error number"; /**************************************************************************** * Converts an EAI_* error code into human readable english text. ****************************************************************************/ -const char *gai_strerror (int errnum) +const char *os2compat_gai_strerror (int errnum) { unsigned i; @@ -98,8 +98,9 @@ const char *gai_strerror (int errnum) * function. */ int -getnameinfo (const struct sockaddr *sa, socklen_t salen, - char *host, int hostlen, char *serv, int servlen, int flags) +os2compat_getnameinfo (const struct sockaddr *sa, socklen_t salen, + char *host, int hostlen, + char *serv, int servlen, int flags) { if (((size_t)salen < sizeof (struct sockaddr_in)) || (sa->sa_family != AF_INET)) @@ -171,11 +172,11 @@ gai_error_from_herrno (void) /* * This functions must be used to free the memory allocated by getaddrinfo(). */ -void freeaddrinfo (struct addrinfo *res) +void os2compat_freeaddrinfo (struct os2compat_addrinfo *res) { while (res != NULL) { - struct addrinfo *next = res->ai_next; + struct os2compat_addrinfo *next = res->ai_next; free (res->ai_canonname); free (res->ai_addr); @@ -187,14 +188,14 @@ void freeaddrinfo (struct addrinfo *res) /* * Internal function that builds an addrinfo struct. */ -static struct addrinfo * +static struct os2compat_addrinfo * makeaddrinfo (int af, int type, int proto, const struct sockaddr *addr, size_t addrlen, const char *canonname) { - struct addrinfo *res; + struct os2compat_addrinfo *res; - res = (struct addrinfo *)malloc (sizeof (struct addrinfo)); + res = malloc (sizeof (*res)); if (res != NULL) { res->ai_flags = 0; @@ -221,11 +222,11 @@ makeaddrinfo (int af, int type, int proto, } } /* failsafe */ - freeaddrinfo (res); + os2compat_freeaddrinfo (res); return NULL; } -static struct addrinfo * +static struct os2compat_addrinfo * makeipv4info (int type, int proto, u_long ip, u_short port, const char *name) { struct sockaddr_in addr; @@ -252,10 +253,11 @@ makeipv4info (int type, int proto, u_long ip, u_short port, const char *name) * Only UDP and TCP over IPv4 are supported here. */ int -getaddrinfo (const char *node, const char *service, - const struct addrinfo *hints, struct addrinfo **res) +os2compat_getaddrinfo (const char *node, const char *service, + const struct os2compat_addrinfo *hints, + struct os2compat_addrinfo **res) { - struct addrinfo *info; + struct os2compat_addrinfo *info; u_long ip; u_short port; int protocol = 0, flags = 0; diff --git a/network/getaddrinfo.h b/network/getaddrinfo.h index ba54031..c5de3a6 100644 --- a/network/getaddrinfo.h +++ b/network/getaddrinfo.h @@ -1,7 +1,7 @@ /* * getaddrinfo() implementation for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -10,10 +10,18 @@ * http://www.wtfpl.net/ for more details. */ +/* + * Dependencies: network/socklen_t.h + */ + #ifndef OS2COMPAT_GETADDRINFO_H #define OS2COMPAT_GETADDRINFO_H #include +#include +#include + +#include "network/socklen_t.h" #ifdef __cplusplus extern "C" { @@ -83,9 +91,7 @@ extern "C" { #define AI_NUMERICHOST 4 #endif -typedef int socklen_t; - -struct addrinfo +struct os2compat_addrinfo { int ai_flags; int ai_family; @@ -94,15 +100,24 @@ struct addrinfo size_t ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; - struct addrinfo *ai_next; + struct os2compat_addrinfo *ai_next; }; -const char *gai_strerror (int errnum); -int getaddrinfo (const char *node, const char *service, - const struct addrinfo *hints, struct addrinfo **res); -void freeaddrinfo (struct addrinfo *res); -int getnameinfo (const struct sockaddr *sa, socklen_t salen, char *host, - int hostlen, char *serv, int servlen, int flags); +const char *os2compat_gai_strerror( int errnum ); +int os2compat_getaddrinfo( const char *node, const char *service, + const struct os2compat_addrinfo *hints, + struct os2compat_addrinfo **res ); +void os2compat_freeaddrinfo( struct os2compat_addrinfo *res ); +int os2compat_getnameinfo( const struct sockaddr *sa, socklen_t salen, + char *host, int hostlen, + char *serv, int servlen, int flags ); + +#define addrinfo os2compat_addrinfo + +#define gai_strerror os2compat_gai_strerror +#define getaddrinfo os2compat_getaddrinfo +#define freeaddrinfo os2compat_freeaddrinfo +#define getnameinfo os2compat_getnameinfo #ifdef __cplusplus } diff --git a/network/if_nameindex.c b/network/if_nameindex.c index 08c5acb..8b112e7 100644 --- a/network/if_nameindex.c +++ b/network/if_nameindex.c @@ -1,7 +1,7 @@ /* * if_nameindex() family implementaiton for OS/2 kLIBC * - * Copyright (C) 2016 KO Myung-Hun + * Copyright (C) 2016-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -22,12 +22,12 @@ #include /* struct ifconf, struct ifreq */ #include /* struct sockaddr_dl */ -struct if_nameindex *if_nameindex( void ) +struct os2compat_if_nameindex *os2compat_if_nameindex( void ) { int s; struct ifconf ifconf; struct ifreq iflist[ IFMIB_ENTRIES /* MAX 42 */]; - struct if_nameindex *nis = NULL; + struct os2compat_if_nameindex *nis = NULL; int ifcount; int entries = 0; int i; @@ -62,7 +62,7 @@ struct if_nameindex *if_nameindex( void ) nis[ entries ].if_name = strdup( iflist[ i ].ifr_name ); if( nis[ entries ].if_name == NULL ) { - if_freenameindex( nis ); + os2compat_if_freenameindex( nis ); nis = NULL; @@ -87,7 +87,7 @@ struct if_nameindex *if_nameindex( void ) return nis; } -void if_freenameindex( struct if_nameindex *ptr ) +void os2compat_if_freenameindex( struct os2compat_if_nameindex *ptr ) { int i; @@ -100,12 +100,12 @@ void if_freenameindex( struct if_nameindex *ptr ) free( ptr ); } -char *if_indextoname( unsigned ifindex, char *ifname ) +char *os2compat_if_indextoname( unsigned ifindex, char *ifname ) { - struct if_nameindex *nis; + struct os2compat_if_nameindex *nis; int i; - nis = if_nameindex(); + nis = os2compat_if_nameindex(); if( nis == NULL ) return NULL; @@ -121,7 +121,7 @@ char *if_indextoname( unsigned ifindex, char *ifname ) i = nis[ i ].if_index; - if_freenameindex( nis ); + os2compat_if_freenameindex( nis ); if( i == 0 ) return NULL; @@ -129,12 +129,12 @@ char *if_indextoname( unsigned ifindex, char *ifname ) return ifname; } -unsigned if_nametoindex( const char *ifname ) +unsigned os2compat_if_nametoindex( const char *ifname ) { - struct if_nameindex *nis; + struct os2compat_if_nameindex *nis; int i; - nis = if_nameindex(); + nis = os2compat_if_nameindex(); if( nis == NULL ) return 0; @@ -146,7 +146,7 @@ unsigned if_nametoindex( const char *ifname ) i = nis[ i ].if_index; - if_freenameindex( nis ); + os2compat_if_freenameindex( nis ); return i; } diff --git a/network/if_nameindex.h b/network/if_nameindex.h index 5f0c671..de8c5a3 100644 --- a/network/if_nameindex.h +++ b/network/if_nameindex.h @@ -1,7 +1,7 @@ /* * if_nameindex() family implementation for OS/2 kLIBC * - * Copyright (C) 2016 KO Myung-Hun + * Copyright (C) 2016-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -13,21 +13,28 @@ #ifndef OS2COMPAT_IF_NAMEINDEX_H #define OS2COMPAT_IF_NAMEINDEX_H +#include + #ifdef __cplusplus extern "C" { #endif -struct if_nameindex +struct os2compat_if_nameindex { /* Note: if_index may be different from ifmib.iftable.iftIndex */ unsigned int if_index; char *if_name; }; -struct if_nameindex *if_nameindex( void ); -void if_freenameindex( struct if_nameindex *ptr ); -char *if_indextoname( unsigned ifindex, char *ifname ); -unsigned if_nametoindex( const char *ifname ); +struct os2compat_if_nameindex *os2compat_if_nameindex( void ); +void os2compat_if_freenameindex( struct os2compat_if_nameindex *ptr ); +char *os2compat_if_indextoname( unsigned ifindex, char *ifname ); +unsigned os2compat_if_nametoindex( const char *ifname ); + +#define if_nameindex os2compat_if_nameindex +#define if_freenameindex os2compat_if_freenameindex +#define if_indextoname os2compat_if_indextoname +#define if_nametoindex os2compat_if_nametoindex #ifdef __cplusplus } diff --git a/network/poll.c b/network/poll.c index 05c73fb..96db80f 100644 --- a/network/poll.c +++ b/network/poll.c @@ -1,7 +1,7 @@ /* * poll() implementation for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This file was excerpted and modifed from src/os2/thread.c of VLC. * @@ -32,7 +32,7 @@ #include "poll.h" -int poll( struct pollfd *fds, unsigned nfds, int timeout ) +int os2compat_poll( struct os2compat_pollfd *fds, unsigned nfds, int timeout ) { fd_set rdset, wrset, exset; diff --git a/network/poll.h b/network/poll.h index dfbc4a0..c55c34c 100644 --- a/network/poll.h +++ b/network/poll.h @@ -1,7 +1,7 @@ /* * poll() implementation for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -36,14 +36,18 @@ extern "C" { #define POLLNVAL 0x0020 #endif -struct pollfd +struct os2compat_pollfd { int fd; unsigned events; unsigned revents; }; -int poll( struct pollfd *fds, unsigned nfds, int timeout ); +int os2compat_poll( struct os2compat_pollfd *fds, unsigned nfds, int timeout ); + +#define pollfd os2compat_pollfd + +#define poll os2compat_poll #ifdef __cplusplus } diff --git a/network/shutdown.h b/network/shutdown.h index 3d4afa1..b8968b4 100644 --- a/network/shutdown.h +++ b/network/shutdown.h @@ -1,7 +1,7 @@ /* * Define macros for shutdown() for OS/2 kLIBC * - * Copyright (C) 2014 KO Myung-Hun + * Copyright (C) 2014-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -13,6 +13,8 @@ #ifndef OS2COMPAT_SHUTDOWN_H #define OS2COMPAT_SHUTDOWN_H +#include + #ifndef SHUT_RD #define SHUT_RD 0 #endif diff --git a/testcase/Makefile b/testcase/Makefile index 0883e84..220fb65 100644 --- a/testcase/Makefile +++ b/testcase/Makefile @@ -1,6 +1,6 @@ # # Configuration parts of GNU Make/GCC build system. -# Copyright (C) 2014 by KO Myung-Hun +# Copyright (C) 2014-2021 by KO Myung-Hun # # This file is part of GNU Make/GCC build system. # @@ -17,10 +17,10 @@ SUBDIRS := # specify gcc compiler flags for all the programs -CFLAGS := -Wall -DOS2EMX_PLAIN_CHAR -funsigned-char +CFLAGS := -Wall -DOS2EMX_PLAIN_CHAR -funsigned-char -I.. # specify g++ compiler flags for all the programs -CXXFLAGS := -Wall -DOS2EMX_PLAIN_CHAR -funsigned-char +CXXFLAGS := -Wall -DOS2EMX_PLAIN_CHAR -funsigned-char -I.. # specify linker flags such as -L option for all the programs LDFLAGS := @@ -147,7 +147,7 @@ _response-1_SRCS := _response-1.c ../process/_response.c getrusage-1_SRCS := getrusage-1.c ../process/getrusage.c getrusage-1_CFLAGS := -I../process -select-1_SRCS := select-1.c ../network/select.c ../io/pipe.c +select-1_SRCS := select-1.c ../network/select.c ../io/pipe.c ../io/fcntl.c select-1_CFLAGS := -I../network # 1. specify a list of libraries without an extension with diff --git a/thread/semaphore.c b/thread/semaphore.c index c65ace0..9c6d50f 100644 --- a/thread/semaphore.c +++ b/thread/semaphore.c @@ -1,7 +1,7 @@ /* * POSIX semaphore implementation for OS/2 kLIBC * - * Copyright (C) 2016 KO Myung-Hun + * Copyright (C) 2016-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -86,7 +86,7 @@ static int rc2errno( ULONG rc ) * * @todo Support @a pshared */ -int sem_init( sem_t *sem, int pshared, unsigned int value ) +int os2compat_sem_init( os2compat_sem_t *sem, int pshared, unsigned int value ) { if( value > SEM_VALUE_MAX ) { @@ -101,7 +101,7 @@ int sem_init( sem_t *sem, int pshared, unsigned int value ) { errno = ENOSPC; - sem_destroy( sem ); + os2compat_sem_destroy( sem ); return -1; } @@ -114,7 +114,7 @@ int sem_init( sem_t *sem, int pshared, unsigned int value ) /** * sem_destroy() */ -int sem_destroy( sem_t *sem ) +int os2compat_sem_destroy( os2compat_sem_t *sem ) { ULONG rc; @@ -132,7 +132,7 @@ int sem_destroy( sem_t *sem ) /** * sem_post() */ -int sem_post( sem_t *sem ) +int os2compat_sem_post( os2compat_sem_t *sem ) { ULONG rc = 0; @@ -150,7 +150,7 @@ int sem_post( sem_t *sem ) EPILOGUE; } -static int sem_wait_common( sem_t *sem, ULONG ulTimeout ) +static int sem_wait_common( os2compat_sem_t *sem, ULONG ulTimeout ) { ULONG rc; @@ -181,7 +181,7 @@ static int sem_wait_common( sem_t *sem, ULONG ulTimeout ) /** * sem_wait() */ -int sem_wait( sem_t *sem ) +int os2compat_sem_wait( os2compat_sem_t *sem ) { return sem_wait_common( sem, SEM_INDEFINITE_WAIT ); } @@ -189,7 +189,7 @@ int sem_wait( sem_t *sem ) /** * sem_trywait() */ -int sem_trywait( sem_t *sem ) +int os2compat_sem_trywait( os2compat_sem_t *sem ) { return sem_wait_common( sem, SEM_IMMEDIATE_RETURN ); } diff --git a/thread/semaphore.h b/thread/semaphore.h index 88599e8..0f9dbf0 100644 --- a/thread/semaphore.h +++ b/thread/semaphore.h @@ -1,7 +1,7 @@ /* * POSIX semaphore implementation for OS/2 kLIBC * - * Copyright (C) 2016 KO Myung-Hun + * Copyright (C) 2016-2021 KO Myung-Hun * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -27,13 +27,22 @@ typedef struct { unsigned long/*HMTX*/ hmtxWait; /**< mutex for waiting */ unsigned long/*HMTX*/ hmtxCount; /**< mutex for counting */ int count; /**< count of semaphore */ -} sem_t; +} os2compat_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 ); -int sem_trywait( sem_t *sem ); +int os2compat_sem_init( os2compat_sem_t *sem, int pshared, + unsigned int value ); +int os2compat_sem_destroy( os2compat_sem_t *sem ); +int os2compat_sem_post( os2compat_sem_t *sem ); +int os2compat_sem_wait( os2compat_sem_t *sem ); +int os2compat_sem_trywait( os2compat_sem_t *sem ); + +#define sem_t os2compat_sem_t + +#define sem_init os2compat_sem_init +#define sem_destroy os2compat_sem_destroy +#define sem_post os2compat_sem_post +#define sem_wait os2compat_sem_wait +#define sem_trywait os2compat_sem_trywait #ifdef __cplusplus }