From d11af4159eb8836696ef29f1e1ac9ad4db348d47 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 10 Jan 2006 17:47:56 +0000 Subject: Sync from gnulib. --- lib/savedir.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'lib/savedir.c') 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 #include +#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)); +} -- cgit v1.2.3-54-g00ecf