[Libguestfs] [PATCH 1/2] Include <config.h> at the start of every C file.

Richard W.M. Jones rjones at redhat.com
Thu Dec 6 13:32:54 UTC 2012


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




More information about the Libguestfs mailing list