[ovs-dev] [PATCH v2] util: New wrapper function ovs_vsnprintf().

Saurabh Shah ssaurabh at vmware.com
Fri Dec 20 22:54:19 UTC 2013


Sorry, wrong patch. Please ignore.

From: Saurabh Shah <ssaurabh at nicira.com<mailto:ssaurabh at nicira.com>>
Date: Friday, December 20, 2013 2:58 PM
To: "dev at openvswitch.org<mailto:dev at openvswitch.org>" <dev at openvswitch.org<mailto:dev at openvswitch.org>>
Subject: [ovs-dev] [PATCH v2] util: New wrapper function ovs_vsnprintf().

So that vsnprintf on windows has C99 like semantics.

Signed-off-by: Saurabh Shah <ssaurabh at nicira.com<mailto:ssaurabh at nicira.com>>
---
lib/command-line.c   |    2 +-
lib/dynamic-string.c |    4 ++--
lib/util.c           |   18 ++++++++++++++++--
lib/util.h           |    1 +
4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/lib/command-line.c b/lib/command-line.c
index 805e51b..01f6b16 100644
--- a/lib/command-line.c
+++ b/lib/command-line.c
@@ -171,7 +171,7 @@ proctitle_set(const char *format, ...)
     va_start(args, format);
     n = snprintf(argv_start, argv_size, "%s: ", program_name);
     if (n < argv_size) {
-        n += vsnprintf(argv_start + n, argv_size - n, format, args);
+        n += ovs_vsnprintf(argv_start + n, argv_size - n, format, args);
     }
     if (n >= argv_size) {
         /* The name is too long, so add an ellipsis at the end. */
diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c
index 914af64..dcc1379 100644
--- a/lib/dynamic-string.c
+++ b/lib/dynamic-string.c
@@ -152,7 +152,7 @@ ds_put_format_valist(struct ds *ds, const char *format, va_list args_)
     va_copy(args, args_);
     available = ds->string ? ds->allocated - ds->length + 1 : 0;
-    needed = vsnprintf(&ds->string[ds->length], available, format, args);
+    needed = ovs_vsnprintf(&ds->string[ds->length], available, format, args);
     va_end(args);
     if (needed < available) {
@@ -162,7 +162,7 @@ ds_put_format_valist(struct ds *ds, const char *format, va_list args_)
         va_copy(args, args_);
         available = ds->allocated - ds->length + 1;
-        needed = vsnprintf(&ds->string[ds->length], available, format, args);
+        needed = ovs_vsnprintf(&ds->string[ds->length], available, format, args);
         va_end(args);
         ovs_assert(needed < available);
diff --git a/lib/util.c b/lib/util.c
index 984ab45..4e60b0e 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -155,11 +155,11 @@ xvasprintf(const char *format, va_list args)
     char *s;
     va_copy(args2, args);
-    needed = vsnprintf(NULL, 0, format, args);
+    needed = ovs_vsnprintf(NULL, 0, format, args);
     s = xmalloc(needed + 1);
-    vsnprintf(s, needed + 1, format, args2);
+    ovs_vsnprintf(s, needed + 1, format, args2);
     va_end(args2);
     return s;
@@ -502,6 +502,20 @@ ovs_hex_dump(FILE *stream, const void *buf_, size_t size,
     }
}
+int
+ovs_vsnprintf(char * s, size_t n, const char * format, va_list arg)
+{
+#ifndef _WIN32
+    return vsnprintf(s, n ,format, arg);
+#else
+    int needed = _vscprintf(format, arg);
+    if (s && (needed < n)) {
+        vsnprintf(s, n, format, arg);
+    }
+    return needed;
+#endif
+}
+
bool
str_to_int(const char *s, int base, int *i)
{
diff --git a/lib/util.h b/lib/util.h
index 8886a54..1519808 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -273,6 +273,7 @@ void ovs_error_valist(int err_no, const char *format, va_list)
const char *ovs_retval_to_string(int);
const char *ovs_strerror(int);
void ovs_hex_dump(FILE *, const void *, size_t, uintptr_t offset, bool ascii);
+int ovs_vsnprintf(char * s, size_t n, const char * format, va_list arg);
bool str_to_int(const char *, int base, int *);
bool str_to_long(const char *, int base, long *);
--
1.7.9.5

_______________________________________________
dev mailing list
dev at openvswitch.org<mailto:dev at openvswitch.org>
https://urldefense.proofpoint.com/v1/url?u=http://openvswitch.org/mailman/listinfo/dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=pEkjsHfytvHEWufeZPpgqSOJMdMjuZPbesVsNhCUc0E%3D%0A&m=LyRVOOm7QBuJpz1f1ITBv39bbPIjHUsG%2Bw8jfmwedME%3D%0A&s=94cf86a7d599efea00e891a7ac92fc1f7de9bd0c2c011f23cdc9a92981f05b7f

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20131220/ec1e2bab/attachment-0003.html>


More information about the dev mailing list