xref: /csrg-svn/sbin/mknod/mknod.c (revision 37130)
1*37130Sbostic /*
2*37130Sbostic  * Copyright (c) 1989 The Regents of the University of California.
3*37130Sbostic  * All rights reserved.
4*37130Sbostic  *
5*37130Sbostic  * This code is derived from software contributed to Berkeley by
6*37130Sbostic  * Kevin Fall.
7*37130Sbostic  *
8*37130Sbostic  * Redistribution and use in source and binary forms are permitted
9*37130Sbostic  * provided that the above copyright notice and this paragraph are
10*37130Sbostic  * duplicated in all such forms and that any documentation,
11*37130Sbostic  * advertising materials, and other materials related to such
12*37130Sbostic  * distribution and use acknowledge that the software was developed
13*37130Sbostic  * by the University of California, Berkeley.  The name of the
14*37130Sbostic  * University may not be used to endorse or promote products derived
15*37130Sbostic  * from this software without specific prior written permission.
16*37130Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17*37130Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18*37130Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19*37130Sbostic  */
20*37130Sbostic 
2124467Smckusick #ifndef lint
22*37130Sbostic char copyright[] =
23*37130Sbostic "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
24*37130Sbostic  All rights reserved.\n";
25*37130Sbostic #endif /* not lint */
2624467Smckusick 
27*37130Sbostic #ifndef lint
28*37130Sbostic static char sccsid[] = "@(#)mknod.c	4.3 (Berkeley) 03/11/89";
29*37130Sbostic #endif /* not lint */
30*37130Sbostic 
31*37130Sbostic #include <sys/types.h>
32*37130Sbostic #include <sys/stat.h>
3324467Smckusick #include <stdio.h>
3424467Smckusick 
351053Sbill main(argc, argv)
3624467Smckusick 	int argc;
3724467Smckusick 	char **argv;
381053Sbill {
39*37130Sbostic 	extern int errno;
40*37130Sbostic 	u_short mode;
41*37130Sbostic 	char *strerror();
421053Sbill 
43*37130Sbostic 	if (argc != 5) {
44*37130Sbostic 		(void)fprintf(stderr,
45*37130Sbostic 		    "usage: mknod name [b | c] major minor\n");
46*37130Sbostic 		exit(1);
471053Sbill 	}
48*37130Sbostic 
49*37130Sbostic 	mode = 0666;
50*37130Sbostic 	if (argv[2][0] == 'c')
51*37130Sbostic 		mode |= S_IFCHR;
52*37130Sbostic 	else if (argv[2][0] == 'b')
53*37130Sbostic 		mode |= S_IFBLK;
54*37130Sbostic 	else {
55*37130Sbostic 		(void)fprintf(stderr,
56*37130Sbostic 		    "mknod: node must be type 'b' or 'c'.\n");
57*37130Sbostic 		exit(1);
5824467Smckusick 	}
591053Sbill 
60*37130Sbostic 	if (mknod(argv[1], mode, makedev(atoi(argv[3]), atoi(argv[4]))) < 0) {
61*37130Sbostic 		(void)fprintf(stderr,
62*37130Sbostic 		    "mknod: %s: %s\n", argv[1], strerror(errno));
63*37130Sbostic 		exit(1);
641053Sbill 	}
65*37130Sbostic 	exit(0);
661053Sbill }
67