diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-11-29 18:47:35 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-11-29 18:47:35 +0000 |
commit | 0e54d613ae73baae389f82279958af959c746290 (patch) | |
tree | 40e0ca02a7912a34fdebc8384c62e018fc7a0bc6 /lib/savedir.c | |
parent | 9e9e0e34e6cf93309e562335ae663be4784bd76a (diff) | |
download | gnulib-0e54d613ae73baae389f82279958af959c746290.tar.gz |
* modules/savedir (Depends-on): Add openat.
* lib/savedir.h (fdsavedir): New decl.
* lib/savedir.c (fdsavedir, savedirstream): New functions; the latter
contains most of the former guts of savedir.
(savedir): Use savedirstream.
Include "openat.h".
Diffstat (limited to 'lib/savedir.c')
-rw-r--r-- | lib/savedir.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/savedir.c b/lib/savedir.c index 86930eb569..b08f32b791 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)); +} |