[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] readdir_r: now obsolescent

From: Bruno Haible
Subject: Re: [PATCH] readdir_r: now obsolescent
Date: Thu, 11 Feb 2016 02:31:16 +0100
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

Hi Paul,

> +     readdir_r: now obsolescent
> +     * doc/posix-functions/readdir_r.texi (readdir_r): Now obsolescent.

> --- a/doc/posix-functions/readdir_r.texi
> +++ b/doc/posix-functions/readdir_r.texi
> @@ -9,6 +9,9 @@ Gnulib module: extensions
>  Portability problems fixed by Gnulib:
>  @itemize
>  @item
> +This function is planned to be removed from POSIX and to be deprecated
> +in glibc.  Portable applications should use @code{readdir}.

I understand that this came about because of [1] and [2]. But:

What should applications (based on gnulib) use that want to read the
contents of a directory in a portable AND multithread-safe way?

Citing POSIX:2008 [3]:
"The readdir() function need not be thread-safe."

Citing Austin Group #696 [4]:
"Since the new implementation requirements for opendir( ) and closedir( ) have
the net effect of making readdir( ) thread safe, readdir_r( ) is being marked
OBSOLESCENT as superfluous."

Can we assume that all readdir() implementations supported by gnulib are
actually multithread-safe because the pointer they return is in the area
allocated by opendir() [as opposed to a static location]?

A test program could be something like
#include <dirent.h>
#include <stdio.h>

main ()
  DIR *dir1 = opendir (".");
  struct dirent *d1 = readdir (dir1);
  DIR *dir2 = opendir (".");
  DIR *dir3 = opendir (".");
  struct dirent *d2 = readdir (dir2);
  struct dirent *d3 = readdir (dir3);
  return (d1 == d2 || d1 == d3 || d2 == d3);


[1] https://womble.decadent.org.uk/readdir_r-advisory.html
[2] https://bugzilla.redhat.com/show_bug.cgi?id=995839
[3] http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html
[4] http://austingroupbugs.net/view.php?id=696

reply via email to

[Prev in Thread] Current Thread [Next in Thread]