X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmisc.c;h=d68d80656c8d76f25c117b073c9e71e9e62785e5;hb=738fb9c2f44eee567bb60e22dc011bdfd2f362a8;hp=e1731447585a092bd57a3863f13c2955280805ac;hpb=cd7bdd4076ca154575bbef85eb2157e59befcfe2;p=chaz%2Ftar diff --git a/src/misc.c b/src/misc.c index e173144..d68d806 100644 --- a/src/misc.c +++ b/src/misc.c @@ -332,7 +332,7 @@ replace_prefix (char **pname, const char *samp, size_t slen, the range MINVAL .. -1, represent it with a string representation of the negative integer, using leading '-'. */ #if ! (INTMAX_MAX <= UINTMAX_MAX / 2) -# error "strtosysint accepts uintmax_t to represent intmax_t" +# error "sysinttostr: uintmax_t cannot represent all intmax_t values" #endif char * sysinttostr (uintmax_t value, intmax_t minval, uintmax_t maxval, @@ -361,7 +361,7 @@ sysinttostr (uintmax_t value, intmax_t minval, uintmax_t maxval, On conversion error, return 0 and set errno = EINVAL. On overflow, return an extreme value and set errno = ERANGE. */ #if ! (INTMAX_MAX <= UINTMAX_MAX) -# error "strtosysint accepts uintmax_t to represent nonnegative intmax_t" +# error "strtosysint: nonnegative intmax_t does not fit in uintmax_t" #endif intmax_t strtosysint (char const *arg, char **arglim, intmax_t minval, uintmax_t maxval) @@ -631,7 +631,7 @@ remove_any_file (const char *file_name, enum remove_option option) case RECURSIVE_REMOVE_OPTION: { - char *directory = savedir (file_name); + char *directory = tar_savedir (file_name, 0); char const *entry; size_t entrylen; @@ -1144,3 +1144,31 @@ namebuf_name (namebuf_t buf, const char *name) strcpy (buf->buffer + buf->dir_length, name); return buf->buffer; } + +/* Return the filenames in directory NAME, relative to the chdir_fd. + If the directory does not exist, report error if MUST_EXIST is + true. + + Return NULL on errors. +*/ +char * +tar_savedir (const char *name, int must_exist) +{ + char *ret = NULL; + DIR *dir = NULL; + int fd = openat (chdir_fd, name, open_read_flags | O_DIRECTORY); + if (fd < 0) + { + if (!must_exist && errno == ENOENT) + return NULL; + open_error (name); + } + else if (! ((dir = fdopendir (fd)) + && (ret = streamsavedir (dir)))) + savedir_error (name); + + if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0) + savedir_error (name); + + return ret; +}