summaryrefslogtreecommitdiff
path: root/lib/savedir.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-01-10 17:47:56 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-01-10 17:47:56 +0000
commitd11af4159eb8836696ef29f1e1ac9ad4db348d47 (patch)
tree87dc9cf5d37eebdd601ef33b9925bfb955ff87ff /lib/savedir.c
parent71520b31c09c843d37c84abd12694e06428cdd47 (diff)
downloadcoreutils-d11af4159eb8836696ef29f1e1ac9ad4db348d47.tar.xz
Sync from gnulib.
Diffstat (limited to 'lib/savedir.c')
-rw-r--r--lib/savedir.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/savedir.c b/lib/savedir.c
index 86930eb56..b08f32b79 100644
--- a/lib/savedir.c
+++ b/lib/savedir.c
@@ -55,27 +55,27 @@
#include <stdlib.h>
#include <string.h>
+#include "openat.h"
#include "xalloc.h"
-/* 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.
- Return NULL (setting errno) if DIR cannot be opened, read, or closed. */
-
#ifndef NAME_SIZE_DEFAULT
# define NAME_SIZE_DEFAULT 512
#endif
-char *
-savedir (const char *dir)
+/* 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.
+ If DIRP is NULL, return NULL without affecting errno. */
+
+static char *
+savedirstream (DIR *dirp)
{
- DIR *dirp;
char *name_space;
size_t allocated = NAME_SIZE_DEFAULT;
size_t used = 0;
int save_errno;
- dirp = opendir (dir);
if (dirp == NULL)
return NULL;
@@ -127,3 +127,25 @@ savedir (const char *dir)
}
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.
+ Return NULL (setting errno) if DIR cannot be opened, read, or closed. */
+
+char *
+savedir (char const *dir)
+{
+ return savedirstream (opendir (dir));
+}
+
+/* Return a freshly allocated string containing the file names
+ in directory FD, separated by '\0' characters;
+ the end is marked by two '\0' characters in a row.
+ Return NULL (setting errno) if FD cannot be read or closed. */
+
+char *
+fdsavedir (int fd)
+{
+ return savedirstream (fdopendir (fd));
+}