From 69f28e7c0c2fb0f0efddad47310743d12a2b94d3 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Sat, 26 Apr 2003 04:56:17 +0000 Subject: Add the -d option, its used by old versions of config.guess, change to use getopt. --- debianutils/mktemp.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'debianutils') diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 9d8de21..ecc985f 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c @@ -31,10 +31,33 @@ extern int mktemp_main(int argc, char **argv) { - if (argc != 2 && (argc != 3 || strcmp(argv[1], "-q"))) + unsigned char dir_flag = 0; + int opt; + + while ((opt = getopt(argc, argv, "qd")) != -1) { + if (opt == 'd') { + dir_flag = 1; + } + else if (opt != 'q') { + bb_show_usage(); + } + } + + if (optind + 1 != argc) { bb_show_usage(); - if(mkstemp(argv[argc-1]) < 0) - return EXIT_FAILURE; + } + + if (dir_flag) { + if (mkdtemp(argv[argc-1]) == NULL) { + return EXIT_FAILURE; + } + } else { + if (mkstemp(argv[argc-1]) < 0) { + return EXIT_FAILURE; + } + } + (void) puts(argv[argc-1]); + return EXIT_SUCCESS; } -- cgit v1.1