aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/acpi.c2
-rw-r--r--toys/other/blkid.c2
-rw-r--r--toys/other/bzcat.c6
-rw-r--r--toys/other/chroot.c2
-rw-r--r--toys/other/dos2unix.c2
-rw-r--r--toys/other/hexedit.c2
-rw-r--r--toys/other/ifconfig.c2
-rw-r--r--toys/other/inotifyd.c2
-rw-r--r--toys/other/ionice.c2
-rw-r--r--toys/other/losetup.c4
-rw-r--r--toys/other/modinfo.c2
-rw-r--r--toys/other/mountpoint.c2
-rw-r--r--toys/other/realpath.c2
-rw-r--r--toys/other/shred.c6
-rw-r--r--toys/other/stat.c61
15 files changed, 53 insertions, 46 deletions
diff --git a/toys/other/acpi.c b/toys/other/acpi.c
index 363cfb99..bca53814 100644
--- a/toys/other/acpi.c
+++ b/toys/other/acpi.c
@@ -35,7 +35,7 @@ int read_int_at(int dirfd, char *name)
FILE *fil;
if ((fd = openat(dirfd, name, O_RDONLY)) < 0) return -1;
- if (!fscanf(fil = xfdopen(fd, "r"), "%d", &ret)) perror_exit("%s", name);
+ if (!fscanf(fil = xfdopen(fd, "r"), "%d", &ret)) perror_exit_raw(name);
fclose(fil);
return ret;
diff --git a/toys/other/blkid.c b/toys/other/blkid.c
index 4883b607..8aab8f74 100644
--- a/toys/other/blkid.c
+++ b/toys/other/blkid.c
@@ -149,7 +149,7 @@ void blkid_main(void)
sprintf(device, "/dev/%.20s", name);
if (-1 == (fd = open(device, O_RDONLY))) {
- if (errno != ENOMEDIUM) perror_msg("%s", device);
+ if (errno != ENOMEDIUM) perror_msg_raw(device);
} else {
do_blkid(fd, device);
close(fd);
diff --git a/toys/other/bzcat.c b/toys/other/bzcat.c
index 850c51ce..1081b5e9 100644
--- a/toys/other/bzcat.c
+++ b/toys/other/bzcat.c
@@ -663,7 +663,7 @@ static void do_bzcat(int fd, char *name)
{
char *err = bunzipStream(fd, 1);
- if (err) error_exit(err);
+ if (err) error_exit_raw(err);
}
void bzcat_main(void)
@@ -700,7 +700,7 @@ static void do_bunzip2(int fd, char *name)
if (toys.optflags&FLAG_v) {
printf("%s\n", err ? err : "ok");
toys.exitval |= !!err;
- } else if (err) error_msg(err);
+ } else if (err) error_msg_raw(err);
// can't test outfd==1 because may have been called with stdin+stdout closed
if (rename) {
@@ -709,7 +709,7 @@ static void do_bunzip2(int fd, char *name)
tmp = 0;
} else {
if (dotbz) *dotbz = '.';
- if (!unlink(name)) perror_msg("%s", name);
+ if (!unlink(name)) perror_msg_raw(name);
}
(err ? delete_tempfile : replace_tempfile)(-1, outfd, &tmp);
}
diff --git a/toys/other/chroot.c b/toys/other/chroot.c
index 4260d98f..b6ef17d6 100644
--- a/toys/other/chroot.c
+++ b/toys/other/chroot.c
@@ -24,7 +24,7 @@ void chroot_main(void)
{
char *binsh[] = {"/bin/sh", "-i", 0};
- if (chdir(*toys.optargs) || chroot(".")) perror_exit("%s", *toys.optargs);
+ if (chdir(*toys.optargs) || chroot(".")) perror_exit_raw(*toys.optargs);
if (toys.optargs[1]) xexec(toys.optargs+1);
else xexec(binsh);
}
diff --git a/toys/other/dos2unix.c b/toys/other/dos2unix.c
index 021ba384..083a8140 100644
--- a/toys/other/dos2unix.c
+++ b/toys/other/dos2unix.c
@@ -42,7 +42,7 @@ static void do_dos2unix(int fd, char *name)
int len, in, out;
len = read(fd, toybuf+(sizeof(toybuf)/2), sizeof(toybuf)/2);
- if (len<0) perror_msg("%s",name);
+ if (len<0) perror_msg_raw(name);
if (len<1) break;
for (in = out = 0; in < len; in++) {
diff --git a/toys/other/hexedit.c b/toys/other/hexedit.c
index b3bde2e5..c45ef1ca 100644
--- a/toys/other/hexedit.c
+++ b/toys/other/hexedit.c
@@ -173,7 +173,7 @@ void hexedit_main(void)
// Display cursor and flush output
highlight(x, y, ro ? 3 : side);
- xprintf("");
+ xflush();
// Wait for next key
key = scan_key(keybuf, 1);
diff --git a/toys/other/ifconfig.c b/toys/other/ifconfig.c
index bfd9a306..1d2a41dc 100644
--- a/toys/other/ifconfig.c
+++ b/toys/other/ifconfig.c
@@ -110,7 +110,7 @@ static void display_ifconfig(char *name, int always, unsigned long long val[])
short flags;
xstrncpy(ifre.ifr_name, name, IFNAMSIZ);
- if (ioctl(TT.sockfd, SIOCGIFFLAGS, &ifre)<0) perror_exit("%s", name);
+ if (ioctl(TT.sockfd, SIOCGIFFLAGS, &ifre)<0) perror_exit_raw(name);
flags = ifre.ifr_flags;
if (!always && !(flags & IFF_UP)) return;
diff --git a/toys/other/inotifyd.c b/toys/other/inotifyd.c
index f2e11ca4..42d1d76e 100644
--- a/toys/other/inotifyd.c
+++ b/toys/other/inotifyd.c
@@ -65,7 +65,7 @@ void inotifyd_main(void)
// This returns increasing numbers starting from 1, which coincidentally
// is the toys.optargs position of the file. (0 is program to run.)
- if (inotify_add_watch(fds.fd, path, mask) < 0) perror_exit("%s", path);
+ if (inotify_add_watch(fds.fd, path, mask) < 0) perror_exit_raw(path);
}
for (;;) {
diff --git a/toys/other/ionice.c b/toys/other/ionice.c
index 152a8c33..37d35456 100644
--- a/toys/other/ionice.c
+++ b/toys/other/ionice.c
@@ -82,7 +82,7 @@ void iorenice_main(void)
if (p == -1) perror_exit("read priority");
TT.class = (p>>13)&3;
p &= 7;
- xprintf("Pid %d, class %s (%d), prio %d\n",
+ xprintf("Pid %ld, class %s (%ld), prio %d\n",
TT.pid, classes[TT.class], TT.class, p);
return;
}
diff --git a/toys/other/losetup.c b/toys/other/losetup.c
index a40d9e42..4e467a9c 100644
--- a/toys/other/losetup.c
+++ b/toys/other/losetup.c
@@ -88,7 +88,7 @@ static void loopback_setup(char *device, char *file)
if (-1 == lfd || ioctl(lfd, LOOP_GET_STATUS64, loop)) {
if (errno == ENXIO && (flags & (FLAG_a|FLAG_j))) goto done;
if (errno != ENXIO || !file) {
- perror_msg("%s", device ? device : "-f");
+ perror_msg_raw(device ? device : "-f");
goto done;
}
}
@@ -101,7 +101,7 @@ static void loopback_setup(char *device, char *file)
if (flags & (FLAG_c|FLAG_d)) {
// The constant is LOOP_SET_CAPACITY
if (ioctl(lfd, (flags & FLAG_c) ? 0x4C07 : LOOP_CLR_FD, 0)) {
- perror_msg("%s", device);
+ perror_msg_raw(device);
goto done;
}
// Associate file with this device?
diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c
index 3a7e821f..61155b46 100644
--- a/toys/other/modinfo.c
+++ b/toys/other/modinfo.c
@@ -50,7 +50,7 @@ static void modinfo_file(char *full_name)
}
if (!buf) {
- perror_msg("%s", full_name);
+ perror_msg_raw(full_name);
return;
}
diff --git a/toys/other/mountpoint.c b/toys/other/mountpoint.c
index 150865ca..ce1d23cd 100644
--- a/toys/other/mountpoint.c
+++ b/toys/other/mountpoint.c
@@ -33,7 +33,7 @@ void mountpoint_main(void)
char *arg = *toys.optargs;
int quiet = toys.optflags & FLAG_q;
- if (lstat(arg, &st1)) perror_exit("%s", arg);
+ if (lstat(arg, &st1)) perror_exit_raw(arg);
if (toys.optflags & FLAG_x) {
if (S_ISBLK(st1.st_mode)) {
diff --git a/toys/other/realpath.c b/toys/other/realpath.c
index ec981082..8f75d3f2 100644
--- a/toys/other/realpath.c
+++ b/toys/other/realpath.c
@@ -20,7 +20,7 @@ void realpath_main(void)
char **s = toys.optargs;
for (s = toys.optargs; *s; s++) {
- if (!realpath(*s, toybuf)) perror_msg("%s", *s);
+ if (!realpath(*s, toybuf)) perror_msg_raw(*s);
else xputs(toybuf);
}
}
diff --git a/toys/other/shred.c b/toys/other/shred.c
index 64db5edf..5b018ea0 100644
--- a/toys/other/shred.c
+++ b/toys/other/shred.c
@@ -57,7 +57,7 @@ void shred_main(void)
fd = open(*try, O_RDWR);
}
if (fd == -1) {
- perror_msg("%s", *try);
+ perror_msg_raw(*try);
continue;
}
@@ -84,7 +84,7 @@ void shred_main(void)
if (pos < TT.offset) {
if (TT.offset != lseek(fd, TT.offset, SEEK_SET)) {
- perror_msg("%s", *try);
+ perror_msg_raw(*try);
break;
}
pos = TT.offset;
@@ -97,7 +97,7 @@ void shred_main(void)
if (len-pos < throw) throw = len-pos;
if (iter != TT.iterations) xread(TT.ufd, toybuf, throw);
- if (throw != writeall(fd, toybuf, throw)) perror_msg("%s");
+ if (throw != writeall(fd, toybuf, throw)) perror_msg_raw(*try);
pos += throw;
}
if (toys.optflags & FLAG_u)
diff --git a/toys/other/stat.c b/toys/other/stat.c
index fe522b08..fb5922c6 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -2,7 +2,7 @@
* Copyright 2012 <warior.linux@gmail.com>
* Copyright 2013 <anand.sinha85@gmail.com>
-USE_STAT(NEWTOY(stat, "c:f", TOYFLAG_BIN))
+USE_STAT(NEWTOY(stat, "<1c:f", TOYFLAG_BIN))
config STAT
bool stat
@@ -55,24 +55,31 @@ static void date_stat_format(struct timespec *ts)
{
strftime(toybuf, sizeof(toybuf), "%Y-%m-%d %H:%M:%S",
localtime(&(ts->tv_sec)));
- xprintf("%s.%09d", toybuf, ts->tv_nsec);
+ xprintf("%s.%09ld", toybuf, ts->tv_nsec);
+}
+
+// Force numeric output to long long instead of manually typecasting everything
+static void out(char c, long long val)
+{
+ sprintf(toybuf, "%%ll%c", c);
+ printf(toybuf, val);
}
static void print_stat(char type)
{
struct stat *stat = (struct stat *)&TT.stat;
- if (type == 'a') xprintf("%lo", stat->st_mode & ~S_IFMT);
+ if (type == 'a') out('o', stat->st_mode&~S_IFMT);
else if (type == 'A') {
char str[11];
mode_to_string(stat->st_mode, str);
xprintf("%s", str);
- } else if (type == 'b') xprintf("%llu", stat->st_blocks);
- else if (type == 'B') xprintf("%lu", stat->st_blksize);
- else if (type == 'd') xprintf("%ld", stat->st_dev);
- else if (type == 'D') xprintf("%llx", stat->st_dev);
- else if (type == 'f') xprintf("%lx", stat->st_mode);
+ } else if (type == 'b') out('u', stat->st_blocks);
+ else if (type == 'B') out('u', stat->st_blksize);
+ else if (type == 'd') out('d', stat->st_dev);
+ else if (type == 'D') out('x', stat->st_dev);
+ else if (type == 'f') out('x', stat->st_mode);
else if (type == 'F') {
char *t = "character device\0directory\0block device\0" \
"regular file\0symbolic link\0socket\0FIFO (named pipe)";
@@ -81,38 +88,38 @@ static void print_stat(char type)
for (i = 1; filetype != (i*8192) && i < 7; i++) t += strlen(t)+1;
if (!stat->st_size && filetype == S_IFREG) t = "regular empty file";
xprintf("%s", t);
- } else if (type == 'g') xprintf("%lu", stat->st_gid);
+ } else if (type == 'g') out('u', stat->st_gid);
else if (type == 'G') xprintf("%8s", TT.group_name->gr_name);
- else if (type == 'h') xprintf("%lu", stat->st_nlink);
- else if (type == 'i') xprintf("%llu", stat->st_ino);
+ else if (type == 'h') out('u', stat->st_nlink);
+ else if (type == 'i') out('u', stat->st_ino);
else if (type == 'N') {
xprintf("`%s'", *toys.optargs);
if (S_ISLNK(stat->st_mode))
if (0<readlink(*toys.optargs, toybuf, sizeof(toybuf)))
xprintf(" -> `%s'", toybuf);
- } else if (type == 'o') xprintf("%lu", stat->st_blksize);
- else if (type == 's') xprintf("%llu", stat->st_size);
- else if (type == 'u') xprintf("%lu", stat->st_uid);
+ } else if (type == 'o') out('u', stat->st_blksize);
+ else if (type == 's') out('u', stat->st_size);
+ else if (type == 'u') out('u', stat->st_uid);
else if (type == 'U') xprintf("%8s", TT.user_name->pw_name);
else if (type == 'x') date_stat_format((void *)&stat->st_atime);
- else if (type == 'X') xprintf("%llu", (long long)stat->st_atime);
+ else if (type == 'X') out('u', stat->st_atime);
else if (type == 'y') date_stat_format((void *)&stat->st_mtime);
- else if (type == 'Y') xprintf("%llu", (long long)stat->st_mtime);
+ else if (type == 'Y') out('u', stat->st_mtime);
else if (type == 'z') date_stat_format((void *)&stat->st_ctime);
- else if (type == 'Z') xprintf("%llu", (long long)stat->st_ctime);
+ else if (type == 'Z') out('u', stat->st_ctime);
else xprintf("?");
}
static void print_statfs(char type) {
struct statfs *statfs = (struct statfs *)&TT.stat;
- if (type == 'a') xprintf("%llu", statfs->f_bavail);
- else if (type == 'b') xprintf("%llu", statfs->f_blocks);
- else if (type == 'c') xprintf("%llu", statfs->f_files);
- else if (type == 'd') xprintf("%llu", statfs->f_ffree);
- else if (type == 'f') xprintf("%llu", statfs->f_bfree);
- else if (type == 'l') xprintf("%ld", statfs->f_namelen);
- else if (type == 't') xprintf("%lx", statfs->f_type);
+ if (type == 'a') out('u', statfs->f_bavail);
+ else if (type == 'b') out('u', statfs->f_blocks);
+ else if (type == 'c') out('u', statfs->f_files);
+ else if (type == 'd') out('u', statfs->f_ffree);
+ else if (type == 'f') out('u', statfs->f_bfree);
+ else if (type == 'l') out('d', statfs->f_namelen);
+ else if (type == 't') out('x', statfs->f_type);
else if (type == 'T') {
char *s = "unknown";
struct {unsigned num; char *name;} nn[] = {
@@ -129,11 +136,11 @@ static void print_statfs(char type) {
for (i=0; i<ARRAY_LEN(nn); i++)
if (nn[i].num == statfs->f_type) s = nn[i].name;
- xprintf(s);
+ fputs(s, stdout);
} else if (type == 'i')
xprintf("%08x%08x", statfs->f_fsid.__val[0], statfs->f_fsid.__val[1]);
- else if (type == 's') xprintf("%d", statfs->f_frsize);
- else if (type == 'S') xprintf("%d", statfs->f_bsize);
+ else if (type == 's') out('d', statfs->f_frsize);
+ else if (type == 'S') out('d', statfs->f_bsize);
else xprintf("?");
}