Introduction
Introduction Statistics Contact Development Disclaimer Help
mknod.c - ubase - suckless linux base utils
git clone git://git.suckless.org/ubase
Log
Files
Refs
README
LICENSE
---
mknod.c (856B)
---
1 /* See LICENSE file for copyright and license details. */
2 #include <sys/stat.h>
3 #include <sys/sysmacros.h>
4 #include <sys/types.h>
5
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11
12 #include "util.h"
13
14 static void
15 usage(void)
16 {
17 eprintf("usage: %s [-m mode] name type major minor\n", argv0);
18 }
19
20 int
21 main(int argc, char *argv[])
22 {
23 mode_t type, mode = 0644;
24 dev_t dev;
25
26 ARGBEGIN {
27 case 'm':
28 mode = estrtol(EARGF(usage()), 8);
29 break;
30 default:
31 usage();
32 } ARGEND;
33
34 if (argc != 4)
35 usage();
36
37 if (strlen(argv[1]) != 1 || !strchr("ucb", argv[1][0]))
38 eprintf("mknod: '%s': invalid type\n", argv[1]);
39 type = (argv[1][0] == 'b') ? S_IFBLK : S_IFCHR;
40
41 dev = makedev(estrtol(argv[2], 0), estrtol(argv[3], 0));
42
43 if (mknod(argv[0], type|mode, dev) == -1)
44 eprintf("mknod: '%s':", argv[0]);
45 return 0;
46 }
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.