blob: c0d3a365d6c5a7b86d146ae27f98c05e74a559a4 [file] [log] [blame]
Erik Andersen227a59b2000-04-25 23:24:55 +00001/* 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 *
Rob Landleyb5ca9e02005-12-02 17:54:01 +00009 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Erik Andersen227a59b2000-04-25 23:24:55 +000010 */
11
Erik Andersen227a59b2000-04-25 23:24:55 +000012#include <stdio.h>
13#include <errno.h>
Eric Anderseneba8ed72001-03-09 14:36:42 +000014#include <string.h>
Eric Andersened3ef502001-01-27 08:24:39 +000015#include <unistd.h>
16#include <stdlib.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000017#include "busybox.h"
Erik Andersen227a59b2000-04-25 23:24:55 +000018
Erik Andersen227a59b2000-04-25 23:24:55 +000019extern int mktemp_main(int argc, char **argv)
20{
Rob Landleyb5ca9e02005-12-02 17:54:01 +000021 unsigned long flags = bb_getopt_ulflags(argc, argv, "dq");
22
23 if (optind + 1 != argc)
Manuel Novoa III cad53642003-03-19 09:13:01 +000024 bb_show_usage();
Rob Landleyb5ca9e02005-12-02 17:54:01 +000025
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 McGrath69f28e72003-04-26 04:56:17 +000033 }
34
Rob Landleyb5ca9e02005-12-02 17:54:01 +000035 puts(argv[optind]);
Glenn L McGrath69f28e72003-04-26 04:56:17 +000036
Matt Kraai3e856ce2000-12-01 02:55:13 +000037 return EXIT_SUCCESS;
Erik Andersen227a59b2000-04-25 23:24:55 +000038}