From 7fb538737d4a5d8e086785339fb2933f8a5c18b7 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 6 Mar 2013 20:59:41 +0100 Subject: [PATCH] Fix cppcheck warning "Non reentrant function 'readdir' called" For threadsafe applications it is recommended to use the reentrant replacement function 'readdir_r'. --- libnfc/conf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libnfc/conf.c b/libnfc/conf.c index 7647a52..2ec348b 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -1,3 +1,4 @@ + /*- * Copyright (C) 2012, 2013 Romuald Conty * @@ -15,12 +16,12 @@ * along with this program. If not, see */ -#include "conf.h" - #ifdef HAVE_CONFIG_H # include "config.h" #endif // HAVE_CONFIG_H +#include "conf.h" + #ifdef CONFFILES #include #include @@ -163,7 +164,10 @@ conf_devices_load(const char *dirname, nfc_context *context) log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname); } else { struct dirent *de; - while ((de = readdir(d))) { + struct dirent entry; + struct dirent *result; + while ((readdir_r(d, &entry, &result) == 0) && (result != NULL)) { + de = &entry; if (de->d_name[0] != '.') { const size_t filename_len = strlen(de->d_name); const size_t extension_len = strlen(".conf");