]>
jfr.im git - solanum.git/blob - librb/src/unix.c
2 * ircd-ratbox: A slightly useful ircd.
3 * unix.c: various unix type functions
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 2005 ircd-ratbox development team
7 * Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24 * $Id: unix.c 26180 2008-11-11 00:00:12Z androsyn $
26 #include <libratbox_config.h>
27 #include <ratbox_lib.h>
35 #if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN)
39 #include <crt_externs.h>
43 extern char **environ
;
46 rb_spawn_process(const char *path
, const char **argv
)
49 const void *arghack
= argv
;
52 posix_spawnattr_t spattr
;
53 posix_spawnattr_init(&spattr
);
54 #ifdef POSIX_SPAWN_USEVFORK
55 posix_spawnattr_setflags(&spattr
, POSIX_SPAWN_USEVFORK
);
58 myenviron
= *_NSGetEnviron(); /* apple needs to go fuck themselves for this */
62 error
= posix_spawn(&pid
, path
, NULL
, &spattr
, arghack
, myenviron
);
63 posix_spawnattr_destroy(&spattr
);
73 rb_spawn_process(const char *path
, const char **argv
)
78 execv(path
, (const void *)argv
); /* make gcc shut up */
79 _exit(1); /* if we're still here, we're screwed */
85 #ifndef HAVE_GETTIMEOFDAY
87 rb_gettimeofday(struct timeval
*tv
, void *tz
)
95 if(time(&tv
->tv_sec
) == -1)
101 rb_gettimeofday(struct timeval
*tv
, void *tz
)
103 return (gettimeofday(tv
, tz
));
108 rb_sleep(unsigned int seconds
, unsigned int useconds
)
110 #ifdef HAVE_NANOSLEEP
112 tv
.tv_nsec
= (useconds
* 1000);
114 nanosleep(&tv
, NULL
);
118 tv
.tv_usec
= useconds
;
119 select(0, NULL
, NULL
, NULL
, &tv
);
123 /* this is to keep some linkers from bitching about exporting a non-existant symbol..bleh */
125 rb_strerror(int error
)
127 return strerror(error
);
131 rb_kill(pid_t pid
, int sig
)
133 return kill(pid
, sig
);
137 rb_setenv(const char *name
, const char *value
, int overwrite
)
139 return setenv(name
, value
, overwrite
);
143 rb_waitpid(pid_t pid
, int *status
, int options
)
145 return waitpid(pid
, status
, options
);