Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/mkfifo.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1297 - (show annotations) (download)
Fri May 27 15:12:11 2011 UTC (13 years ago) by niro
File MIME type: text/plain
File size: 1184 byte(s)
-updated to klibc-1.5.22 with mntproc definitions patch included
1 #include <sys/stat.h>
2 #include <sys/types.h>
3 #include <fcntl.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9
10 #include "file_mode.h"
11
12 static mode_t leaf_mode;
13
14 char *progname;
15
16 static int make_fifo(char *dir)
17 {
18 if (mkfifo(dir, leaf_mode)) {
19 /*
20 * We failed, remove the directory we created.
21 */
22 fprintf(stderr, "%s: ", progname);
23 perror(dir);
24 return -1;
25 }
26 return 0;
27 }
28
29 int main(int argc, char *argv[])
30 {
31 int c, ret = 0;
32 mode_t saved_umask;
33
34 progname = argv[0];
35
36 saved_umask = umask(0);
37 leaf_mode =
38 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) &
39 ~saved_umask;
40
41 do {
42 c = getopt(argc, argv, "m:");
43 if (c == EOF)
44 break;
45 switch (c) {
46 case 'm':
47 leaf_mode =
48 parse_file_mode(optarg, leaf_mode, saved_umask);
49 break;
50
51 case '?':
52 fprintf(stderr, "%s: invalid option -%c\n",
53 progname, optopt);
54 exit(1);
55 }
56 } while (1);
57
58 if (optind == argc) {
59 fprintf(stderr, "Usage: %s [-m mode] file...\n", progname);
60 exit(1);
61 }
62
63 while (optind < argc) {
64 if (make_fifo(argv[optind]))
65 ret = 255; /* seems to be what gnu mkdir does */
66 optind++;
67 }
68
69 return ret;
70 }