#include "find-mount-point.h"
#include "hash.h"
#include "xstrtol-error.h"
+#include "xvasprintf.h"
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "df"
for (col = 0; col < ncolumns; col++)
{
- char *cell = nullptr;
+ char *cell;
char const *header = _(columns[col]->caption);
if (columns[col]->field == SIZE_FIELD
header = _("blocks");
/* TRANSLATORS: this is the "1K-blocks" header in "df" output. */
- if (asprintf (&cell, _("%s-%s"), num, header) == -1)
- cell = nullptr;
+ cell = xasprintf (_("%s-%s"), num, header);
}
else if (header_mode == POSIX_MODE && columns[col]->field == SIZE_FIELD)
{
char *num = umaxtostr (output_block_size, buf);
/* TRANSLATORS: this is the "1024-blocks" header in "df -P". */
- if (asprintf (&cell, _("%s-%s"), num, header) == -1)
- cell = nullptr;
+ cell = xasprintf (_("%s-%s"), num, header);
}
else
- cell = strdup (header);
-
- if (!cell)
- xalloc_die ();
+ cell = xstrdup (header);
replace_problematic_chars (cell);
}
}
- if (0 <= pct)
- {
- if (asprintf (&cell, "%.0f%%", pct) == -1)
- cell = nullptr;
- }
- else
- cell = strdup ("-");
-
- if (!cell)
- xalloc_die ();
-
+ cell = pct < 0 ? xstrdup ("-") : xasprintf ("%.0f%%", pct);
break;
}