Changeset

7931:b619b85e01aa

util.pposix, configure: Move _GNU_SOURCE macro into source files
author Kim Alvefur <zash@zash.se>
date Wed, 01 Mar 2017 22:27:11 +0100
parents 7930:5dec27760ecd
children 7932:6c5e4f24b51e
files configure util-src/crand.c util-src/net.c util-src/pposix.c util-src/signal.c
diffstat 5 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Wed Mar 01 17:48:15 2017 +0100
+++ b/configure	Wed Mar 01 22:27:11 2017 +0100
@@ -113,7 +113,7 @@
          RUNWITH="lua$LUA_SUFFIX"
          LUA_INCDIR="/usr/include/lua$LUA_SUFFIX"
          LUA_INCDIR_SET=yes
-         CFLAGS="$CFLAGS -ggdb -D_GNU_SOURCE"
+         CFLAGS="$CFLAGS -ggdb"
       fi
       if [ "$OSTYPE" = "macosx" ]; then
          LUA_INCDIR=/usr/local/include;
@@ -128,7 +128,7 @@
          LUA_INCDIR_SET=yes
          LUA_LIBDIR=/usr/local/lib
          LUA_LIBDIR_SET=yes
-         CFLAGS="$CFLAGS -ggdb -D_GNU_SOURCE"
+         CFLAGS="$CFLAGS -ggdb"
       fi
       if [ "$OSTYPE" = "freebsd" -o "$OSTYPE" = "openbsd" ]; then
          LUA_INCDIR="/usr/local/include/lua51"
@@ -167,7 +167,7 @@
             LUA_INCDIR="$LUA_CF"
             LUA_INCDIR_SET=yes
          fi
-         CFLAGS="$CFLAGS -D_GNU_SOURCE"
+         CFLAGS="$CFLAGS"
       fi
       ;;
    --libdir=*)
--- a/util-src/crand.c	Wed Mar 01 17:48:15 2017 +0100
+++ b/util-src/crand.c	Wed Mar 01 22:27:11 2017 +0100
@@ -19,6 +19,8 @@
 *
 */
 
+#define _DEFAULT_SOURCE
+
 #include "lualib.h"
 #include "lauxlib.h"
 
--- a/util-src/net.c	Wed Mar 01 17:48:15 2017 +0100
+++ b/util-src/net.c	Wed Mar 01 22:27:11 2017 +0100
@@ -9,6 +9,7 @@
 --
 */
 
+#define _GNU_SOURCE
 #include <stddef.h>
 #include <string.h>
 #include <errno.h>
--- a/util-src/pposix.c	Wed Mar 01 17:48:15 2017 +0100
+++ b/util-src/pposix.c	Wed Mar 01 22:27:11 2017 +0100
@@ -15,6 +15,14 @@
 
 #define MODULE_VERSION "0.3.6"
 
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#else
+#define _DEFAULT_SOURCE
+#endif
+#define _POSIX_C_SOURCE 200809L
+
 #include <stdlib.h>
 #include <math.h>
 #include <unistd.h>
@@ -40,11 +48,11 @@
 #endif
 
 #include <fcntl.h>
-#if defined(__linux__) && defined(_GNU_SOURCE)
+#if defined(__linux__)
 #include <linux/falloc.h>
 #endif
 
-#if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO))
+#if !defined(WITHOUT_MALLINFO)
 #include <malloc.h>
 #define WITH_MALLINFO
 #endif
@@ -663,7 +671,7 @@
 	lua_setfield(L, -2, "version");
 	lua_pushstring(L, uname_info.machine);
 	lua_setfield(L, -2, "machine");
-#ifdef _GNU_SOURCE
+#ifdef __USE_GNU
 	lua_pushstring(L, uname_info.domainname);
 	lua_setfield(L, -2, "domainname");
 #endif
@@ -726,7 +734,6 @@
  * https://github.com/rrthomas/luaposix/blob/master/lposix.c#L631
  * */
 
-#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE)
 int lc_fallocate(lua_State *L) {
 	int ret;
 	off_t offset, len;
@@ -739,7 +746,7 @@
 	offset = luaL_checkinteger(L, 2);
 	len = luaL_checkinteger(L, 3);
 
-#if defined(__linux__) && defined(_GNU_SOURCE)
+#if defined(__linux__)
 	errno = 0;
 	ret = fallocate(fileno(f), FALLOC_FL_KEEP_SIZE, offset, len);
 
@@ -759,10 +766,6 @@
 		return 2;
 	}
 
-#else
-#warning Only using posix_fallocate() fallback.
-#warning Linux fallocate() is strongly recommended if available: recompile with -D_GNU_SOURCE
-#warning Note that posix_fallocate() will still be used on filesystems that dont support fallocate()
 #endif
 
 	ret = posix_fallocate(fileno(f), offset, len);
@@ -784,7 +787,6 @@
 		return 2;
 	}
 }
-#endif
 
 /* Register functions */
 
@@ -825,9 +827,7 @@
 		{ "meminfo", lc_meminfo },
 #endif
 
-#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE)
 		{ "fallocate", lc_fallocate },
-#endif
 
 		{ NULL, NULL }
 	};
--- a/util-src/signal.c	Wed Mar 01 17:48:15 2017 +0100
+++ b/util-src/signal.c	Wed Mar 01 22:27:11 2017 +0100
@@ -26,6 +26,8 @@
  * OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#define _POSIX_C_SOURCE 200809L
+
 #include <signal.h>
 #include <stdlib.h>