Skip to content

Commit

Permalink
Use os2compat_ prefix for types and function needing additional headers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
komh committed Oct 11, 2021
1 parent 1471efe commit f65e380
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 103 deletions.
14 changes: 7 additions & 7 deletions io/scandir.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* scandir() and alphasort() implementation for OS/2 kLIBC
*
* Copyright (C) 2016 KO Myung-Hun <[email protected]>
* Copyright (C) 2016-2021 KO Myung-Hun <[email protected]>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions io/scandir.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* scandir() and alphasort() implementation for OS/2 kLIBC
*
* Copyright (C) 2016 KO Myung-Hun <[email protected]>
* Copyright (C) 2016-2021 KO Myung-Hun <[email protected]>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
Expand All @@ -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
}
Expand Down
24 changes: 13 additions & 11 deletions memory/mmap.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* mmap() simple implementation for OS/2 kLIBC
*
* Copyright (C) 2014 KO Myung-Hun <[email protected]>
* Copyright (C) 2014-2021 KO Myung-Hun <[email protected]>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 )
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
52 changes: 43 additions & 9 deletions memory/mmap.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* mmap() simple implementation for OS/2 kLIBC
*
* Copyright (C) 2014 KO Myung-Hun <[email protected]>
* Copyright (C) 2014-2021 KO Myung-Hun <[email protected]>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
Expand All @@ -13,53 +13,87 @@
#ifndef OS2COMPAT_MMAP_H
#define OS2COMPAT_MMAP_H

#include <sys/mman.h>
#include <sys/types.h>

/*
* 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
}
Expand Down
30 changes: 16 additions & 14 deletions network/getaddrinfo.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* getaddrinfo() implementation for OS/2 kLIBC
*
* Copyright (C) 2014 KO Myung-Hun <[email protected]>
* Copyright (C) 2014-2021 KO Myung-Hun <[email protected]>
*
* This file was modifed from src/os2/getaddrinfo.c of VLC.
*
Expand Down Expand Up @@ -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;

Expand All @@ -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))
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit f65e380

Please sign in to comment.