Richard W.M. Jones
2012-Dec-06 13:32 UTC
[Libguestfs] [PATCH 0/2] Two build fixes for libldm
Two simple build fixes for libldm. Well, the first isn't a build fix as such, but a code improvement. Rich.
Richard W.M. Jones
2012-Dec-06 13:32 UTC
[Libguestfs] [PATCH 1/2] Include <config.h> at the start of every C file.
From: "Richard W.M. Jones" <rjones at redhat.com>
As a rule of thumb, every C file should begin with:
#include <config.h>
Also add AC_USE_SYSTEM_EXTENSIONS to configure.ac so that config.h
defines _GNU_SOURCE etc when necessary.
---
configure.ac | 3 +++
src/gpt.c | 2 ++
src/ldm.c | 2 +-
src/ldmtool.c | 2 +-
src/mbr.c | 2 ++
test/ldmread.c | 2 ++
test/partread.c | 2 ++
7 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index cbffa95..ff1b10e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,9 @@ AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC_C99
LT_INIT
+# Define _GNU_SOURCE etc.
+AC_USE_SYSTEM_EXTENSIONS
+
AC_CHECK_LIB([readline], [readline], [],
[AC_MSG_ERROR([readline library is missing])])
diff --git a/src/gpt.c b/src/gpt.c
index beb8711..7f89631 100644
--- a/src/gpt.c
+++ b/src/gpt.c
@@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include <endian.h>
#include <iconv.h>
#include <linux/fs.h>
diff --git a/src/ldm.c b/src/ldm.c
index a55723c..d528a1a 100644
--- a/src/ldm.c
+++ b/src/ldm.c
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define _GNU_SOURCE
+#include <config.h>
#include <endian.h>
#include <errno.h>
diff --git a/src/ldmtool.c b/src/ldmtool.c
index 6e58883..cc49dc0 100644
--- a/src/ldmtool.c
+++ b/src/ldmtool.c
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define _GNU_SOURCE
+#include <config.h>
#include <dirent.h>
#include <errno.h>
diff --git a/src/mbr.c b/src/mbr.c
index bf9dd14..aff4a5b 100644
--- a/src/mbr.c
+++ b/src/mbr.c
@@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include <unistd.h>
#include <endian.h>
diff --git a/test/ldmread.c b/test/ldmread.c
index 448b43b..d8e5fec 100644
--- a/test/ldmread.c
+++ b/test/ldmread.c
@@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include <stdio.h>
#include <fcntl.h>
diff --git a/test/partread.c b/test/partread.c
index f7362b8..119ccb8 100644
--- a/test/partread.c
+++ b/test/partread.c
@@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include <stdio.h>
#include <fcntl.h>
--
1.8.0.1
Richard W.M. Jones
2012-Dec-06 13:32 UTC
[Libguestfs] [PATCH 2/2] Cast return value of be64toh to uint64_t before printing.
From: "Richard W.M. Jones" <rjones at redhat.com>
With glibc 2.16-24.fc18, be64toh is a macro around __bswap_64 which is
defined as:
unsigned long long int __bswap_64 (unsigned long long int __bsx);
Unfortunately on 64 bit platforms, unsigned long long int cannot be
printed using the expansion of PRIu64 ("%lu") resulting in about a
dozen errors such as:
ldm.c:1129:5: error: format '%lu' expects argument of type 'long
unsigned int', but argument 11 has type 'long long unsigned int'
[-Werror=format]
This commit corrects the problem by casting the result to uint64_t,
although I'm fairly sure that this is really a bug in glibc.
---
src/ldm.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/ldm.c b/src/ldm.c
index d528a1a..7335982 100644
--- a/src/ldm.c
+++ b/src/ldm.c
@@ -1090,18 +1090,18 @@ _find_vmdb(const void * const config, const gchar *
const path,
" Size: %" PRIu64 "\n"
" Flags2: %016" PRIo64,
path,
- be64toh(tocblock->seq1),
- be64toh(tocblock->seq2),
+ (uint64_t) be64toh(tocblock->seq1),
+ (uint64_t) be64toh(tocblock->seq2),
tocblock->bitmap[0].name,
be16toh(tocblock->bitmap[0].flags1),
- be64toh(tocblock->bitmap[0].start),
- be64toh(tocblock->bitmap[0].size),
- be64toh(tocblock->bitmap[0].flags2),
+ (uint64_t) be64toh(tocblock->bitmap[0].start),
+ (uint64_t) be64toh(tocblock->bitmap[0].size),
+ (uint64_t) be64toh(tocblock->bitmap[0].flags2),
tocblock->bitmap[1].name,
be16toh(tocblock->bitmap[1].flags1),
- be64toh(tocblock->bitmap[1].start),
- be64toh(tocblock->bitmap[1].size),
- be64toh(tocblock->bitmap[1].flags2));
+ (uint64_t) be64toh(tocblock->bitmap[1].start),
+ (uint64_t) be64toh(tocblock->bitmap[1].size),
+ (uint64_t) be64toh(tocblock->bitmap[1].flags2));
/* Find the start of the DB */
*vmdb = NULL;
@@ -1150,8 +1150,8 @@ _find_vmdb(const void * const config, const gchar * const
path,
be16toh((*vmdb)->version_major),
be16toh((*vmdb)->version_minor),
(*vmdb)->disk_group_guid,
- be64toh((*vmdb)->committed_seq),
- be64toh((*vmdb)->pending_seq),
+ (uint64_t) be64toh((*vmdb)->committed_seq),
+ (uint64_t) be64toh((*vmdb)->pending_seq),
be32toh((*vmdb)->n_committed_vblks_vol),
be32toh((*vmdb)->n_committed_vblks_comp),
be32toh((*vmdb)->n_committed_vblks_part),
@@ -1276,10 +1276,10 @@ _read_privhead_off(const int fd, const gchar * const
path,
be16toh(privhead->version_minor),
privhead->disk_guid,
privhead->disk_group_guid,
- be64toh(privhead->logical_disk_start),
- be64toh(privhead->logical_disk_size),
- be64toh(privhead->ldm_config_start),
- be64toh(privhead->ldm_config_size));
+ (uint64_t) be64toh(privhead->logical_disk_start),
+ (uint64_t) be64toh(privhead->logical_disk_size),
+ (uint64_t) be64toh(privhead->ldm_config_start),
+ (uint64_t) be64toh(privhead->ldm_config_size));
return TRUE;
}
--
1.8.0.1
Maybe Matching Threads
- [PATCH libldm v3 0/2] Make libldm to parse and return volume GUID.
- [PATCH libldm v4 0/3] Make libldm to parse and return volume GUID.
- DB virtualization for multiple database support - Was Re: How to use vmdb.sql in voicemail.conf/extension.conf
- [PATCH libldm 00/12] New API: an ability to retrieve created device-mapper devices back after they have been created.
- How to use vmdb.sql in voicemail.conf/extension.conf