]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/fileutils: xalloc stuff in library-like code
authorKarel Zak <kzak@redhat.com>
Wed, 18 Jun 2014 10:57:42 +0000 (12:57 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 18 Jun 2014 10:57:42 +0000 (12:57 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/fileutils.h
lib/fileutils.c

index 2144e5e5df1fdb2b88389212277f483b281330c4..98798f7ee9f0d2123b3a837e980c77f07687b338 100644 (file)
@@ -7,10 +7,11 @@ static inline FILE *xfmkstemp(char **tmpname, char *dir)
 {
        int fd;
        FILE *ret;
+
        fd = xmkstemp(tmpname, dir);
-       if (fd == -1) {
+       if (fd == -1)
                return NULL;
-       }
+
        if (!(ret = fdopen(fd, "w+" UL_CLOEXECSTR))) {
                close(fd);
                return NULL;
index a1b47575783fb979cac629dd3da18303930afe31..bffa8ff34c19810a623a1e92996b2146778648fa 100644 (file)
@@ -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);