From 815f652f0835b62d799accdfb6a13f0d710f5a05 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 4 Apr 2013 12:57:44 +0200 Subject: [PATCH] Move tmpname generation to utility function c_tmpname for cleander code. --- src/csync_propagate.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/csync_propagate.c b/src/csync_propagate.c index 848301da80..55341eea29 100644 --- a/src/csync_propagate.c +++ b/src/csync_propagate.c @@ -240,30 +240,9 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) { } /* create the temporary file name */ -#ifdef _WIN32 - if (asprintf(&turi, "%s.~XXXXXX", duri) < 0) { -#else - /* split up the path */ - if(duri) { - char *path = c_dirname(duri); - char *base = c_basename(duri); + turi = c_tmpname(duri); - if( path ) { - re = asprintf(&turi, "%s/.%s.~XXXXXX", path, base); - } else { - re = asprintf(&turi,".%s.~XXXXXX", base); - } - SAFE_FREE(path); - SAFE_FREE(base); - } - if (re < 0) { -#endif - rc = -1; - goto out; - } - - /* We just want a random file name here, open checks if the file exists. */ - if (c_tmpname(turi) < 0) { + if (!turi) { rc = -1; goto out; } @@ -296,7 +275,9 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) { goto out; } if(_push_to_tmp_first(ctx)) { - if (c_tmpname(turi) < 0) { + SAFE_FREE(turi); + turi = c_tmpname(duri); + if (!turi) { rc = -1; goto out; }