Created
November 28, 2016 01:10
-
-
Save rigelk/621f3515fed57476ccc6c58fdef99343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 28ca8cd283095614d65ab9acfc1afe57c1965e57 Mon Sep 17 00:00:00 2001 | |
From: Pierre-Antoine Rault <par@rigelk.eu> | |
Date: Mon, 28 Nov 2016 01:28:26 +0100 | |
Subject: [PATCH] fixes #41 deprecated readdir_r | |
* src/hakactl/console.c (initialize_console): readdir_r is removed in favor of POSIX.1-2008-compliant readdir, mainly to support glibc >= glibc-2.24 (released Aug 5, 2016). | |
--- | |
src/hakactl/console.c | 23 ++++++++++++----------- | |
1 file changed, 12 insertions(+), 11 deletions(-) | |
diff --git a/src/hakactl/console.c b/src/hakactl/console.c | |
index 0abaa8f..99e7848 100644 | |
--- a/src/hakactl/console.c | |
+++ b/src/hakactl/console.c | |
@@ -32,7 +32,7 @@ bool initialize_console(struct lua_state *state) | |
char *console_path; | |
size_t size; | |
DIR *dir; | |
- struct dirent entry, *result = NULL; | |
+ struct dirent *entry; | |
/* Load all console utilities */ | |
lua_newtable(state->L); | |
@@ -56,37 +56,38 @@ bool initialize_console(struct lua_state *state) | |
return false; | |
} | |
else { | |
- while (!readdir_r(dir, &entry, &result) && result) { | |
- const size_t len = strlen(entry.d_name); | |
+ while ( (entry = readdir(dir)) != NULL ) { | |
+ //while (!readdir(dir, &entry, &result) && result) { | |
+ const size_t len = strlen(entry->d_name); | |
char fullfilename[PATH_MAX]; | |
const int level = lua_gettop(state->L); | |
snprintf(fullfilename, sizeof(fullfilename), "%s/%s", | |
- console_path, entry.d_name); | |
+ console_path, entry->d_name); | |
- if (len > 4 && strcmp(entry.d_name + (len - 4), ".lua") == 0) { | |
- entry.d_name[len - 4] = 0; | |
+ if (len > 4 && strcmp(entry->d_name + (len - 4), ".lua") == 0) { | |
+ entry->d_name[len - 4] = 0; | |
} | |
else if (len > 3 | |
- && strcmp(entry.d_name + (len - 3), ".bc") == 0) { | |
- entry.d_name[len - 3] = 0; | |
+ && strcmp(entry->d_name + (len - 3), ".bc") == 0) { | |
+ entry->d_name[len - 3] = 0; | |
} | |
else { | |
continue; | |
} | |
- LOG_DEBUG(core, "loading console script '%s'", entry.d_name); | |
+ LOG_DEBUG(core, "loading console script '%s'", entry->d_name); | |
if (luaL_dofile(state->L, fullfilename)) { | |
const char *msg = lua_tostring(state->L, -1); | |
LOG_ERROR(core, "cannot open console script '%s': %s", | |
- entry.d_name, msg); | |
+ entry->d_name, msg); | |
lua_pop(state->L, 1); | |
} | |
else { | |
const int res = lua_gettop(state->L) - level; | |
if (res == 1) { | |
- lua_setfield(state->L, -2, entry.d_name); | |
+ lua_setfield(state->L, -2, entry->d_name); | |
} | |
else { | |
lua_pop(state->L, res); | |
-- | |
2.10.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment