[libvirt] [RFC PATCH] build: avoid %zu in translated strings

Eric Blake eblake at redhat.com
Tue Aug 17 22:05:03 UTC 2010


Mingw64 lacks %zu, and has the unfortunate setup where
sizeof(long)==4 but sizeof(size_t)==8.  Since gnulib's
printf-posix module is not LGPLv2+, the best we can do
is manually cast to the only portable int type known to
hold size_t, and rely on gnulib's inttypes.h.

* src/remote/remote_driver.c (remoteStreamPacket): Rewrite size_t
formatting.
* src/storage/storage_driver.c (storageWipeExtent): Likewise.
---

Here's the latter option; there are many more uses of %zu, but
only in DEBUG statements.  I suppose it would also be easy enough
to teach cfg.mk how to recognize and reject %z inside translated
strings, as part of 'make syntax-check'.

 src/remote/remote_driver.c   |    7 +++++--
 src/storage/storage_driver.c |    7 ++++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index cb0d8e1..d9115c8 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <arpa/inet.h>
 #include <sys/wait.h>
+#include <inttypes.h>

 /* Windows socket compatibility functions. */
 #include <errno.h>
@@ -8024,8 +8025,10 @@ remoteStreamPacket(virStreamPtr st,

     if (status == REMOTE_CONTINUE) {
         if (((4 + REMOTE_MESSAGE_MAX) - thiscall->bufferLength) < nbytes) {
-            remoteError(VIR_ERR_RPC, _("data size %zu too large for payload %d"),
-                        nbytes, ((4 + REMOTE_MESSAGE_MAX) - thiscall->bufferLength));
+            remoteError(VIR_ERR_RPC,
+                        _("data size %" PRIuMAX " too large for payload %d"),
+                        (uintmax_t) nbytes,
+                        ((4 + REMOTE_MESSAGE_MAX) - thiscall->bufferLength));
             goto error;
         }

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 4ebbced..3837182 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1,7 +1,7 @@
 /*
  * storage_driver.c: core driver for storage APIs
  *
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2010 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -29,6 +29,7 @@
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <fcntl.h>
+#include <inttypes.h>

 #if HAVE_PWD_H
 # include <pwd.h>
@@ -1597,9 +1598,9 @@ storageWipeExtent(virStorageVolDefPtr vol,
         written = safewrite(fd, writebuf, write_size);
         if (written < 0) {
             virReportSystemError(errno,
-                                 _("Failed to write %zu bytes to "
+                                 _("Failed to write %" PRIuMAX " bytes to "
                                    "storage volume with path '%s'"),
-                                 write_size, vol->target.path);
+                                 (uintmax_t) write_size, vol->target.path);

             goto out;
         }
-- 
1.7.2.1




More information about the libvir-list mailing list