diff options
author | Karel Zak <kzak@redhat.com> | 2014-06-18 12:57:42 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2014-06-18 12:57:42 +0200 |
commit | f272b32c57dcfd440f01c2eae119dce1aea5611e (patch) | |
tree | d9d814f7e719aee08d70b41d6a67bfd369684399 /lib/fileutils.c | |
parent | 65322517eb6961b16a7d833332cfdae18c0dcf03 (diff) | |
download | util-linux-f272b32c57dcfd440f01c2eae119dce1aea5611e.tar.gz |
lib/fileutils: xalloc stuff in library-like code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/fileutils.c')
-rw-r--r-- | lib/fileutils.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/fileutils.c b/lib/fileutils.c index a1b475757..bffa8ff34 100644 --- a/lib/fileutils.c +++ b/lib/fileutils.c @@ -12,7 +12,6 @@ #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. */ @@ -21,7 +20,7 @@ int xmkstemp(char **tmpname, char *dir) char *localtmp; char *tmpenv; mode_t old_mode; - int fd; + int fd, rc; /* Some use cases must be capable of being moved atomically * with rename(2), which is the reason why dir is here. */ @@ -31,11 +30,15 @@ int xmkstemp(char **tmpname, char *dir) tmpenv = getenv("TMPDIR"); if (tmpenv) - xasprintf(&localtmp, "%s/%s.XXXXXX", tmpenv, + rc = asprintf(&localtmp, "%s/%s.XXXXXX", tmpenv, program_invocation_short_name); else - xasprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP, + rc = asprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP, program_invocation_short_name); + + if (rc < 0) + return -1; + old_mode = umask(077); fd = mkostemp(localtmp, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC); umask(old_mode); |