blob: 495a2ea3af44b5ca17151a1b66af2e80b0cbd3e1 [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 *
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00009 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Erik Andersen227a59b2000-04-25 23:24:55 +000010 */
11
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000012#include "busybox.h"
Erik Andersen227a59b2000-04-25 23:24:55 +000013#include <stdio.h>
14#include <errno.h>
Eric Anderseneba8ed72001-03-09 14:36:42 +000015#include <string.h>
Eric Andersened3ef502001-01-27 08:24:39 +000016#include <unistd.h>
17#include <stdlib.h>
Erik Andersen227a59b2000-04-25 23:24:55 +000018
Rob Landleydfba7412006-03-06 20:47:33 +000019int mktemp_main(int argc, char **argv)
Erik Andersen227a59b2000-04-25 23:24:55 +000020{
Rob Landleyb5ca9e02005-12-02 17:54:01 +000021 unsigned long flags = bb_getopt_ulflags(argc, argv, "dq");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000022
Rob Landleyb5ca9e02005-12-02 17:54:01 +000023 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}