Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 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 | * | ||||
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 9 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 10 | */ |
11 | |||||
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
13 | #include <errno.h> | ||||
Eric Andersen | eba8ed7 | 2001-03-09 14:36:42 +0000 | [diff] [blame] | 14 | #include <string.h> |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 15 | #include <unistd.h> |
16 | #include <stdlib.h> | ||||
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 17 | #include "busybox.h" |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 18 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 19 | int mktemp_main(int argc, char **argv) |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 20 | { |
Rob Landley | b5ca9e0 | 2005-12-02 17:54:01 +0000 | [diff] [blame] | 21 | unsigned long flags = bb_getopt_ulflags(argc, argv, "dq"); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 22 | |
Rob Landley | b5ca9e0 | 2005-12-02 17:54:01 +0000 | [diff] [blame] | 23 | if (optind + 1 != argc) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 24 | bb_show_usage(); |
Rob Landley | b5ca9e0 | 2005-12-02 17:54:01 +0000 | [diff] [blame] | 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; | ||||
Glenn L McGrath | 69f28e7 | 2003-04-26 04:56:17 +0000 | [diff] [blame] | 33 | } |
34 | |||||
Rob Landley | b5ca9e0 | 2005-12-02 17:54:01 +0000 | [diff] [blame] | 35 | puts(argv[optind]); |
Glenn L McGrath | 69f28e7 | 2003-04-26 04:56:17 +0000 | [diff] [blame] | 36 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 37 | return EXIT_SUCCESS; |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 38 | } |