put the ifdef for HAVE_VA_COPY in one place rather than in lots of
authorAndrew Tridgell <tridge@samba.org>
Mon, 3 Jun 2002 03:07:24 +0000 (03:07 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 3 Jun 2002 03:07:24 +0000 (03:07 +0000)
functions
(This used to be commit 1cf3228fdc20f0314d1f8e71ad710a5e548b3f72)

source3/CodingSuggestions
source3/include/includes.h
source3/lib/dprintf.c
source3/lib/snprintf.c
source3/lib/talloc.c
source3/lib/util.c
source3/lib/xfile.c

index 1ff3e01c1ca469f031c63e0e6514b2531b4e1b8b..eda2bee6d009c193acc99cad94bd6f2bdc833b8c 100644 (file)
@@ -59,8 +59,8 @@ Here are some other suggestions:
 6) explicitly add const qualifiers on parm passing in functions where parm
    is input only (somewhat controversial but const can be #defined away)
 
-7) when passing a va_list as an arg, or assigning one to another, check
-   for HAVE_VA_COPY, and use it if it exists.
+7) when passing a va_list as an arg, or assigning one to another
+   please use the VA_COPY() macro
        reason: on some platforms, va_list is a struct that must be 
                initialized in each function...can SEGV if you don't.
 
index 3d71f43303ca0c8ee2e4eaacdb648671896b4771..705cb485fded8869701e6ba96d2ab435222cf59f 100644 (file)
@@ -1164,5 +1164,13 @@ int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
 #define slprintf snprintf
 #define vslprintf vsnprintf
 
+
+/* we need to use __va_copy() on some platforms */
+#ifdef HAVE_VA_COPY
+#define VA_COPY(dest, src) __va_copy(dest, src)
+#else
+#define VA_COPY(dest, src) (dest) = (src)
+#endif
+
 #endif /* _INCLUDES_H */
 
index e3aa2c76696064e947514aa32eb3a3569ca4d330..f0f09e199d468bef70adad853034f65703d88e34 100644 (file)
@@ -42,11 +42,8 @@ int d_vfprintf(FILE *f, const char *format, va_list ap)
        msgstr = lang_msg(format);
        if (!msgstr) return -1;
 
-#if defined(HAVE_VA_COPY)
-       __va_copy(ap2, ap);
-#else
-       ap2 = ap;
-#endif
+       VA_COPY(ap2, ap);
+
        ret = vasprintf(&p, msgstr, ap2);
 
        lang_msg_free(msgstr);
index 561e775c8f01473fcda862ee4fd3486feb8137ac..aaad55f22ad49bb7d0a26f0696096b3f90974176 100644 (file)
@@ -163,11 +163,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
        size_t currlen;
        va_list args;
 
-#if defined(HAVE_VA_COPY)
-       __va_copy(args, args_in);
-#else
-       args = args_in;
-#endif
+       VA_COPY(args, args_in);
        
        state = DP_S_DEFAULT;
        currlen = flags = cflags = min = 0;
@@ -802,20 +798,16 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
        int ret;
        va_list ap2;
 
-#if defined(HAVE_VA_COPY)
-       __va_copy(ap2, ap);
-#else
-       ap2 = ap;
-#endif
+       VA_COPY(ap2, ap);
        
        ret = vsnprintf(NULL, 0, format, ap2);
        if (ret <= 0) return ret;
 
        (*ptr) = (char *)malloc(ret+1);
        if (!*ptr) return -1;
-#if defined(HAVE_VA_COPY)
-       __va_copy(ap2, ap);
-#endif
+
+       VA_COPY(ap2, ap);
+
        ret = vsnprintf(*ptr, ret+1, format, ap2);
 
        return ret;
index b66d674dd5a1ea06b9dd04a991a606a092683ce6..d81528588cec67a710a8f55279faa914f16c82e2 100644 (file)
@@ -318,18 +318,13 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p)
        char *ret;
        va_list ap2;
        
-#ifdef HAVE_VA_COPY
-       __va_copy(ap2, ap);  /* for systems were va_list is a struct */
-#else
-       ap2 = ap;
-#endif
+       VA_COPY(ap2, ap);
+
        len = vsnprintf(NULL, 0, fmt, ap2);
 
        ret = talloc(t, len+1);
        if (ret) {
-#ifdef HAVE_VA_COPY
-               __va_copy(ap2, ap);
-#endif
+               VA_COPY(ap2, ap);
                vsnprintf(ret, len+1, fmt, ap2);
        }
 
@@ -366,20 +361,16 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p)
        int len, s_len;
        va_list ap2;
 
-#ifdef HAVE_VA_COPY
-       __va_copy(ap2, ap);
-#else
-       ap2 = ap;
-#endif
+       VA_COPY(ap2, ap);
+
        s_len = strlen(s);
        len = vsnprintf(NULL, 0, fmt, ap2);
 
        s = talloc_realloc(t, s, s_len + len+1);
        if (!s) return NULL;
 
-#ifdef HAVE_VA_COPY
-       __va_copy(ap2, ap);
-#endif
+       VA_COPY(ap2, ap);
+
        vsnprintf(s+s_len, len+1, fmt, ap2);
 
        return s;
index 2fe9ec331b20fa58daca42929a153fadaf33fc2a..fe1011668de8ca88357d710309abd0a74674d30c 100644 (file)
@@ -1820,11 +1820,9 @@ int smb_xvasprintf(char **ptr, const char *format, va_list ap)
 {
        int n;
        va_list ap2;
-#if defined(HAVE_VA_COPY)
-       __va_copy(ap2, ap);
-#else
-       ap2 = ap;
-#endif
+
+       VA_COPY(ap2, ap);
+
        n = vasprintf(ptr, format, ap2);
        if (n == -1 || ! *ptr) {
                smb_panic("smb_xvasprintf: out of memory");
index 7b97d329aeaec50e3fa1feecd83fc477d5113560..59f9fd48ad006ab10b4d15ad8a6d05b33e11af64 100644 (file)
@@ -188,11 +188,9 @@ int x_vfprintf(XFILE *f, const char *format, va_list ap)
        char *p;
        int len, ret;
        va_list ap2;
-#if defined(HAVE_VA_COPY)
-       __va_copy(ap2, ap);
-#else
-       ap2 = ap;
-#endif
+
+       VA_COPY(ap2, ap);
+
        len = vasprintf(&p, format, ap2);
        if (len <= 0) return len;
        ret = x_fwrite(p, 1, len, f);