[PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files

Rosen Penev rosenp at gmail.com
Sun Oct 26 13:00:49 PDT 2025


Allows removing the global GNU_SOURCE define.

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 jffsX-utils/mkfs.jffs2.c | 4 ++++
 lib/libmtd.c             | 6 +++++-
 lib/libmtd_legacy.c      | 5 ++++-
 misc-utils/flash_erase.c | 6 +++++-
 misc-utils/recv_image.c  | 4 ++++
 nand-utils/nandtest.c    | 4 ++++
 6 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/jffsX-utils/mkfs.jffs2.c b/jffsX-utils/mkfs.jffs2.c
index da07b69..b0e649c 100644
--- a/jffsX-utils/mkfs.jffs2.c
+++ b/jffsX-utils/mkfs.jffs2.c
@@ -49,6 +49,10 @@
 
 #define PROGRAM_NAME "mkfs.jffs2"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE    // needed for asprintf
+#endif
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <sys/stat.h>
diff --git a/lib/libmtd.c b/lib/libmtd.c
index f588e09..0489a15 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -22,12 +22,16 @@
  * MTD library.
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE    // needed for loff_t
+#endif
+
+#include <fcntl.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <dirent.h>
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index e0ecf49..457f330 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -23,7 +23,10 @@
  * not possible to get sub-page size.
  */
 
-#include <limits.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE    // needed for loff_t
+#endif
+
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c
index 36f8d57..98289f4 100644
--- a/misc-utils/flash_erase.c
+++ b/misc-utils/flash_erase.c
@@ -21,11 +21,15 @@
 
 #define PROGRAM_NAME "flash_erase"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE    // needed for loff_t
+#endif
+
+#include <fcntl.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
diff --git a/misc-utils/recv_image.c b/misc-utils/recv_image.c
index eeaa2e2..157e240 100644
--- a/misc-utils/recv_image.c
+++ b/misc-utils/recv_image.c
@@ -4,6 +4,10 @@
 #define _BSD_SOURCE	/* struct ip_mreq */
 #define _DEFAULT_SOURCE
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE     // needed for loff_t
+#endif
+
 #include <errno.h>
 #include <stdio.h>
 #include <netdb.h>
diff --git a/nand-utils/nandtest.c b/nand-utils/nandtest.c
index cac0dde..58542e5 100644
--- a/nand-utils/nandtest.c
+++ b/nand-utils/nandtest.c
@@ -1,5 +1,9 @@
 #define PROGRAM_NAME "nandtest"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE    // needed for loff_t
+#endif
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-- 
2.51.1




More information about the linux-mtd mailing list