]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsnprintf.c
Detect mount/junction points and ignore junctions in Windows
[bacula/bacula] / bacula / src / lib / bsnprintf.c
index 5fa592610b248e75f4ec1f990d227098db6ad92b..d808ca8d13f38bf04853f40f322bb47e6fa16742 100644 (file)
@@ -6,7 +6,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    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
+   You should have received a copy of the GNU Affero 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.
@@ -115,6 +115,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
 #define DP_C_LDOUBLE  3
 #define DP_C_INT64    4
 #define DP_C_WCHAR    5      /* wide characters */
+#define DP_C_SIZE_T   6
 
 #define char_to_int(p) ((p)- '0')
 #undef MAX
@@ -250,6 +251,10 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
                ch = *format++;
             }
             break;
+         case 'z':
+            cflags = DP_C_SIZE_T;
+            ch = *format++;
+            break;
          case 'L':
             cflags = DP_C_LDOUBLE;
             ch = *format++;
@@ -273,6 +278,8 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
                value = va_arg(args, int32_t);
             } else if (cflags == DP_C_INT64) {
                value = va_arg(args, int64_t);
+            } else if (cflags == DP_C_SIZE_T) {
+               value = va_arg(args, ssize_t);
             } else {
                value = va_arg(args, int);
             }
@@ -299,6 +306,8 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
                value = va_arg(args, uint32_t);
             } else if (cflags == DP_C_INT64) {
                value = va_arg(args, uint64_t);
+            } else if (cflags == DP_C_SIZE_T) {
+               value = va_arg(args, size_t);
             } else {
                value = va_arg(args, unsigned int);
             }
@@ -339,10 +348,16 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
          case 's':
             if (cflags != DP_C_WCHAR) {
               strvalue = va_arg(args, char *);
+              if (!strvalue) {
+                 strvalue = (char *)"<NULL>";
+              }
               currlen = fmtstr(buffer, currlen, maxlen, strvalue, flags, min, max);
             } else {
               /* %ls means to edit wide characters */
               wstrvalue = va_arg(args, wchar_t *);
+              if (!wstrvalue) {
+                 wstrvalue = (wchar_t *)L"<NULL>";
+              }
               currlen = fmtwstr(buffer, currlen, maxlen, wstrvalue, flags, min, max);
             }
             break;
@@ -428,9 +443,6 @@ static int32_t fmtstr(char *buffer, int32_t currlen, int32_t maxlen,
    } else if (max < 0) {
       max = maxlen;
    }
-   if (!value) {
-      value = "<NULL>";
-   }
    strln = strlen(value);
    if (strln > max) {
       strln = max;                /* truncate to max */
@@ -472,9 +484,6 @@ static int32_t fmtwstr(char *buffer, int32_t currlen, int32_t maxlen,
    } else if (max < 0) {
       max = maxlen;
    }
-   if (!value) {
-      value = L"<NULL>";
-   }
    strln = wcslen(value);
    if (strln > max) {
       strln = max;                /* truncate to max */
@@ -743,6 +752,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
 
    if (!result) {
       r_length = 0;
+      dummy[0] = 0;
       result = dummy;
    } else {
       r_length = strlen(result);