mknod: Use a switch statement for the node type
This commit is contained in:
parent
e5d8efb32f
commit
ba2f04f391
19
mknod.c
19
mknod.c
|
@ -22,7 +22,7 @@ usage(void)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
mode_t type, mode = 0666;
|
mode_t mode = 0666;
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
|
@ -36,13 +36,24 @@ main(int argc, char *argv[])
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (strlen(argv[1]) != 1 || !strchr("ucb", argv[1][0]))
|
if (strlen(argv[1]) != 1)
|
||||||
|
goto invalid;
|
||||||
|
switch (argv[1][0]) {
|
||||||
|
case 'b':
|
||||||
|
mode |= S_IFBLK;
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
case 'c':
|
||||||
|
mode |= S_IFCHR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
invalid:
|
||||||
eprintf("invalid type '%s'\n", argv[1]);
|
eprintf("invalid type '%s'\n", argv[1]);
|
||||||
type = (argv[1][0] == 'b') ? S_IFBLK : S_IFCHR;
|
}
|
||||||
|
|
||||||
dev = makedev(estrtonum(argv[2], 0, LLONG_MAX), estrtonum(argv[3], 0, LLONG_MAX));
|
dev = makedev(estrtonum(argv[2], 0, LLONG_MAX), estrtonum(argv[3], 0, LLONG_MAX));
|
||||||
|
|
||||||
if (mknod(argv[0], type|mode, dev) == -1)
|
if (mknod(argv[0], mode, dev) == -1)
|
||||||
eprintf("mknod %s:", argv[0]);
|
eprintf("mknod %s:", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user