]> sourceware.org Git - lvm2.git/commitdiff
Add dm_snprintf
authorAlasdair Kergon <agk@redhat.com>
Mon, 21 Aug 2006 12:52:39 +0000 (12:52 +0000)
committerAlasdair Kergon <agk@redhat.com>
Mon, 21 Aug 2006 12:52:39 +0000 (12:52 +0000)
WHATS_NEW_DM
libdm/.exported_symbols
libdm/libdevmapper.h
libdm/libdm-string.c

index 01d95e60c1fc2ada17404a90ed92f3868a785a48..1932c2cd4166c55375f3dec8800a3fca5fe781f7 100644 (file)
@@ -1,6 +1,6 @@
 Version 1.02.10 - 
 ==============================
-  Add dm_split_words() and dm_split_lvm_name() to libdevmapper.
+  Add dm_snprintf(), dm_split_words() and dm_split_lvm_name() to libdevmapper.
   Reorder mm bounds_check code to reduce window for a dmeventd race.
 
 Version 1.02.09 - 15 Aug 2006
index 263d2ad6125b9dbdcb8d3eb9404ad36244ebe0d8..43cbf51f75ee6766fb240516586ddfc2aca66c14 100644 (file)
@@ -111,3 +111,4 @@ dm_set_selinux_context
 dm_task_set_geometry
 dm_split_lvm_name
 dm_split_words
+dm_snprintf
index c979e87284d04a2acbd1d32c2cf5fd7a3dbf3eaf..209177f684635d18ab404ecd9ad6191249453eaf 100644 (file)
@@ -17,6 +17,7 @@
 #define LIB_DEVICE_MAPPER_H
 
 #include <inttypes.h>
+#include <stdarg.h>
 #include <sys/types.h>
 
 #ifdef linux
@@ -601,4 +602,9 @@ int dm_split_words(char *buffer, unsigned max,
                   unsigned ignore_comments, /* Not implemented */
                   char **argv);
 
+/* 
+ * Returns -1 if buffer too small
+ */
+int dm_snprintf(char *buf, size_t bufsize, const char *format, ...);
+
 #endif                         /* LIB_DEVICE_MAPPER_H */
index 4ce6608078672812931e98c8e2f71b498235305d..f990d95bcf5c1b74b4a688b78350e5b0579018f9 100644 (file)
@@ -99,3 +99,25 @@ int dm_split_lvm_name(struct dm_pool *mem, const char *dmname,
 
        return 1;
 }
+
+/*
+ * On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small;
+ * From glibc 2.1 it returns number of chars (excl. trailing null) that would 
+ * have been written had there been room.
+ *
+ * dm_snprintf reverts to the old behaviour.
+ */
+int dm_snprintf(char *buf, size_t bufsize, const char *format, ...)
+{
+       int n;
+       va_list ap;
+
+       va_start(ap, format);
+       n = vsnprintf(buf, bufsize, format, ap);
+       va_end(ap);
+
+       if (n < 0 || (n > bufsize - 1))
+               return -1;
+
+       return n;
+}
This page took 0.034702 seconds and 5 git commands to generate.