unstack, sort: cleanup and improvement
[minix.git] / commands / mknod / mknod.c
blob43d3b732f20cca25f381e9250ff453fb2d872391
1 /* mknod - build a special file Author: Andy Tanenbaum */
3 #include <sys/types.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <minix/minlib.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #ifdef __NBSD_LIBC
10 #include <sys/stat.h>
11 #endif
13 int main(int argc, char *argv []);
14 void badcomm(void);
15 void badfifo(void);
16 void badchar(void);
17 void badblock(void);
19 int main(argc, argv)
20 int argc;
21 char *argv[];
23 /* Mknod name b/c major minor makes a node. */
25 int mode, major, minor, dev;
27 if (argc < 3) badcomm();
28 if (*argv[2] != 'b' && *argv[2] != 'c' && *argv[2] != 'p') badcomm();
29 if (*argv[2] == 'p' && argc != 3) badfifo();
30 if (*argv[2] == 'c' && argc != 5) badchar();
31 if (*argv[2] == 'b' && argc != 5) badblock();
32 if (*argv[2] == 'p') {
33 mode = 010666;
34 dev = 0;
35 } else {
36 mode = (*argv[2] == 'b' ? 060666 : 020666);
37 major = atoi(argv[3]);
38 minor = atoi(argv[4]);
39 if (major - 1 > 0xFE || minor > 0xFF) badcomm();
40 dev = (major << 8) | minor;
42 if (mknod(argv[1], mode, dev) < 0) {
43 int err = errno;
44 std_err("mknod: ");
45 errno = err;
46 perror(argv[1]);
48 return(0);
51 void badcomm()
53 std_err("Usage: mknod name b/c/p [major minor]\n");
54 exit(1);
57 void badfifo()
59 std_err("Usage: mknod name p\n");
60 exit(1);
63 void badchar()
65 std_err("Usage: mknod name c major minor\n");
66 exit(1);
69 void badblock()
71 std_err("Usage: mknod name b major minor\n");
72 exit(1);