md5/sha1sum: better fix for small resource leak
[platform/upstream/busybox.git] / coreutils / mkfifo.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * mkfifo implementation for busybox
4  *
5  * Copyright (C) 2003  Manuel Novoa III  <mjn3@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8  */
9
10 /* BB_AUDIT SUSv3 compliant */
11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */
12
13 //usage:#define mkfifo_trivial_usage
14 //usage:       "[-m MODE] " IF_SELINUX("[-Z] ") "NAME"
15 //usage:#define mkfifo_full_usage "\n\n"
16 //usage:       "Create named pipe\n"
17 //usage:     "\nOptions:"
18 //usage:     "\n        -m MODE Mode (default a=rw)"
19 //usage:        IF_SELINUX(
20 //usage:     "\n        -Z      Set security context"
21 //usage:        )
22
23 #include "libbb.h"
24 #include "libcoreutils/coreutils.h"
25
26 /* This is a NOEXEC applet. Be very careful! */
27
28 int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29 int mkfifo_main(int argc UNUSED_PARAM, char **argv)
30 {
31         mode_t mode;
32         int retval = EXIT_SUCCESS;
33
34         mode = getopt_mk_fifo_nod(argv);
35
36         argv += optind;
37         if (!*argv) {
38                 bb_show_usage();
39         }
40
41         do {
42                 if (mkfifo(*argv, mode) < 0) {
43                         bb_simple_perror_msg(*argv);  /* Avoid multibyte problems. */
44                         retval = EXIT_FAILURE;
45                 }
46         } while (*++argv);
47
48         return retval;
49 }