Skip to contentSkip to conversation

libdevmapper.h: make this include file standard-compliant

PATCH New Mikulas Patocka 2 participants 3 messages Mar 16, 2013 – Mar 18, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libdevmapper.h: make this include file standard-compliant

libdevmapper.h: make this include file standard-compliant

This file may be included by other programs, so it should be compliant with the C standard.

* use __linux__ instead of linux - __linux__ is always defined, linux is not defined when gcc runs in standard-compliant mode (with -std=c89 or -std=c99) because the C standard doesn't allow polluting namespace with arbitrary defines.

* the inline keyword is not present in the c89 standard (with gcc -std=c89). If the compiler runs in c89 mode, use __inline__ (which is gcc extension), or nothing at all if we don't use gcc.

---
 libdm/libdevmapper.h |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
libdm/libdevmapper.h +8 -2
Index: LVM2.2.02.98/libdm/libdevmapper.h
===================================================================
@@ -21,7 +21,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#ifdef linux
+#ifdef __linux__
 #  include <linux/types.h>
 #endif
 
@@ -940,7 +940,13 @@ int dm_bit_get_next(dm_bitset_t bs, int 
    memcpy((bs1) + 1, (bs2) + 1, ((*(bs1) / DM_BITS_PER_INT) + 1) * sizeof(int))
 
 /* Returns number of set bits */
-static inline unsigned hweight32(uint32_t i)
+static
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
+inline
+#elif defined(__GNUC__)
+__inline__
+#endif
+unsigned hweight32(uint32_t i)
 {
 	unsigned r = (i & 0x55555555) + ((i >> 1) & 0x55555555);
 
#1 lore raw

PATCH 1/1 libdevmapper.h: make this include file standard-compliant

Is there any reason for any of the code to try to support c89 these days?

I was assuming c99 as the miniumum and saw no need to support c89.

Alasdair

#2 lore raw

PATCH 1/1 libdevmapper.h: make this include file standard-compliant

Quoted 5 lines · Alasdair G Kergon

Is there any reason for any of the code to try to support c89 these days?

I was assuming c99 as the miniumum and saw no need to support c89.

Alasdair

Include files typically need to be compatible with c89, so that users can compile their programs in c89 mode. (some BSD systems go even as far to support K&R prototypes in their include files)

In libdevmapper.h it is not critical because there are very few programs that use it. If you want to include c89 support, do it, but it is not critical.

Mikulas