]> git.meshlink.io Git - meshlink/blobdiff - lib/dropin.c
Merge branch 'master' into 1.1
[meshlink] / lib / dropin.c
index a3c28b0412af761358a7718caa44a6d6037235ef..4ad32378bdbb541c90ac9e1303d8da059ff9988a 100644 (file)
@@ -38,8 +38,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 +96,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;
@@ -125,27 +123,35 @@ char *get_current_dir_name(void)
 #endif
 
 #ifndef HAVE_ASPRINTF
-int asprintf(char **buf, const char *fmt, ...)
-{
-       int status;
+int asprintf(char **buf, const char *fmt, ...) {
+       int result;
        va_list ap;
+       va_start(ap, fmt);
+       result = vasprintf(buf, fmt, ap);
+       va_end(ap);
+       return result;
+}
+
+int vasprintf(char **buf, const char *fmt, va_list ap) {
+       int status;
+       va_list aq;
        int len;
 
        len = 4096;
        *buf = xmalloc(len);
 
-       va_start(ap, fmt);
-       status = vsnprintf(*buf, len, fmt, ap);
-       va_end(ap);
+       va_copy(aq, ap);
+       status = vsnprintf(*buf, len, fmt, aq);
+       va_end(aq);
 
        if(status >= 0)
                *buf = xrealloc(*buf, status + 1);
 
        if(status > len - 1) {
                len = status;
-               va_start(ap, fmt);
-               status = vsnprintf(*buf, len, fmt, ap);
-               va_end(ap);
+               va_copy(aq, ap);
+               status = vsnprintf(*buf, len, fmt, aq);
+               va_end(aq);
        }
 
        return status;
@@ -159,15 +165,3 @@ int gettimeofday(struct timeval *tv, void *tz) {
        return 0;
 }
 #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;
-}
-#endif