]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
xalloc: use xasprintf in all files
authorSami Kerola <kerolasa@iki.fi>
Wed, 29 Feb 2012 14:54:24 +0000 (15:54 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 18 Mar 2012 13:28:05 +0000 (14:28 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/fsck.cramfs.c
lib/fileutils.c
misc-utils/findmnt.c
misc-utils/lsblk.c
misc-utils/namei.c
partx/partx.c
sys-utils/lscpu.c
sys-utils/mount.c
sys-utils/prlimit.c

index eab44f30ad98263d9076d4c3981cc39c5f31bbb3..465e11594102cc0833a2cfefd2ccca1ce1fae209 100644 (file)
@@ -530,7 +530,7 @@ static void do_symlink(char *path, struct cramfs_inode *i)
        if (opt_verbose) {
                char *str;
 
-               asprintf(&str, "%s -> %s", path, outbuffer);
+               xasprintf(&str, "%s -> %s", path, outbuffer);
                print_node('l', i, str);
                if (opt_verbose > 1)
                        printf(_("  uncompressing block at %ld to %ld (%ld)\n"),
index ed97967a3b68eddf72a09217506e86f6a321d3c3..81929893584e5dd5ea692d1356563780f32d47a6 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "c.h"
 #include "pathnames.h"
+#include "xalloc.h"
 
 /* Create open temporary file in safe way.  Please notice that the
  * file permissions are -rw------- by default. */
@@ -22,10 +23,10 @@ FILE *xmkstemp(char **tmpname)
 
        tmpenv = getenv("TMPDIR");
        if (tmpenv)
-               asprintf(&localtmp, "%s/%s.XXXXXX", tmpenv,
+               xasprintf(&localtmp, "%s/%s.XXXXXX", tmpenv,
                         program_invocation_short_name);
        else
-               asprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP,
+               xasprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP,
                         program_invocation_short_name);
        old_mode = umask(077);
        fd = mkstemp(localtmp);
index 77897d3bad34ec9291c7b58aa54477481784f46a..2df79a4cbbf91c2764b49f81a2bf873b5ff752a1 100644 (file)
@@ -38,6 +38,7 @@
 #include "c.h"
 #include "tt.h"
 #include "strutils.h"
+#include "xalloc.h"
 
 /* flags */
 enum {
@@ -305,7 +306,7 @@ static const char *get_data(struct libmnt_fs *fs, int num)
                if (root && str && !(flags & FL_NOFSROOT) && strcmp(root, "/")) {
                        char *tmp;
 
-                       if (asprintf(&tmp, "%s[%s]", str, root) > 0)
+                       if (xasprintf(&tmp, "%s[%s]", str, root) > 0)
                                str = tmp;
                }
                break;
@@ -338,10 +339,10 @@ static const char *get_data(struct libmnt_fs *fs, int num)
                        char *tmp;
                        int rc = 0;
                        if ((tt_flags & TT_FL_RAW) || (tt_flags & TT_FL_EXPORT))
-                               rc = asprintf(&tmp, "%u:%u",
+                               rc = xasprintf(&tmp, "%u:%u",
                                              major(devno), minor(devno));
                        else
-                               rc = asprintf(&tmp, "%3u:%-3u",
+                               rc = xasprintf(&tmp, "%3u:%-3u",
                                              major(devno), minor(devno));
                        if (rc)
                                str = tmp;
index 4709aaaae087e398203cdcdb4bad6b997ac632fd..9c0be27493c9e125689b509505698251a0ffe957 100644 (file)
@@ -604,7 +604,7 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
        case COL_SIZE:
                if (cxt->size) {
                        if (lsblk->bytes) {
-                               if (asprintf(&p, "%jd", cxt->size) < 0)
+                               if (xasprintf(&p, "%jd", cxt->size) < 0)
                                        p = NULL;
                        } else
                                p = size_to_human_string(SIZE_SUFFIX_1LETTER, cxt->size);
index 3c2e7fc31031f9a56da887273f2c6d971fc1adc6..e53b4c9a475655ec8b5dbb5b34092e32d5ca42df 100644 (file)
@@ -123,7 +123,7 @@ add_id(struct idcache **ic, char *name, unsigned long int id, int *width)
        /* note, we ignore names with non-printable widechars */
        if (w > 0)
                nc->name = xstrdup(name);
-       else if (asprintf(&nc->name, "%lu", id) == -1)
+       else if (xasprintf(&nc->name, "%lu", id) == -1)
                nc->name = NULL;
 
        for (x = *ic; x && x->next; x = x->next);
index e5f4319c898d5b0ab05b111b1fb2306a6a6f5803..ddce6fe4e461e175fd7523101e33bb0b212f7ba5 100644 (file)
@@ -445,25 +445,25 @@ static void add_tt_line(struct tt *tt, blkid_partition par)
 
                switch (get_column_id(i)) {
                case COL_PARTNO:
-                       rc = asprintf(&str, "%d",
+                       rc = xasprintf(&str, "%d",
                                        blkid_partition_get_partno(par));
                        break;
                case COL_START:
-                       rc = asprintf(&str, "%ju",
+                       rc = xasprintf(&str, "%ju",
                                        blkid_partition_get_start(par));
                        break;
                case COL_END:
-                       rc = asprintf(&str, "%ju",
+                       rc = xasprintf(&str, "%ju",
                                        blkid_partition_get_start(par) +
                                        blkid_partition_get_size(par) - 1);
                        break;
                case COL_SECTORS:
-                       rc = asprintf(&str, "%ju",
+                       rc = xasprintf(&str, "%ju",
                                        blkid_partition_get_size(par));
                        break;
                case COL_SIZE:
                        if (partx_flags & FL_BYTES)
-                               rc = asprintf(&str, "%ju", (uintmax_t)
+                               rc = xasprintf(&str, "%ju", (uintmax_t)
                                        blkid_partition_get_size(par) << 9);
                        else
                                str = size_to_human_string(SIZE_SUFFIX_1LETTER,
@@ -484,11 +484,11 @@ static void add_tt_line(struct tt *tt, blkid_partition par)
                        if (str)
                                str = xstrdup(str);
                        else
-                               rc = asprintf(&str, "0x%x",
+                               rc = xasprintf(&str, "0x%x",
                                        blkid_partition_get_type(par));
                        break;
                case COL_FLAGS:
-                       rc = asprintf(&str, "0x%llx", blkid_partition_get_flags(par));
+                       rc = xasprintf(&str, "0x%llx", blkid_partition_get_flags(par));
                        break;
                case COL_SCHEME:
                {
index 3cdd767041c2771937eb459ae9e47aeae1832b99..6e17b2eb55db4df795a57bebd91512c370ea8812 100644 (file)
@@ -543,7 +543,7 @@ read_hypervisor(struct lscpu_desc *desc)
                        str = strchr(buf, ':');
                        if (!str)
                                continue;
-                       if (asprintf(&str, "%s", str + 1) == -1)
+                       if (xasprintf(&str, "%s", str + 1) == -1)
                                errx(EXIT_FAILURE, _("failed to allocate memory"));
                        /* remove leading, trailing and repeating whitespace */
                        while (*str == ' ')
index 69f536b47dac3ab5cdca69d89a45b52b0e3c4dd6..b1a0390d6f4321daf19af1e1c3182ff3e0ec396a 100644 (file)
@@ -769,7 +769,7 @@ int main(int argc, char **argv)
                case 'U':
                        if (source)
                                errx(MOUNT_EX_USAGE, _("only one <source> may be specified"));
-                       if (asprintf(&srcbuf, "%s=\"%s\"",
+                       if (xasprintf(&srcbuf, "%s=\"%s\"",
                                     c == 'L' ? "LABEL" : "UUID", optarg) <= 0)
                                err(MOUNT_EX_SYSERR, _("failed to allocate source buffer"));
                        source = srcbuf;
index a446187ffebe0dab76f9190f20b2d6f3506698f9..c45b85efbf87c4ad7ee700391896191934604c15 100644 (file)
@@ -228,20 +228,20 @@ static void add_tt_line(struct tt *tt, struct prlimit *l)
 
                switch (get_column_id(i)) {
                case COL_RES:
-                       rc = asprintf(&str, "%s", l->desc->name);
+                       rc = xasprintf(&str, "%s", l->desc->name);
                        break;
                case COL_HELP:
-                       rc = asprintf(&str, "%s", l->desc->help);
+                       rc = xasprintf(&str, "%s", l->desc->help);
                        break;
                case COL_SOFT:
                        rc = l->rlim.rlim_cur == RLIM_INFINITY ?
-                               asprintf(&str, "%s", "unlimited") :
-                               asprintf(&str, "%llu", (unsigned long long) l->rlim.rlim_cur);
+                               xasprintf(&str, "%s", "unlimited") :
+                               xasprintf(&str, "%llu", (unsigned long long) l->rlim.rlim_cur);
                        break;
                case COL_HARD:
                        rc = l->rlim.rlim_max == RLIM_INFINITY ?
-                               asprintf(&str, "%s", "unlimited") :
-                               asprintf(&str, "%llu", (unsigned long long) l->rlim.rlim_max);
+                               xasprintf(&str, "%s", "unlimited") :
+                               xasprintf(&str, "%llu", (unsigned long long) l->rlim.rlim_max);
                        break;
                case COL_UNITS:
                        str = l->desc->unit ? xstrdup(_(l->desc->unit)) : NULL;