Proper check and dropin replacement for usleep().
[oweals/tinc.git] / lib / dropin.c
index 23d2b136f304f798ffe9536da0fdee66d23afaaa..1bad05cd43e6fee4c88937f0a69577741819aca6 100644 (file)
@@ -1,7 +1,7 @@
 /*
     dropin.c -- a set of drop-in replacements for libc functions
     Copyright (C) 2000-2005 Ivo Timmermans,
-                  2000-2006 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2009 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    $Id$
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #include "system.h"
@@ -38,8 +36,7 @@
   Unless the argument noclose is non-zero, daemon() will redirect
   standard input, standard output and standard error to /dev/null.
 */
-int daemon(int nochdir, int noclose)
-{
+int daemon(int nochdir, int noclose) {
 #ifdef HAVE_FORK
        pid_t pid;
        int fd;
@@ -97,8 +94,7 @@ int daemon(int nochdir, int noclose)
   current directory name.  If the environment variable PWD is set, and
   its value is correct, then that value will be returned.
 */
-char *get_current_dir_name(void)
-{
+char *get_current_dir_name(void) {
        size_t size;
        char *buf;
        char *r;
@@ -135,7 +131,6 @@ int asprintf(char **buf, const char *fmt, ...) {
 }
 
 int vasprintf(char **buf, const char *fmt, va_list ap) {
-{
        int status;
        va_list aq;
        int len;
@@ -169,14 +164,10 @@ int gettimeofday(struct timeval *tv, void *tz) {
 }
 #endif
 
-#ifndef HAVE_RANDOM
-#include <openssl/rand.h>
-
-long int random(void) {
-       long int x;
-       
-       RAND_pseudo_bytes((unsigned char *)&x, sizeof(x));
-
-       return x;
+#ifndef HAVE_USLEEP
+int usleep(long usec) {
+       struct timeval tv = {usec / 1000000, (usec / 1000) % 1000};
+       select(0, NULL, NULL, NULL, &tv);
+       return 0;
 }
 #endif