commit - 1115ad3a8de82a7059b834dc980d31c3d43c2c7b
commit + 44121ddf9f1fabdd3e85b8a8cdbfa27245f902c7
blob - e063ce55e231c9aeb46fa18f868804d10676bf15
blob + b8555e87ca541cdabe8ccbc609f16a6ff126ec65
--- ChangeLog.md
+++ ChangeLog.md
and disks can have a label but partitions don't
(at least through the disklabel interface).
- Print fancy unicode characters by default.
+- Use err(3) instead of die()
### Removed
- Options:
blob - 060bc89a75870ac5592955670542c92e70c69d89
blob + 0328e8c612b9e2a393f234d2cc0dc62c84bde83d
--- lsblk.c
+++ lsblk.c
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
-
-static __dead void die (const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- fputs ("Error: ", stderr);
- vfprintf (stderr, fmt, ap);
-
- if (errno != 0) {
- fprintf (stderr, ": %s\n", strerror (errno));
- } else {
- fputc ('\n', stderr);
- }
-
- exit (1);
-}
+#include <err.h>
static int diskcount (void)
{
size_t len = sizeof diskcount;
if (sysctl (mib, 2, &diskcount, &len, NULL, 0) == -1)
- die ("sysctl(hw.diskcount)");
+ err (1, "sysctl(hw.diskcount)");
return diskcount;
}
char *buffer = malloc (len);
if (sysctl (mib, 2, buffer, &len, NULL, 0) == -1)
- die ("sysctl(hw.disknames)");
+ err (1, "sysctl(hw.disknames)");
return buffer;
}
if (!mounts) {
n_mounts = getmntinfo (&mounts, MNT_NOWAIT);
if (n_mounts == 0)
- die ("getmntinfo()");
+ err (1, "getmntinfo()");
}
for (int i = 0; i < n_mounts; ++i) {
asprintf (&path, "/dev/%sc", name);
fd = open (path, O_RDONLY);
if (fd < 0)
- die ("open(%s)", path);
+ err (1, "opendev(%s)", name);
if (ioctl (fd, DIOCGDINFO, &label) < 0)
- die ("ioctl(%s, DIOCGDINFO)", path);
+ err (1, "ioctl(%s, DIOCGDINFO)", name);
close (fd);
free (path);
}
int options = 0;
if (unveil ("/dev", "r") == -1)
- die ("unveil(/dev)");
+ err (1, "unveil(/dev)");
if (unveil (NULL, NULL) == -1)
- die ("unveil()");
+ err (1, "unveil()");
while ((option = getopt (argc, argv, ":ainUuV")) != -1) {
switch (option) {
char *names = argc == 0 ? disknames () : NULL;
if (pledge ("stdio rpath disklabel", NULL) == -1)
- die ("pledge()");
+ err (1, "pledge()");
size_t cap_disks;
if (argc == 0) {