From 0ee67fede81600dad90da5139f6109399d6926e7 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Sat, 3 May 2008 12:34:19 +0300 Subject: Temp file handling tweaks - rename rpmMkTemp() (back) to rpmMkTempFile() - rpmMkTemp() is now a lower level thin wrapper around mkstemp() --- rpmio/rpmfileutil.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'rpmio/rpmfileutil.c') diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index 64510e991..93c5cd52f 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -225,11 +225,27 @@ exit: return rc; } -FD_t rpmMkTemp(const char * prefix, char **fn) +FD_t rpmMkTemp(char *template) +{ + int sfd; + FD_t tfd = NULL; + + sfd = mkstemp(template); + if (sfd < 0) { + goto exit; + } + + tfd = fdDup(sfd); + close(sfd); + +exit: + return tfd; +} + +FD_t rpmMkTempFile(const char * prefix, char **fn) { const char *tpmacro = "%{_tmppath}"; /* always set from rpmrc */ char *tempfn; - int sfd; static int _initialized = 0; FD_t tfd = NULL; @@ -245,16 +261,10 @@ FD_t rpmMkTemp(const char * prefix, char **fn) } tempfn = rpmGetPath(prefix, tpmacro, "/rpm-tmp.XXXXXX", NULL); - sfd = mkstemp(tempfn); - if (sfd < 0) { - rpmlog(RPMLOG_ERR, _("error creating temporary file: %m\n")); - goto exit; - } + tfd = rpmMkTemp(tempfn); - tfd = fdDup(sfd); - close(sfd); if (tfd == NULL || Ferror(tfd)) { - rpmlog(RPMLOG_ERR, _("error opening temporary file %s: %m\n"), tempfn); + rpmlog(RPMLOG_ERR, _("error creating temporary file %s: %m\n"), tempfn); goto exit; } -- cgit v1.2.3