X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/b57f37fb6a4d30ac9aaba3bbca06f5a3307c804a..6f187f63b510ade944b8b3704727eeff3f0d31ca:/libratbox/src/unix.c diff --git a/libratbox/src/unix.c b/libratbox/src/unix.c index a7b2efd..397045e 100644 --- a/libratbox/src/unix.c +++ b/libratbox/src/unix.c @@ -21,28 +21,49 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA * - * $Id: unix.c 25038 2008-01-23 16:03:08Z androsyn $ */ #include #include -#ifndef WINDOWS + +#ifndef _WIN32 + +#include + + #if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN) #include + +#ifdef __APPLE__ +#include +#endif + +#ifndef __APPLE__ extern char **environ; +#endif pid_t rb_spawn_process(const char *path, const char **argv) { pid_t pid; const void *arghack = argv; + char **myenviron; + int error; posix_spawnattr_t spattr; posix_spawnattr_init(&spattr); #ifdef POSIX_SPAWN_USEVFORK posix_spawnattr_setflags(&spattr, POSIX_SPAWN_USEVFORK); #endif - if(posix_spawn(&pid, path, NULL, &spattr, arghack, environ)) +#ifdef __APPLE__ + myenviron = *_NSGetEnviron(); /* apple needs to go fuck themselves for this */ +#else + myenviron = environ; +#endif + error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron); + posix_spawnattr_destroy(&spattr); + if (error != 0) { - return -1; + errno = error; + pid = -1; } return pid; } @@ -53,10 +74,10 @@ rb_spawn_process(const char *path, const char **argv) pid_t pid; if(!(pid = vfork())) { - execv(path, (const void *)argv); /* make gcc shut up */ - _exit(1); /* if we're still here, we're screwed */ + execv(path, (const void *)argv); /* make gcc shut up */ + _exit(1); /* if we're still here, we're screwed */ } - return(pid); + return (pid); } #endif @@ -78,7 +99,7 @@ rb_gettimeofday(struct timeval *tv, void *tz) int rb_gettimeofday(struct timeval *tv, void *tz) { - return(gettimeofday(tv, tz)); + return (gettimeofday(tv, tz)); } #endif @@ -90,13 +111,44 @@ rb_sleep(unsigned int seconds, unsigned int useconds) tv.tv_nsec = (useconds * 1000); tv.tv_sec = seconds; nanosleep(&tv, NULL); -#else +#else struct timeval tv; tv.tv_sec = seconds; tv.tv_usec = useconds; select(0, NULL, NULL, NULL, &tv); #endif } -#endif /* !WINDOWS */ + +/* this is to keep some linkers from bitching about exporting a non-existant symbol..bleh */ +char * +rb_strerror(int error) +{ + return strerror(error); +} + +int +rb_kill(pid_t pid, int sig) +{ + return kill(pid, sig); +} + +int +rb_setenv(const char *name, const char *value, int overwrite) +{ + return setenv(name, value, overwrite); +} + +pid_t +rb_waitpid(pid_t pid, int *status, int options) +{ + return waitpid(pid, status, options); +} + +pid_t +rb_getpid(void) +{ + return getpid(); +} +#endif /* !WIN32 */