From 82755e48e832ca94886d0d4376343ac74cf00bd6 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 1 Mar 2017 17:03:48 +0100
Subject: util.pposix: Expose ENOENT constant (usually 2, but you never know)

---
 util-src/pposix.c | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'util-src')

diff --git a/util-src/pposix.c b/util-src/pposix.c
index 10edbd71..da47cac2 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -835,6 +835,11 @@ int luaopen_util_pposix(lua_State *L) {
 	lua_newtable(L);
 	luaL_setfuncs(L, exports, 0);
 
+#ifdef ENOENT
+	lua_pushinteger(L, ENOENT);
+	lua_setfield(L, -2, "ENOENT");
+#endif
+
 	lua_pushliteral(L, "pposix");
 	lua_setfield(L, -2, "_NAME");
 
-- 
cgit v1.2.3


From d205c783278eea95143aa95443803c16882c3f5b Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 1 Mar 2017 22:27:11 +0100
Subject: util.pposix, configure: Move _GNU_SOURCE macro into source files

---
 util-src/crand.c  |  2 ++
 util-src/net.c    |  1 +
 util-src/pposix.c | 24 ++++++++++++------------
 util-src/signal.c |  2 ++
 4 files changed, 17 insertions(+), 12 deletions(-)

(limited to 'util-src')

diff --git a/util-src/crand.c b/util-src/crand.c
index f3fa00ea..8ac89a1f 100644
--- a/util-src/crand.c
+++ b/util-src/crand.c
@@ -19,6 +19,8 @@
 *
 */
 
+#define _DEFAULT_SOURCE
+
 #include "lualib.h"
 #include "lauxlib.h"
 
diff --git a/util-src/net.c b/util-src/net.c
index 32f69025..35f2c362 100644
--- a/util-src/net.c
+++ b/util-src/net.c
@@ -9,6 +9,7 @@
 --
 */
 
+#define _GNU_SOURCE
 #include <stddef.h>
 #include <string.h>
 #include <errno.h>
diff --git a/util-src/pposix.c b/util-src/pposix.c
index da47cac2..f9c07e54 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -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 @@ int lc_uname(lua_State *L) {
 	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 @@ int lc_meminfo(lua_State *L) {
  * 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 @@ int lc_fallocate(lua_State *L) {
 	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 @@ int lc_fallocate(lua_State *L) {
 		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 @@ int lc_fallocate(lua_State *L) {
 		return 2;
 	}
 }
-#endif
 
 /* Register functions */
 
@@ -825,9 +827,7 @@ int luaopen_util_pposix(lua_State *L) {
 		{ "meminfo", lc_meminfo },
 #endif
 
-#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(_GNU_SOURCE)
 		{ "fallocate", lc_fallocate },
-#endif
 
 		{ NULL, NULL }
 	};
diff --git a/util-src/signal.c b/util-src/signal.c
index a083df54..2cf68800 100644
--- a/util-src/signal.c
+++ b/util-src/signal.c
@@ -26,6 +26,8 @@
  * OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#define _POSIX_C_SOURCE 200809L
+
 #include <signal.h>
 #include <stdlib.h>
 
-- 
cgit v1.2.3


From dfb72918f3fa150c6f6bae95cf2c945d17200fd4 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 1 Mar 2017 22:39:01 +0100
Subject: util.crand: Move comment block

---
 util-src/crand.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'util-src')

diff --git a/util-src/crand.c b/util-src/crand.c
index 8ac89a1f..95362589 100644
--- a/util-src/crand.c
+++ b/util-src/crand.c
@@ -36,10 +36,6 @@
 #error getrandom() requires Linux 3.17 or later
 #endif
 
-/*
- * This acts like a read from /dev/urandom with the exception that it
- * *does* block if the entropy pool is not yet initialized.
- */
 int getrandom(void *buf, size_t len, int flags) {
 	return syscall(SYS_getrandom, buf, len, flags);
 }
@@ -58,6 +54,10 @@ int Lrandom(lua_State *L) {
 	void *buf = lua_newuserdata(L, len);
 
 #if defined(WITH_GETRANDOM)
+	/*
+	 * This acts like a read from /dev/urandom with the exception that it
+	 * *does* block if the entropy pool is not yet initialized.
+	 */
 	ret = getrandom(buf, len, 0);
 
 	if(ret < 0) {
-- 
cgit v1.2.3


From 7dba99875fa4a3539cc7778efa7486bdcefea898 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Thu, 2 Mar 2017 00:15:04 +0100
Subject: util.crand: Change argumen names to match some man page

---
 util-src/crand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'util-src')

diff --git a/util-src/crand.c b/util-src/crand.c
index 95362589..353b153c 100644
--- a/util-src/crand.c
+++ b/util-src/crand.c
@@ -36,8 +36,8 @@
 #error getrandom() requires Linux 3.17 or later
 #endif
 
-int getrandom(void *buf, size_t len, int flags) {
-	return syscall(SYS_getrandom, buf, len, flags);
+int getrandom(void *buf, size_t buflen, unsigned int flags) {
+	return syscall(SYS_getrandom, buf, buflen, flags);
 }
 
 #elif defined(WITH_ARC4RANDOM)
-- 
cgit v1.2.3


From 956c50882b749f8b3cc007aaec8c0a5c2c6725ee Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Thu, 2 Mar 2017 00:17:34 +0100
Subject: util.crand: Only include getrandom shiv with glibc older than 2.25

---
 util-src/crand.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'util-src')

diff --git a/util-src/crand.c b/util-src/crand.c
index 353b153c..ef9da4d2 100644
--- a/util-src/crand.c
+++ b/util-src/crand.c
@@ -28,17 +28,22 @@
 #include <errno.h>
 
 #if defined(WITH_GETRANDOM)
+
+#if ! __GLIBC_PREREQ(2,25)
 #include <unistd.h>
 #include <sys/syscall.h>
-#include <linux/random.h>
 
 #ifndef SYS_getrandom
 #error getrandom() requires Linux 3.17 or later
 #endif
 
+/* This wasn't present before glibc 2.25 */
 int getrandom(void *buf, size_t buflen, unsigned int flags) {
 	return syscall(SYS_getrandom, buf, buflen, flags);
 }
+#else
+#include <sys/random.h>
+#endif
 
 #elif defined(WITH_ARC4RANDOM)
 #include <stdlib.h>
-- 
cgit v1.2.3


From 3bf3935e78e682642593f783762bc648a65f4d72 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Thu, 2 Mar 2017 00:46:32 +0100
Subject: Backed out changeset a3a4ed0d34f4 C99 is ok

---
 util-src/table.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'util-src')

diff --git a/util-src/table.c b/util-src/table.c
index 0e547858..f1cd9e12 100644
--- a/util-src/table.c
+++ b/util-src/table.c
@@ -7,12 +7,11 @@ static int Lcreate_table(lua_State *L) {
 }
 
 static int Lpack(lua_State *L) {
-	int arg;
 	unsigned int n_args = lua_gettop(L);
 	lua_createtable(L, n_args, 1);
 	lua_insert(L, 1);
 
-	for(arg = n_args; arg >= 1; arg--) {
+	for(int arg = n_args; arg >= 1; arg--) {
 		lua_rawseti(L, 1, arg);
 	}
 
-- 
cgit v1.2.3


From 2246bd21b50f12862cb99c92edfaa79c97f4d47b Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Thu, 2 Mar 2017 19:22:07 +0100
Subject: util.ringbuffer: Change types of length related variables to size_t
 [-Wsign-compare]

---
 util-src/ringbuffer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'util-src')

diff --git a/util-src/ringbuffer.c b/util-src/ringbuffer.c
index 831b1fe2..2a13903c 100644
--- a/util-src/ringbuffer.c
+++ b/util-src/ringbuffer.c
@@ -31,7 +31,7 @@ void modpos(ringbuffer *b) {
 	b->wpos = b->wpos % b->alen;
 }
 
-int find(ringbuffer *b, const char *s, int l) {
+int find(ringbuffer *b, const char *s, size_t l) {
 	size_t i, j;
 	int m;
 
@@ -74,7 +74,7 @@ int rb_find(lua_State *L) {
 
 int rb_read(lua_State *L) {
 	ringbuffer *b = luaL_checkudata(L, 1, "ringbuffer_mt");
-	int r = luaL_checkinteger(L, 2);
+	size_t r = luaL_checkinteger(L, 2);
 	int peek = lua_toboolean(L, 3);
 
 	if(r > b->blen) {
-- 
cgit v1.2.3