diff --git a/src/http.c b/src/http.c index 9918b34a..686db86f 100644 --- a/src/http.c +++ b/src/http.c @@ -2367,7 +2367,7 @@ check_file_output (const struct url *u, struct http_stat *hs, } else if (!ALLOW_CLOBBER) { - char *unique = unique_name (hs->local_file, true); + char *unique = unique_name_passthrough (hs->local_file); if (unique != hs->local_file) xfree (hs->local_file); hs->local_file = unique; diff --git a/src/metalink.c b/src/metalink.c index e50cc24a..3cf05783 100644 --- a/src/metalink.c +++ b/src/metalink.c @@ -1108,7 +1108,7 @@ badhash_suffix (char *name) char *bhash, *uname; bhash = concat_strings (name, ".badhash", (char *)0); - uname = unique_name (bhash, false); + uname = unique_name (bhash); logprintf (LOG_VERBOSE, _("Renaming %s to %s.\n"), quote_n (0, name), quote_n (1, uname)); diff --git a/src/url.c b/src/url.c index 7dabb123..950002bb 100644 --- a/src/url.c +++ b/src/url.c @@ -1863,7 +1863,7 @@ url_file_name (const struct url *u, char *replaced_filename) } else { - unique = unique_name (fname, true); + unique = unique_name_passthrough (fname); if (unique != fname) xfree (fname); } diff --git a/src/utils.c b/src/utils.c index 433eb298..b7ae4437 100644 --- a/src/utils.c +++ b/src/utils.c @@ -686,21 +686,27 @@ unique_name_1 (const char *prefix) by this function exists until you open it with O_EXCL or equivalent. - If ALLOW_PASSTHROUGH is 0, it always returns a freshly allocated - string. Otherwise, it may return FILE if the file doesn't exist + unique_name() always returns a freshly allocated string. + + unique_name_passthrough() may return FILE if the file doesn't exist (and therefore doesn't need changing). */ char * -unique_name (const char *file, bool allow_passthrough) +unique_name_passthrough (const char *file) { /* If the FILE itself doesn't exist, return it without - modification. */ - if (!file_exists_p (file, NULL)) - return allow_passthrough ? (char *)file : xstrdup (file); + modification. Otherwise, find a numeric suffix that results in unused + file name and return it. */ + return file_exists_p (file, NULL) ? unique_name_1 (file) : (char *) file; +} - /* Otherwise, find a numeric suffix that results in unused file name - and return it. */ - return unique_name_1 (file); +char * +unique_name (const char *file) +{ + /* If the FILE itself doesn't exist, return it without + modification. Otherwise, find a numeric suffix that results in unused + file name and return it. */ + return file_exists_p (file, NULL) ? unique_name_1 (file) : xstrdup (file); } #else /* def UNIQ_SEP */ @@ -709,10 +715,17 @@ unique_name (const char *file, bool allow_passthrough) possible. */ char * -unique_name (const char *file, bool allow_passthrough) +unique_name_passthrough (const char *file, bool allow_passthrough) { /* Return the FILE itself, without modification, irregardful. */ - return allow_passthrough ? (char *)file : xstrdup (file); + return (char *) file); +} +char * + +unique_name (const char *file) +{ + /* Return the FILE itself, without modification, irregardful. */ + return xstrdup (file); } #endif /* def UNIQ_SEP [else] */ @@ -726,12 +739,12 @@ FILE * unique_create (const char *name, bool binary, char **opened_name) { /* unique file name, based on NAME */ - char *uname = unique_name (name, false); + char *uname = unique_name (name); FILE *fp; while ((fp = fopen_excl (uname, binary)) == NULL && errno == EEXIST) { xfree (uname); - uname = unique_name (name, false); + uname = unique_name (name); } if (opened_name) { diff --git a/src/utils.h b/src/utils.h index 64ad198f..df3683ce 100644 --- a/src/utils.h +++ b/src/utils.h @@ -88,7 +88,8 @@ bool file_exists_p (const char *, file_stats_t *); bool file_non_directory_p (const char *); wgint file_size (const char *); int make_directory (const char *); -char *unique_name (const char *, bool); +char *unique_name_passthrough (const char *); +char *unique_name (const char *); FILE *unique_create (const char *, bool, char **); FILE *fopen_excl (const char *, int); FILE *fopen_stat (const char *, const char *, file_stats_t *);