nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Ross Zwisler <ross.zwisler@linux.intel.com>
To: Andi Kleen <ak@linux.intel.com>, linux-nvdimm@lists.01.org
Subject: [PATCH 2/3] readdir_r(3) is deprecated, use readdir(3) instead
Date: Thu, 22 Mar 2018 12:33:21 -0600	[thread overview]
Message-ID: <20180322183322.23076-2-ross.zwisler@linux.intel.com> (raw)
In-Reply-To: <20180322183322.23076-1-ross.zwisler@linux.intel.com>

gcc 7.3.1 provides the following warning when compiling affinity.c:

affinity.c: In function ‘affinity_file’:
affinity.c:158:2: warning: ‘readdir_r’ is deprecated [-Wdeprecated-declarations]
  while (readdir_r(dir, &de, &dep) == 0 && dep) {
In file included from affinity.c:39:0:
/usr/include/dirent.h:183:12: note: declared here
 extern int readdir_r (DIR *__restrict __dirp,

According to the man page for readdir_r(3), calls this function should be
fixed to instead use readdir(3).

One interesting note: I had to move the affinity_class() call above the
closedir(dir) call in affinity_file() because with readdir(3) the string
stored in 'name' is cleared on closedir().  This doesn't happen with
readdir_r() for some reason.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
 affinity.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/affinity.c b/affinity.c
index 85597fc..06784f7 100644
--- a/affinity.c
+++ b/affinity.c
@@ -131,7 +131,7 @@ static int affinity_file(struct bitmask *mask, char *cls, const char *file)
 	int n;
 	unsigned maj = 0, min = 0;
 	dev_t d;
-	struct dirent de, *dep;
+	struct dirent *dep;
 	cls = "block";
 	char fn[sizeof("/sys/class/") + strlen(cls)];
@@ -155,8 +155,10 @@ static int affinity_file(struct bitmask *mask, char *cls, const char *file)
 		return -1;
-	while (readdir_r(dir, &de, &dep) == 0 && dep) {
+	while ((dep = readdir(dir)) != NULL) {
 		char *name = dep->d_name;
+		int ret;
 		if (*name == '.')
 		char *dev;
@@ -179,8 +181,9 @@ static int affinity_file(struct bitmask *mask, char *cls, const char *file)
 		if (major(d) != maj || minor(d) != min)
+		ret = affinity_class(mask, "block", name);
-		return affinity_class(mask, "block", name);
+		return ret;
 	numa_warn(W_blockdev5, "Cannot find block device %x:%x in sysfs for `%s'",

Linux-nvdimm mailing list

  reply	other threads:[~2018-03-22 18:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-22 18:33 [PATCH 1/3] Avoid filename truncation in numastat Ross Zwisler
2018-03-22 18:33 ` Ross Zwisler [this message]
2018-03-22 18:33 ` [PATCH 3/3] Add pkg-config file for NUMA library Ross Zwisler
2018-04-05 15:01 ` [PATCH 1/3] Avoid filename truncation in numastat Ross Zwisler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180322183322.23076-2-ross.zwisler@linux.intel.com \
    --to=ross.zwisler@linux.intel.com \
    --cc=ak@linux.intel.com \
    --cc=linux-nvdimm@lists.01.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).