#include "c.h"
#include "nls.h"
+#include "xalloc.h"
#include "blkdev.h"
#include "linux_version.h"
#include "common.h"
va_end(p);
}
-static void
-fatal(char *s, ...) {
- va_list p;
-
- va_start(p, s);
- fflush(stdout);
- fprintf(stderr, "\n" PROGNAME ": ");
- vfprintf(stderr, s, p);
- fflush(stderr);
- va_end(p);
- exit(1);
-}
-
/*
* arm needs PACKED - use it everywhere?
*/
if (!sseek(dev, fd, sno))
return 0;
- if (!(s = (struct sector *)malloc(sizeof(struct sector))))
- fatal(_("out of memory - giving up\n"));
+ s = xmalloc(sizeof(struct sector));
if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
if (errno) /* 0 in case we read past end-of-disk */
pno = linux_to_index(pnum, z);
}
if (!(pno >= 0 && pno < z->partno))
- fatal(_("%s: no such partition\n"), pnam);
+ errx(EXIT_FAILURE, _("%s: no such partition\n"), pnam);
return pno;
}
/* Have at least 4 partitions been defined? */
if (partno < 4) {
if (!partno)
- fatal(_("no partition table present.\n"));
+ errx(EXIT_FAILURE, _("no partition table present."));
else
- fatal(_("strange, only %d partitions defined.\n"), partno);
+ errx(EXIT_FAILURE, _("strange, only %d partitions defined."), partno);
return 0;
}
}
if (save_sector_file) {
if (!save_sectors(dev, fd)) {
- fatal(_("Failed saving the old sectors - aborting\n"));
+ errx(EXIT_FAILURE, _("Failed saving the old sectors - aborting\n"));
return 0;
}
}
return RD_EOF;
}
if (!(lp = strchr(lp, '\n')))
- fatal(_("long or incomplete input line - quitting\n"));
+ errx(EXIT_FAILURE, _("long or incomplete input line - quitting"));
*lp = 0;
/* remove comments, if any */
while (isalnum(*ip)) /* 0x07FF */
ip++;
} else
- fatal(_("input error: `=' expected after %s field\n"),
+ errx(EXIT_FAILURE, _("input error: `=' expected after %s field"),
d->fldname);
if (fno <= d->fldno)
fno = d->fldno + 1;
if (*ip == 0)
return fno;
if (*ip != ',' && *ip != ';')
- fatal(_("input error: unexpected character %c after %s field\n"),
+ errx(EXIT_FAILURE, _("input error: unexpected character %c after %s field"),
*ip, d->fldname);
*ip = 0;
goto nxtfld;
}
}
- fatal(_("unrecognized input: %s\n"), ip);
+ errx(EXIT_FAILURE, _("unrecognized input: %s"), ip);
}
/* split line into fields */
while (!(i = read_line(pno, ep, dev, interactive, z)))
if (!interactive)
- fatal(_("bad input\n"));
+ errx(EXIT_FAILURE, _("bad input"));
if (i < 0) {
p->ep = ep;
return 0;
textdomain(PACKAGE);
if (argc < 1)
- fatal(_("no command?\n"));
+ errx(EXIT_FAILURE, _("no command?"));
if ((progn = strrchr(argv[0], '/')) == NULL)
progn = argv[0];
else
}
if (do_id) {
if ((do_id & PRINT_ID) != 0 && optind != argc - 2)
- fatal(_("usage: sfdisk --print-id device partition-number\n"));
+ errx(EXIT_FAILURE, _("usage: sfdisk --print-id device partition-number"));
else if ((do_id & CHANGE_ID) != 0 && optind != argc - 3)
- fatal(_("usage: sfdisk --change-id device partition-number Id\n"));
+ errx(EXIT_FAILURE, _("usage: sfdisk --change-id device partition-number Id"));
else if (optind != argc - 3 && optind != argc - 2)
- fatal(_("usage: sfdisk --id device partition-number [Id]\n"));
+ errx(EXIT_FAILURE, _("usage: sfdisk --id device partition-number [Id]"));
do_change_id(argv[optind], argv[optind + 1],
(optind == argc - 2) ? 0 : argv[optind + 2]);
exit(exit_status);
}
if (optind != argc - 1)
- fatal(_("can specify only one device (except with -l or -s)\n"));
+ errx(EXIT_FAILURE, _("can specify only one device (except with -l or -s)"));
dev = argv[optind];
if (opt_reread)
if (fd < 0 && !silent) {
perror(dev);
if (rw)
- fatal(_("cannot open %s read-write\n"), dev);
+ errx(EXIT_FAILURE, _("cannot open %s read-write"), dev);
else
- fatal(_("cannot open %s for reading\n"), dev);
+ errx(EXIT_FAILURE, _("cannot open %s for reading"), dev);
}
return fd;
}
if (blkdev_get_sectors(fd, &size) == -1) {
if (!silent) {
perror(dev);
- fatal(_("Cannot get size of %s\n"), dev);
+ errx(EXIT_FAILURE, _("Cannot get size of %s"), dev);
}
return;
}
if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17)
id -= 0x10;
else
- fatal(_("partition %s has id %x and is not hidden\n"), pnam, id);
+ errx(EXIT_FAILURE, _("partition %s has id %x and is not hidden"), pnam, id);
z->partitions[pno].p.sys_type = id;
}
}
i = strtoul(id, NULL, 16);
if (i > 255)
- fatal(_("Bad Id %lx\n"), i);
+ errx(EXIT_FAILURE, _("Bad Id %lx"), i);
z->partitions[pno].p.sys_type = i;
if (write_partitions(dev, fd, z))
if (stat(dev, &statbuf) < 0) {
perror(dev);
- fatal(_("Fatal error: cannot find %s\n"), dev);
+ errx(EXIT_FAILURE, _("Fatal error: cannot find %s"), dev);
}
if (!S_ISBLK(statbuf.st_mode)) {
do_warn(_("Warning: %s is not a block device\n"), dev);
out_partitions(dev, z);
if (one_only && (one_only_pno = linux_to_index(one_only, z)) < 0)
- fatal(_("Partition %d does not exist, cannot change it\n"), one_only);
+ errx(EXIT_FAILURE, _("Partition %d does not exist, cannot change it"), one_only);
z = &newp;
if (!partitions_ok(fd, z) && !force) {
if (!interactive)
- fatal(_("I don't like these partitions - nothing changed.\n"
- "(If you really want this, use the --force option.)\n"));
+ errx(EXIT_FAILURE, _("I don't like these partitions - nothing changed.\n"
+ "(If you really want this, use the --force option.)"));
else
do_warn(_("I don't like this - probably you should answer No\n"));
}
if (c == EOF)
printf(_("\nsfdisk: premature end of input\n"));
if (c == EOF || answer == 'q' || answer == 'Q') {
- fatal(_("Quitting - nothing changed\n"));
+ errx(EXIT_FAILURE, _("Quitting - nothing changed"));
} else if (answer == 'n' || answer == 'N') {
continue;
} else if (answer == 'y' || answer == 'Y') {