From 565ef9b451d1adf14ad6cbc08bc5bf77388ec5c9 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 19 Jul 2019 13:58:58 -0400 Subject: implement in C --- mktemp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mktemp.c (limited to 'mktemp.c') diff --git a/mktemp.c b/mktemp.c new file mode 100644 index 0000000..14d615c --- /dev/null +++ b/mktemp.c @@ -0,0 +1,20 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + char template[FILENAME_MAX] = "tmp.XXXXXXXXXX"; + if (argc != 1) { + strcpy(template, argv[1]); + } + if (!strstr(template, "XXXXXX")) { + fprintf(stderr, "template must contain at least six 'X' characters\n"); + return 1; + } + rmdir(template); + printf("%s\n", mkdtemp(template)); + return 0; +} -- cgit v1.2.1