Skip to content

Commit

Permalink
readdir_r(3) is deprecated, use readdir(3) instead
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Ross Zwisler committed Apr 5, 2018
1 parent 11cd558 commit b407601
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand All @@ -155,8 +155,10 @@ static int affinity_file(struct bitmask *mask, char *cls, const char *file)
cls);
return -1;
}
while (readdir_r(dir, &de, &dep) == 0 && dep) {
while ((dep = readdir(dir)) != NULL) {
char *name = dep->d_name;
int ret;

if (*name == '.')
continue;
char *dev;
Expand All @@ -179,8 +181,9 @@ static int affinity_file(struct bitmask *mask, char *cls, const char *file)
if (major(d) != maj || minor(d) != min)
continue;

ret = affinity_class(mask, "block", name);
closedir(dir);
return affinity_class(mask, "block", name);
return ret;
}
closedir(dir);
numa_warn(W_blockdev5, "Cannot find block device %x:%x in sysfs for `%s'",
Expand Down

0 comments on commit b407601

Please sign in to comment.