]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/compat/misc.c
Add libatalk ABI for 3.1.0 and bump library version leaving room for 3.0 series
[netatalk.git] / libatalk / compat / misc.c
index 2fe6a7f3cfc6adec921b2a7a8ea9a53d0505d18f..32e2943dded16b60795979e39b956725d5103349 100644 (file)
@@ -1,5 +1,20 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdarg.h>
+
 #include <atalk/compat.h>
 
+#if !defined HAVE_DIRFD && defined SOLARIS
+#include <dirent.h>
+int dirfd(DIR *dir)
+{
+    return dir->d_fd;
+}
+#endif
+
 #ifndef HAVE_STRNLEN
 size_t strnlen(const char *s, size_t max)
 {
@@ -13,3 +28,36 @@ size_t strnlen(const char *s, size_t max)
     return len;  
 }
 #endif
+
+#ifndef HAVE_VASPRINTF
+int vasprintf(char **ret, const char *fmt, va_list ap)
+{
+    int n, size = 64;
+    char *p, *np;
+
+    if ((p = malloc(size)) == NULL)
+        return NULL;
+
+    while (1) {
+        /* Try to print in the allocated space. */
+        n = vsnprintf(p, size, fmt, ap);
+        /* If that worked, return the string. */
+        if (n > -1 && n < size) {
+            *ret = p;
+            return n;
+        }
+        /* Else try again with more space. */
+        if (n > -1)    /* glibc 2.1 */
+            size = n+1; /* precisely what is needed */
+        else           /* glibc 2.0 */
+            size *= 2;  /* twice the old size */
+        if ((np = realloc (p, size)) == NULL) {
+            free(p);
+            *ret = NULL;
+            return -1;
+        } else {
+            p = np;
+        }
+    }
+}
+#endif