Mercurial > hg > octave-lyh > gnulib-hg
changeset 13670:a930c356f503
savedir: add streamsavedir, deprecate fdsavedir
* NEWS: Mention deprecation of fdsavedir.
* lib/savedir.c (streamsavedir): New extern function, whose name
ends in "savedir" to be consistent with the others. This differs
from savedirstream in that it doesn't close its argument. The
next version of GNU tar will use this instead of fdsavedir, to
avoid some race conditions and conserve file descriptors.
(savedirstream): Reimplement as a wrapper around streamsavedir.
(fdsavedir): Add a comment deprecating this function. As far as
I know, only GNU tar used it, and GNU tar doesn't need it any more.
* lib/savedir.h (streamsavedir): New decl.
(fdsavedir): Add a comment deprecating this.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 12 Sep 2010 14:21:52 -0700 |
parents | c44f2f1aa276 |
children | 228e72ae2254 |
files | ChangeLog NEWS lib/savedir.c lib/savedir.h |
diffstat | 4 files changed, 42 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-09-12 Paul Eggert <eggert@cs.ucla.edu> + + savedir: add streamsavedir, deprecate fdsavedir + * NEWS: Mention deprecation of fdsavedir. + * lib/savedir.c (streamsavedir): New extern function, whose name + ends in "savedir" to be consistent with the others. This differs + from savedirstream in that it doesn't close its argument. The + next version of GNU tar will use this instead of fdsavedir, to + avoid some race conditions and conserve file descriptors. + (savedirstream): Reimplement as a wrapper around streamsavedir. + (fdsavedir): Add a comment deprecating this function. As far as + I know, only GNU tar used it, and GNU tar doesn't need it any more. + * lib/savedir.h (streamsavedir): New decl. + (fdsavedir): Add a comment deprecating this. + 2010-09-10 Bruno Haible <bruno@clisp.org> langinfo: Fix last commit.
--- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ Date Modules Changes +2010-09-12 savedir The fdsavedir function is now deprecated. + 2010-09-10 fcntl-h This module now defaults O_CLOEXEC to 0, and it defaults O_EXEC and O_SEARCH to O_RDONLY. Use "#if O_CLOEXEC" instead of "#ifdef O_CLOEXEC".
--- a/lib/savedir.c +++ b/lib/savedir.c @@ -44,11 +44,11 @@ /* Return a freshly allocated string containing the file names in directory DIRP, separated by '\0' characters; the end is marked by two '\0' characters in a row. - Return NULL (setting errno) if DIRP cannot be read or closed. + Return NULL (setting errno) if DIRP cannot be read. If DIRP is NULL, return NULL without affecting errno. */ -static char * -savedirstream (DIR *dirp) +char * +streamsavedir (DIR *dirp) { char *name_space; size_t allocated = NAME_SIZE_DEFAULT; @@ -96,8 +96,6 @@ } name_space[used] = '\0'; save_errno = errno; - if (closedir (dirp) != 0) - save_errno = errno; if (save_errno != 0) { free (name_space); @@ -107,6 +105,22 @@ return name_space; } +/* Like savedirstreamp (DIRP), except also close DIRP. */ + +static char * +savedirstream (DIR *dirp) +{ + char *name_space = streamsavedir (dirp); + if (dirp && closedir (dirp) != 0) + { + int save_errno = errno; + free (name_space); + errno = save_errno; + return NULL; + } + return name_space; +} + /* Return a freshly allocated string containing the file names in directory DIR, separated by '\0' characters; the end is marked by two '\0' characters in a row. @@ -123,6 +137,7 @@ the end is marked by two '\0' characters in a row. Return NULL (setting errno) if FD cannot be read or closed. */ +/* deprecated */ char * fdsavedir (int fd) {
--- a/lib/savedir.h +++ b/lib/savedir.h @@ -18,10 +18,12 @@ /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ -#if !defined SAVEDIR_H_ -# define SAVEDIR_H_ +#ifndef _GL_SAVEDIR_H +#define _GL_SAVEDIR_H +#include <dirent.h> +char *streamsavedir (DIR *dirp); char *savedir (char const *dir); -char *fdsavedir (int fd); +char *fdsavedir (int fd); /* deprecated */ #endif