bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] savedir: add streamsavedir, deprecate fdsavedir


From: Paul Eggert
Subject: [PATCH] savedir: add streamsavedir, deprecate fdsavedir
Date: Sun, 12 Sep 2010 14:24:52 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100826 Thunderbird/3.0.7

I installed the following into gnulib, as part of my campaign
to put GNU tar on a file descriptor diet.  Is anyone besides
tar using fdsavedir?  If not, I'd like to remove it from gnulib.

* 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.
---
 ChangeLog     |   15 +++++++++++++++
 NEWS          |    2 ++
 lib/savedir.c |   25 ++++++++++++++++++++-----
 lib/savedir.h |    8 +++++---
 4 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bdce4a3..8e6c3c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-09-12  Paul Eggert  <address@hidden>
+
+       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  <address@hidden>
 
        langinfo: Fix last commit.
diff --git a/NEWS b/NEWS
index c23c316..6311533 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 538f397..79d2fd0 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 fb11f90..5a57fe3 100644
--- a/lib/savedir.h
+++ b/lib/savedir.h
@@ -18,10 +18,12 @@
 
 /* Written by David MacKenzie <address@hidden>. */
 
-#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
-- 
1.7.2




reply via email to

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