From: Paul Eggert Date: Sun, 12 Sep 2010 21:21:52 +0000 (-0700) Subject: savedir: add streamsavedir, deprecate fdsavedir X-Git-Tag: v0.1~3817 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=cd3df4488a72cb4dd3b490a8d8087d0130e64ff1;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index bdce4a3c0..8e6c3c23b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-09-12 Paul Eggert + + 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 langinfo: Fix last commit. diff --git a/NEWS b/NEWS index c23c316a6..6311533e0 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ User visible incompatible changes 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". diff --git a/lib/savedir.c b/lib/savedir.c index 538f397cb..79d2fd0ff 100644 --- 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 @@ savedirstream (DIR *dirp) } 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 @@ savedirstream (DIR *dirp) 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 @@ savedir (char const *dir) 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) { diff --git a/lib/savedir.h b/lib/savedir.h index fb11f90b1..5a57fe3e6 100644 --- a/lib/savedir.h +++ b/lib/savedir.h @@ -18,10 +18,12 @@ /* Written by David MacKenzie . */ -#if !defined SAVEDIR_H_ -# define SAVEDIR_H_ +#ifndef _GL_SAVEDIR_H +#define _GL_SAVEDIR_H +#include +char *streamsavedir (DIR *dirp); char *savedir (char const *dir); -char *fdsavedir (int fd); +char *fdsavedir (int fd); /* deprecated */ #endif