diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/mknod.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'coreutils/mknod.c')
-rw-r--r-- | coreutils/mknod.c | 94 |
1 files changed, 32 insertions, 62 deletions
diff --git a/coreutils/mknod.c b/coreutils/mknod.c index 432ec2b25..59294e9cb 100644 --- a/coreutils/mknod.c +++ b/coreutils/mknod.c | |||
@@ -1,9 +1,8 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini mknod implementation for busybox | 3 | * mknod implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org> | ||
7 | * | 6 | * |
8 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -21,73 +20,44 @@ | |||
21 | * | 20 | * |
22 | */ | 21 | */ |
23 | 22 | ||
24 | #include <stdio.h> | 23 | /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ |
25 | #include <errno.h> | 24 | |
26 | #include <fcntl.h> | ||
27 | #include <unistd.h> | ||
28 | #include <string.h> | ||
29 | #include <stdlib.h> | 25 | #include <stdlib.h> |
30 | #include <sys/types.h> | 26 | #include <string.h> |
31 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
28 | #include <unistd.h> | ||
32 | #include "busybox.h" | 29 | #include "busybox.h" |
30 | #include "libcoreutils/coreutils.h" | ||
31 | |||
32 | static const char modes_chars[] = { 'p', 'c', 'u', 'b', 0, 1, 1, 2 }; | ||
33 | static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK }; | ||
33 | 34 | ||
34 | int mknod_main(int argc, char **argv) | 35 | extern int mknod_main(int argc, char **argv) |
35 | { | 36 | { |
36 | char *thisarg; | 37 | mode_t mode; |
37 | mode_t mode = 0; | 38 | dev_t dev; |
38 | mode_t perm = 0666; | 39 | const char *name; |
39 | dev_t dev = (dev_t) 0; | 40 | |
41 | mode = getopt_mk_fifo_nod(argc, argv); | ||
42 | argv += optind; | ||
43 | argc -= optind; | ||
40 | 44 | ||
41 | argc--; | 45 | if ((argc >= 2) && ((name = strchr(modes_chars, argv[1][0])) != NULL)) { |
42 | argv++; | 46 | mode |= modes_cubp[(int)(name[4])]; |
43 | 47 | ||
44 | /* Parse any options */ | 48 | dev = 0; |
45 | while (argc > 1) { | 49 | if ((*name != 'p') && ((argc -= 2) == 0)) { |
46 | if (**argv != '-') | 50 | dev = (bb_xgetularg10_bnd(argv[2], 0, 255) << 8) |
47 | break; | 51 | + bb_xgetularg10_bnd(argv[3], 0, 255); |
48 | thisarg = *argv; | ||
49 | thisarg++; | ||
50 | switch (*thisarg) { | ||
51 | case 'm': | ||
52 | argc--; | ||
53 | argv++; | ||
54 | parse_mode(*argv, &perm); | ||
55 | umask(0); | ||
56 | break; | ||
57 | default: | ||
58 | show_usage(); | ||
59 | } | 52 | } |
60 | argc--; | 53 | |
61 | argv++; | 54 | if (argc == 2) { |
62 | } | 55 | name = *argv; |
63 | if (argc != 4 && argc != 2) { | 56 | if (mknod(name, mode, dev) == 0) { |
64 | show_usage(); | 57 | return EXIT_SUCCESS; |
65 | } | 58 | } |
66 | switch (argv[1][0]) { | 59 | bb_perror_msg_and_die("%s", name); |
67 | case 'c': | ||
68 | case 'u': | ||
69 | mode = S_IFCHR; | ||
70 | break; | ||
71 | case 'b': | ||
72 | mode = S_IFBLK; | ||
73 | break; | ||
74 | case 'p': | ||
75 | mode = S_IFIFO; | ||
76 | if (argc != 2) { | ||
77 | show_usage(); | ||
78 | } | 60 | } |
79 | break; | ||
80 | default: | ||
81 | show_usage(); | ||
82 | } | ||
83 | |||
84 | if (mode == S_IFCHR || mode == S_IFBLK) { | ||
85 | dev = (dev_t) ((atoi(argv[2]) << 8) | atoi(argv[3])); | ||
86 | } | 61 | } |
87 | 62 | bb_show_usage(); | |
88 | mode |= perm; | ||
89 | |||
90 | if (mknod(argv[0], mode, dev) != 0) | ||
91 | perror_msg_and_die("%s", argv[0]); | ||
92 | return EXIT_SUCCESS; | ||
93 | } | 63 | } |