Skip to contentSkip to conversation

Drop feature defines from C files, in favour of CFLAGS defines.

PATCH Applied Dimitri John Ledkov 2 participants 2 messages Jan 18, 2015 – Jan 21, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Drop feature defines from C files, in favour of CFLAGS defines.

glibc 2.10+ (5+ years old) enables all the desired features:
_XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined.

This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c).

This patch thus cleans up all feature defines, and sets them at a consistent level.

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969

---
 Makefile              | 2 +-
 btrfs-calc-size.c     | 2 --
 btrfs-convert.c       | 3 ---
 btrfs-corrupt-block.c | 2 --
 btrfs-find-root.c     | 2 --
 btrfs-fragments.c     | 1 -
 btrfs-image.c         | 2 --
 btrfs-list.c          | 1 -
 btrfs-map-logical.c   | 2 --
 btrfs-select-super.c  | 2 --
 btrfs-show-super.c    | 2 --
 btrfs-zero-log.c      | 2 --
 btrfs.c               | 1 -
 btrfstune.c           | 2 --
 chunk-recover.c       | 2 --
 cmds-check.c          | 2 --
 cmds-filesystem.c     | 1 -
 cmds-receive.c        | 5 -----
 cmds-restore.c        | 2 --
 cmds-send.c           | 1 -
 disk-io.c             | 3 ---
 extent_io.c           | 2 --
 mkfs.c                | 3 ---
 send-test.c           | 2 --
 super-recover.c       | 3 ---
 utils-lib.c           | 2 --
 utils.c               | 4 ----
 volumes.c             | 2 --
 28 files changed, 1 insertion(+), 59 deletions(-)
Makefile +1 -1
index 8b843bb..4d7cb4a 100644
@@ -4,7 +4,7 @@ export
 CC = gcc
 LN = ln
 AR = ar
-AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES -fno-strict-aliasing -fPIC
+AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -fno-strict-aliasing -fPIC
 CFLAGS = -g -O1 -fno-strict-aliasing
 LDFLAGS = -rdynamic
 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
btrfs-calc-size.c +0 -2
index 501111c..17d048c 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
btrfs-convert.c +0 -3
index bbd19bb..da10ad6 100644
@@ -16,9 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 600
-#define _GNU_SOURCE 1
-
 #include "kerncompat.h"
 
 #include <sys/ioctl.h>
btrfs-corrupt-block.c +0 -2
index b477e87..6b9dac5 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
btrfs-find-root.c +0 -2
index 6fa61cc..3517107 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
btrfs-fragments.c +0 -1
index 360f10f..d742f60 100644
@@ -14,7 +14,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
btrfs-image.c +0 -2
index cb17f16..0485c8f 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
btrfs-list.c +0 -1
index 50edcf4..3e29cf8 100644
@@ -16,7 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _GNU_SOURCE
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include "ioctl.h"
btrfs-map-logical.c +0 -2
index 47d1104..c235d44 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
btrfs-select-super.c +0 -2
index 6231d42..063ffa3 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
btrfs-show-super.c +0 -2
index 2b48f44..4afa852 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
btrfs-zero-log.c +0 -2
index 4154175..31e7481 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
btrfs.c +0 -1
index e83349c..2451885 100644
@@ -14,7 +14,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
btrfstune.c +0 -2
index 050418a..e175137 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
chunk-recover.c +0 -2
index 381b596..89219d2 100644
@@ -15,8 +15,6 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 021110-1307, USA.
  */
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE
 
 #include <stdio.h>
 #include <stdio_ext.h>
cmds-check.c +0 -2
index f06e029..6741003 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
cmds-filesystem.c +0 -1
index a3cf114..da12ede 100644
@@ -14,7 +14,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
cmds-receive.c +0 -5
index f269ade..983d179 100644
@@ -16,11 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _GNU_SOURCE
-#define _POSIX_C_SOURCE 200809
-#define _XOPEN_SOURCE 700
-#define _DEFAULT_SOURCE
-
 #include "kerncompat.h"
 
 #include <unistd.h>
cmds-restore.c +0 -2
index 859deaf..0bcba92 100644
@@ -16,8 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
 
 #include "kerncompat.h"
 
cmds-send.c +0 -1
index 9b32c1f..e59ba50 100644
@@ -16,7 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _GNU_SOURCE
 
 #include "kerncompat.h"
 
disk-io.c +0 -3
index b853f66..7f03790 100644
@@ -16,9 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 600
-#define __USE_XOPEN2K
-#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
extent_io.c +0 -2
index 9c982f9..cd0efdd 100644
@@ -16,8 +16,6 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 021110-1307, USA.
  */
-#define _XOPEN_SOURCE 600
-#define __USE_XOPEN2K
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
mkfs.c +0 -3
index 98a1edd..9e63b2e 100644
@@ -16,9 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE
-
 #include "kerncompat.h"
 
 #include <sys/ioctl.h>
send-test.c +0 -2
index 0e804a2..af8229e 100644
@@ -21,8 +21,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _GNU_SOURCE
-
 #include <unistd.h>
 #include <stdint.h>
 #include <dirent.h>
super-recover.c +0 -3
index adb2c44..197fc4b 100644
@@ -16,9 +16,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
utils-lib.c +0 -2
index 9d53c6e..79ef35e 100644
@@ -1,5 +1,3 @@
-#define _GNU_SOURCE
-
 #include "kerncompat.h"
 #include <unistd.h>
 #include <stdlib.h>
utils.c +0 -4
index 9b08144..a818950 100644
@@ -17,10 +17,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 700
-#define __USE_XOPEN2K8
-#define __XOPEN2K8 /* due to an error in dirent.h, to get dirfd() */
-#define _GNU_SOURCE	/* O_NOATIME */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
volumes.c +0 -2
index 5ba5db5..16dbf64 100644
@@ -15,8 +15,6 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 021110-1307, USA.
  */
-#define _XOPEN_SOURCE 600
-#define __USE_XOPEN2K
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
Signature · 1 line
2.1.0
Applied
#1 lore raw
Quoted 5 lines · Dimitri John Ledkov

glibc 2.10+ (5+ years old) enables all the desired features:
_XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined.

Sounds reasonable to me.

Quoted 9 lines

This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c).

This patch thus cleans up all feature defines, and sets them at a consistent level.

Thanks, applied.