summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/compat.c133
-rw-r--r--libglusterfs/src/compat.h3
-rw-r--r--libglusterfs/src/protocol.h9
3 files changed, 103 insertions, 42 deletions
diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c
index bad62b563d5..befc22c039f 100644
--- a/libglusterfs/src/compat.c
+++ b/libglusterfs/src/compat.c
@@ -369,38 +369,6 @@ solaris_getxattr(const char *path,
}
-int
-asprintf(char **string_ptr, const char *format, ...)
-{
- va_list arg;
- char *str;
- int size;
- int rv;
-
- if (!string_ptr || !format)
- return -1;
-
- va_start(arg, format);
- size = vsnprintf(NULL, 0, format, arg);
- size++;
- va_start(arg, format);
- str = MALLOC(size);
- if (str == NULL) {
- va_end(arg);
- /*
- * Strictly speaking, GNU asprintf doesn't do this,
- * but the caller isn't checking the return value.
- */
- gf_log ("libglusterfs", GF_LOG_CRITICAL, "failed to allocate memory");
- return -1;
- }
- rv = vsnprintf(str, size, format, arg);
- va_end(arg);
-
- *string_ptr = str;
- return (rv);
-}
-
char* strsep(char** str, const char* delims)
{
char* token;
@@ -424,6 +392,107 @@ char* strsep(char** str, const char* delims)
return token;
}
+/* Code comes from libiberty */
+
+int
+vasprintf (char **result, const char *format, va_list args)
+{
+ const char *p = format;
+ /* Add one to make sure that it is never zero, which might cause malloc
+ to return NULL. */
+ int total_width = strlen (format) + 1;
+ va_list ap;
+
+ /* this is not really portable but works under Windows */
+ memcpy ( &ap, &args, sizeof (va_list));
+
+ while (*p != '\0')
+ {
+ if (*p++ == '%')
+ {
+ while (strchr ("-+ #0", *p))
+ ++p;
+ if (*p == '*')
+ {
+ ++p;
+ total_width += abs (va_arg (ap, int));
+ }
+ else
+ {
+ char *endp;
+ total_width += strtoul (p, &endp, 10);
+ p = endp;
+ }
+ if (*p == '.')
+ {
+ ++p;
+ if (*p == '*')
+ {
+ ++p;
+ total_width += abs (va_arg (ap, int));
+ }
+ else
+ {
+ char *endp;
+ total_width += strtoul (p, &endp, 10);
+ p = endp;
+ }
+ }
+ while (strchr ("hlL", *p))
+ ++p;
+ /* Should be big enough for any format specifier except %s
+ and floats. */
+ total_width += 30;
+ switch (*p)
+ {
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ case 'c':
+ (void) va_arg (ap, int);
+ break;
+ case 'f':
+ case 'e':
+ case 'E':
+ case 'g':
+ case 'G':
+ (void) va_arg (ap, double);
+ /* Since an ieee double can have an exponent of 307, we'll
+ make the buffer wide enough to cover the gross case. */
+ total_width += 307;
+
+ case 's':
+ total_width += strlen (va_arg (ap, char *));
+ break;
+ case 'p':
+ case 'n':
+ (void) va_arg (ap, char *);
+ break;
+ }
+ }
+ }
+ *result = malloc (total_width);
+ if (*result != NULL)
+ return vsprintf (*result, format, args);
+ else
+ return 0;
+}
+
+int
+asprintf (char **buf, const char *fmt, ...)
+{
+ int status;
+ va_list ap;
+
+ va_start (ap, fmt);
+ status = vasprintf (buf, fmt, ap);
+ va_end (ap);
+ return status;
+}
+
#endif /* GF_SOLARIS_HOST_OS */
#ifndef HAVE_STRNLEN
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 228daf5da9d..588ad8b934e 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -218,7 +218,8 @@ enum {
#define lutimes(filename,times) utimes(filename,times)
-int asprintf(char **string_ptr, const char *format, ...);
+int asprintf (char **buf, const char *fmt, ...);
+int vasprintf (char **result, const char *format, va_list args);
char* strsep(char** str, const char* delims);
int solaris_listxattr(const char *path, char *list, size_t size);
int solaris_removexattr(const char *path, const char* key);
diff --git a/libglusterfs/src/protocol.h b/libglusterfs/src/protocol.h
index fdbaf85c02c..54734e6399e 100644
--- a/libglusterfs/src/protocol.h
+++ b/libglusterfs/src/protocol.h
@@ -219,13 +219,10 @@ gf_timespec_from_timespec (struct gf_timespec *gf_ts, struct timespec *ts)
#define GF_O_APPEND 02000
#define GF_O_NONBLOCK 04000
#define GF_O_SYNC 010000
-#define GF_O_ASYNC 020000
#define GF_O_DIRECT 040000
#define GF_O_DIRECTORY 0200000
#define GF_O_NOFOLLOW 0400000
-#define GF_O_NOATIME 01000000
-#define GF_O_CLOEXEC 02000000
#define GF_O_LARGEFILE 0100000
@@ -275,13 +272,10 @@ gf_flags_from_flags (uint32_t flags)
XLATE_BIT (flags, gf_flags, O_APPEND);
XLATE_BIT (flags, gf_flags, O_NONBLOCK);
XLATE_BIT (flags, gf_flags, O_SYNC);
- XLATE_BIT (flags, gf_flags, O_ASYNC);
XLATE_BIT (flags, gf_flags, O_DIRECT);
XLATE_BIT (flags, gf_flags, O_DIRECTORY);
XLATE_BIT (flags, gf_flags, O_NOFOLLOW);
- XLATE_BIT (flags, gf_flags, O_NOATIME);
- XLATE_BIT (flags, gf_flags, O_CLOEXEC);
XLATE_BIT (flags, gf_flags, O_LARGEFILE);
@@ -302,13 +296,10 @@ gf_flags_to_flags (uint32_t gf_flags)
UNXLATE_BIT (gf_flags, flags, O_APPEND);
UNXLATE_BIT (gf_flags, flags, O_NONBLOCK);
UNXLATE_BIT (gf_flags, flags, O_SYNC);
- UNXLATE_BIT (gf_flags, flags, O_ASYNC);
UNXLATE_BIT (gf_flags, flags, O_DIRECT);
UNXLATE_BIT (gf_flags, flags, O_DIRECTORY);
UNXLATE_BIT (gf_flags, flags, O_NOFOLLOW);
- UNXLATE_BIT (gf_flags, flags, O_NOATIME);
- UNXLATE_BIT (gf_flags, flags, O_CLOEXEC);
UNXLATE_BIT (gf_flags, flags, O_LARGEFILE);