aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-10-05 23:33:36 -0500
committerRob Landley <rob@landley.net>2012-10-05 23:33:36 -0500
commita631a3b45b72e54b75758150eba5fc99e85cee7c (patch)
tree3955877d2b3e99c72f4b1014cf5e863140f616f5 /toys/lsb
parent3514b035d6457f92069d91c5e2998c037cee3162 (diff)
downloadtoybox-a631a3b45b72e54b75758150eba5fc99e85cee7c.tar.gz
Cleanup mknod.
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/mknod.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/toys/lsb/mknod.c b/toys/lsb/mknod.c
index c1a543d2..fbdc8800 100644
--- a/toys/lsb/mknod.c
+++ b/toys/lsb/mknod.c
@@ -15,37 +15,29 @@ config MKNOD
usage: mknod NAME TYPE [MAJOR MINOR]
Create a special file NAME with a given type, possible types are
- b create a block device with the given MAJOR/MINOR
- c or u create a character device with the given MAJOR/MINOR
- p create a named pipe ignoring MAJOR/MINOR
+ b block device
+ c or u character device
+ p named pipe (ignores MAJOR/MINOR)
*/
#include "toys.h"
-static const char modes_char[] = {'p', 'c', 'u', 'b'};
-static const mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
-
void mknod_main(void)
{
+ mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
int major=0, minor=0, type;
- char * tmp;
int mode = 0660;
- tmp = strchr(modes_char, toys.optargs[1][0]);
- if (!tmp)
- perror_exit("unknown special device type %c", toys.optargs[1][0]);
-
- type = modes[tmp-modes_char];
-
- if (type == S_IFCHR || type == S_IFBLK) {
- if (toys.optc != 4)
- perror_exit("creating a block/char device requires major/minor");
+ type = stridx("pcub", *toys.optargs[1]);
+ if (type == -1) perror_exit("bad type '%c'", *toys.optargs[1]);
+ if (type) {
+ if (toys.optc != 4) perror_exit("need major/minor");
major = atoi(toys.optargs[2]);
minor = atoi(toys.optargs[3]);
}
- if (mknod(toys.optargs[0], mode | type, makedev(major, minor)))
+ if (mknod(toys.optargs[0], mode | modes[type], makedev(major, minor)))
perror_exit("mknod %s failed", toys.optargs[0]);
}