Skip to content

Commit

Permalink
Check for available getpid() instead of using system defines (radareo…
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored Feb 8, 2021
1 parent 732b162 commit a8885da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 13 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ if get_option('local') and get_option('default_library') == 'shared'
rpath_exe = '$ORIGIN/../' + get_option('libdir')
endif

userconf = configuration_data()
userconf.set10('HAVE_GETPID', cc.has_function('getpid', prefix: '#include <unistd.h>'))
userconf.set10('HAVE__GETPID', cc.has_function('_getpid', prefix: '#include <process.h>'))
sdb_userconf_h = configure_file(
input : 'src/sdb_userconf.h.in',
output : 'sdb_userconf.h',
configuration : userconf,
install_dir : join_paths(sdb_incdir, 'sdb'),
)

# Create sdb_version.h
conf_data = configuration_data()
conf_data.set_quoted('SDB_VERSION', sdb_version, description : 'From config.mk')
versionconf = configuration_data()
versionconf.set_quoted('SDB_VERSION', sdb_version, description : 'From config.mk')
sdb_version_h = configure_file(
output : 'sdb_version.h',
configuration : conf_data,
configuration : versionconf,
install_dir : join_paths(sdb_incdir, 'sdb'),
)

Expand Down
8 changes: 6 additions & 2 deletions src/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <fcntl.h>
#include "sdb.h"
#include "sdb_userconf.h"

SDB_API const char *sdb_lock_file(const char *f) {
static char buf[128];
Expand All @@ -20,11 +21,14 @@ SDB_API const char *sdb_lock_file(const char *f) {
return buf;
}

#if __SDB_WINDOWS__ && !__CYGWIN__
#if HAVE_GETPID
#include <unistd.h>
#define os_getpid() getpid()
#elif HAVE__GETPID
#include <process.h>
#define os_getpid() _getpid()
#else
#define os_getpid() getpid()
#error No supported getpid() found
#endif

SDB_API bool sdb_lock(const char *s) {
Expand Down
7 changes: 7 additions & 0 deletions src/sdb_userconf.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef SDB_USERCONF_H
#define SDB_USERCONF_H

#define HAVE_GETPID @HAVE_GETPID@
#define HAVE__GETPID @HAVE__GETPID@

#endif

0 comments on commit a8885da

Please sign in to comment.