From Jan Kiszka: This patch fixes the security labelling of the login terminal
[oweals/busybox.git] / debianutils / mktemp.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Mini mktemp implementation for busybox
4  *
5  *
6  * Copyright (C) 2000 by Daniel Jacobowitz
7  * Written by Daniel Jacobowitz <dan@debian.org>
8  *
9  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
10  */
11
12 #include <stdio.h>
13 #include <errno.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include "busybox.h"
18
19 int mktemp_main(int argc, char **argv)
20 {
21         unsigned long flags = bb_getopt_ulflags(argc, argv, "dq");
22
23         if (optind + 1 != argc)
24                 bb_show_usage();
25
26         if (flags & 1) {
27                 if (mkdtemp(argv[optind]) == NULL)
28                         return EXIT_FAILURE;
29         }
30         else {
31                 if (mkstemp(argv[optind]) < 0)
32                         return EXIT_FAILURE;
33         }
34
35         puts(argv[optind]);
36
37         return EXIT_SUCCESS;
38 }