Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/debianutils/mktemp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 881 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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 "busybox.h"
13 #include <stdio.h>
14 #include <errno.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include <stdlib.h>
18
19 int mktemp_main(int argc, char **argv)
20 {
21 unsigned long flags = getopt32(argc, argv, "dqt");
22 char *chp;
23
24 if (optind + 1 != argc)
25 bb_show_usage();
26
27 chp = argv[optind];
28
29 if (flags & 4) {
30 char *dir = getenv("TMPDIR");
31 if (dir && *dir != '\0')
32 chp = concat_path_file(dir, chp);
33 else
34 chp = concat_path_file("/tmp/", chp);
35 }
36
37 if (flags & 1) {
38 if (mkdtemp(chp) == NULL)
39 return EXIT_FAILURE;
40 } else {
41 if (mkstemp(chp) < 0)
42 return EXIT_FAILURE;
43 }
44
45 puts(chp);
46
47 return EXIT_SUCCESS;
48 }