aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-03-02 11:52:38 -0600
committerRob Landley <rob@landley.net>2016-03-02 11:52:38 -0600
commit7ca5dc4232b9ac5ee5cd25c8b5b33a58904cd251 (patch)
tree258fe0d485c5793e19a56be81f9d71e51476f0d8 /toys
parent323819c689448fffcf4d3ed20f2485b75ac64b64 (diff)
downloadtoybox-7ca5dc4232b9ac5ee5cd25c8b5b33a58904cd251.tar.gz
For years the man pages have said to #include <sys/types.h> to get
major/minor/makedev, but glibc has vowed to break existing programs (https://sourceware.org/ml/libc-alpha/2015-11/msg00253.html) and replace it with _another_ non-standard header (not in posix or lsb), so let's just add functions to lib/ that do the transform ourselves.
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/mknod.c2
-rw-r--r--toys/other/makedevs.c2
-rw-r--r--toys/other/mountpoint.c5
-rw-r--r--toys/pending/mdev.c2
-rw-r--r--toys/pending/tar.c6
-rw-r--r--toys/posix/cpio.c8
-rw-r--r--toys/posix/ls.c5
-rw-r--r--toys/posix/ps.c2
8 files changed, 18 insertions, 14 deletions
diff --git a/toys/lsb/mknod.c b/toys/lsb/mknod.c
index 1a467b01..8148c857 100644
--- a/toys/lsb/mknod.c
+++ b/toys/lsb/mknod.c
@@ -53,6 +53,6 @@ void mknod_main(void)
if (toys.optflags & FLAG_Z)
if (-1 == lsm_set_create(TT.arg_context))
perror_exit("-Z '%s' failed", TT.arg_context);
- if (mknod(*toys.optargs, mode|modes[type], makedev(major, minor)))
+ if (mknod(*toys.optargs, mode|modes[type], dev_makedev(major, minor)))
perror_exit_raw(*toys.optargs);
}
diff --git a/toys/other/makedevs.c b/toys/other/makedevs.c
index 0f0a6615..0f79b25f 100644
--- a/toys/other/makedevs.c
+++ b/toys/other/makedevs.c
@@ -99,7 +99,7 @@ void makedevs_main()
perror_msg("line %d: file '%s' does not exist", line_no, ptr);
continue;
}
- } else if (mknod(ptr, mode, makedev(major, minor + i*incr))) {
+ } else if (mknod(ptr, mode, dev_makedev(major, minor + i*incr))) {
perror_msg("line %d: can't create node '%s'", line_no, ptr);
continue;
}
diff --git a/toys/other/mountpoint.c b/toys/other/mountpoint.c
index ce1d23cd..98e1d309 100644
--- a/toys/other/mountpoint.c
+++ b/toys/other/mountpoint.c
@@ -37,7 +37,8 @@ void mountpoint_main(void)
if (toys.optflags & FLAG_x) {
if (S_ISBLK(st1.st_mode)) {
- if (!quiet) printf("%u:%u\n", major(st1.st_rdev), minor(st1.st_rdev));
+ if (!quiet)
+ printf("%u:%u\n", dev_major(st1.st_rdev), dev_minor(st1.st_rdev));
return;
}
@@ -57,7 +58,7 @@ void mountpoint_main(void)
// absence of a spec I guess that's the expected behavior?
toys.exitval = !(st1.st_dev != st2.st_dev || st1.st_ino == st2.st_ino);
if (toys.optflags & FLAG_d)
- printf("%u:%u\n", major(st1.st_dev), minor(st1.st_dev));
+ printf("%u:%u\n", dev_major(st1.st_dev), dev_minor(st1.st_dev));
else if (!quiet)
printf("%s is %sa mountpoint\n", *toys.optargs, toys.exitval ? "not " : "");
}
diff --git a/toys/pending/mdev.c b/toys/pending/mdev.c
index e7adc993..975d31da 100644
--- a/toys/pending/mdev.c
+++ b/toys/pending/mdev.c
@@ -190,7 +190,7 @@ found_device:
if (strchr(device_name, '/'))
mkpathat(AT_FDCWD, toybuf, 0, 2);
- if (mknod(toybuf, mode | type, makedev(major, minor)) && errno != EEXIST)
+ if (mknod(toybuf, mode | type, dev_makedev(major, minor)) && errno != EEXIST)
perror_exit("mknod %s failed", toybuf);
diff --git a/toys/pending/tar.c b/toys/pending/tar.c
index 4f4de0b5..c5043087 100644
--- a/toys/pending/tar.c
+++ b/toys/pending/tar.c
@@ -228,8 +228,8 @@ static void add_file(struct archive_handler *tar, char **nam, struct stat *st)
else if (S_ISFIFO(st->st_mode)) hdr.type = '6';
else if (S_ISBLK(st->st_mode) || S_ISCHR(st->st_mode)) {
hdr.type = (S_ISCHR(st->st_mode))?'3':'4';
- itoo(hdr.major, sizeof(hdr.major), major(st->st_rdev));
- itoo(hdr.minor, sizeof(hdr.minor), minor(st->st_rdev));
+ itoo(hdr.major, sizeof(hdr.major), dev_major(st->st_rdev));
+ itoo(hdr.minor, sizeof(hdr.minor), dev_minor(st->st_rdev));
} else {
error_msg("unknown file type '%o'", st->st_mode & S_IFMT);
return;
@@ -623,7 +623,7 @@ CHECK_MAGIC:
file_hdr->gname = xstrdup(tar.gname);
maj = otoi(tar.major, sizeof(tar.major));
min = otoi(tar.minor, sizeof(tar.minor));
- file_hdr->device = makedev(maj, min);
+ file_hdr->device = dev_makedev(maj, min);
if (tar.type <= '7') {
if (tar.link[0]) {
diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c
index 981d6c5a..3bd40f47 100644
--- a/toys/posix/cpio.c
+++ b/toys/posix/cpio.c
@@ -114,6 +114,7 @@ void cpio_main(void)
// Read header and name.
xreadall(afd, toybuf, 110);
+ if (memcmp(toybuf, "070701", 6)) error_exit("bad cpio magic");
tofree = name = strpad(afd, x8u(toybuf+94), 110);
if (!strcmp("TRAILER!!!", name)) {
if (CFG_TOYBOX_FREE) free(tofree);
@@ -180,7 +181,7 @@ void cpio_main(void)
close(fd);
}
} else if (!test)
- err = mknod(name, mode, makedev(x8u(toybuf+78), x8u(toybuf+86)));
+ err = mknod(name, mode, dev_makedev(x8u(toybuf+78), x8u(toybuf+86)));
// Set ownership and timestamp.
if (!test && !err) {
@@ -243,8 +244,9 @@ void cpio_main(void)
llen = sprintf(toybuf,
"070701%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
(int)st.st_ino, st.st_mode, st.st_uid, st.st_gid, (int)st.st_nlink,
- (int)st.st_mtime, (int)st.st_size, major(st.st_dev),
- minor(st.st_dev), major(st.st_rdev), minor(st.st_rdev), nlen, 0);
+ (int)st.st_mtime, (int)st.st_size, dev_major(st.st_dev),
+ dev_minor(st.st_dev), dev_major(st.st_rdev), dev_minor(st.st_rdev),
+ nlen, 0);
xwrite(afd, toybuf, llen);
xwrite(afd, name, nlen);
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 08ae695d..4dcbe888 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -144,7 +144,7 @@ static void entrylen(struct dirtree *dt, unsigned *len)
if (S_ISBLK(st->st_mode) || S_ISCHR(st->st_mode)) {
// cheating slightly here: assuming minor is always 3 digits to avoid
// tracking another column
- len[5] = numlen(major(st->st_rdev))+5;
+ len[5] = numlen(dev_major(st->st_rdev))+5;
} else if (flags & FLAG_h) {
human_readable(tmp, st->st_size, 0);
len[5] = strwidth(tmp);
@@ -453,7 +453,8 @@ static void listfiles(int dirfd, struct dirtree *indir)
// print major/minor, or size
if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
- printf("% *d,% 4d", totals[5]-4, major(st->st_rdev),minor(st->st_rdev));
+ printf("% *d,% 4d", totals[5]-4, dev_major(st->st_rdev),
+ dev_minor(st->st_rdev));
else if (flags&FLAG_h) {
human_readable(tmp, st->st_size, 0);
xprintf("%*s", totals[5]+1, tmp);
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index d2ef9fc1..26b4a4ea 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -701,7 +701,7 @@ static int get_ps(struct dirtree *new)
// Couldn't find it, try all the tty drivers.
if (i == 3) {
FILE *fp = fopen("/proc/tty/drivers", "r");
- int tty_major = 0, maj = major(rdev), min = minor(rdev);
+ int tty_major = 0, maj = dev_major(rdev), min = dev_minor(rdev);
if (fp) {
while (fscanf(fp, "%*s %256s %d %*s %*s", buf, &tty_major) == 2) {