diff options
Diffstat (limited to 'lib/fileutils.c')
-rw-r--r-- | lib/fileutils.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/fileutils.c b/lib/fileutils.c index 819298935..4849061bb 100644 --- a/lib/fileutils.c +++ b/lib/fileutils.c @@ -8,38 +8,35 @@ #include <unistd.h> #include "c.h" +#include "fileutils.h" #include "pathnames.h" #include "xalloc.h" /* Create open temporary file in safe way. Please notice that the * file permissions are -rw------- by default. */ -FILE *xmkstemp(char **tmpname) +int xmkstemp(char **tmpname) { char *localtmp; char *tmpenv; mode_t old_mode; int fd; - FILE *ret; tmpenv = getenv("TMPDIR"); if (tmpenv) xasprintf(&localtmp, "%s/%s.XXXXXX", tmpenv, - program_invocation_short_name); + program_invocation_short_name); else xasprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP, - program_invocation_short_name); + program_invocation_short_name); old_mode = umask(077); fd = mkstemp(localtmp); umask(old_mode); - if (fd == -1) - return NULL; - if (!(ret = fdopen(fd, "w+"))) - goto err; + if (fd == -1) { + free(localtmp); + localtmp = NULL; + } *tmpname = localtmp; - return ret; - err: - close(fd); - return NULL; + return fd; } #ifdef TEST_PROGRAM @@ -47,7 +44,7 @@ int main(void) { FILE *f; char *tmpname; - f = xmkstemp(&tmpname); + f = xfmkstemp(&tmpname); unlink(tmpname); free(tmpname); fclose(f); |