summaryrefslogtreecommitdiff
path: root/lib/savedir.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2010-09-12 14:21:52 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2010-09-12 14:22:53 -0700
commitcd3df4488a72cb4dd3b490a8d8087d0130e64ff1 (patch)
tree0becd08ab8ece0d16ede7e6d1fc86cd45dfbadf1 /lib/savedir.c
parentb7dcc1aa0db4485c142f08d42d1c41cbe7054da2 (diff)
downloadgnulib-cd3df4488a72cb4dd3b490a8d8087d0130e64ff1.tar.gz
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.
Diffstat (limited to 'lib/savedir.c')
-rw-r--r--lib/savedir.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/savedir.c b/lib/savedir.c
index 538f397cb6..79d2fd0ff1 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)
{