1*1aa88f2bSmillert /* $OpenBSD: mkdtemp.c,v 1.2 2024/03/01 21:30:40 millert Exp $ */
22ce65aaeSmillert /*
32ce65aaeSmillert * Copyright (c) 2024 Todd C. Miller
42ce65aaeSmillert *
52ce65aaeSmillert * Permission to use, copy, modify, and distribute this software for any
62ce65aaeSmillert * purpose with or without fee is hereby granted, provided that the above
72ce65aaeSmillert * copyright notice and this permission notice appear in all copies.
82ce65aaeSmillert *
92ce65aaeSmillert * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
102ce65aaeSmillert * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
112ce65aaeSmillert * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
122ce65aaeSmillert * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
132ce65aaeSmillert * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
142ce65aaeSmillert * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
152ce65aaeSmillert * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
162ce65aaeSmillert */
172ce65aaeSmillert
182ce65aaeSmillert #include <sys/stat.h>
192ce65aaeSmillert #include <stdlib.h>
202ce65aaeSmillert
212ce65aaeSmillert static int
mkdtemp_cb(const char * path,int flags)222ce65aaeSmillert mkdtemp_cb(const char *path, int flags)
232ce65aaeSmillert {
242ce65aaeSmillert return mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR);
252ce65aaeSmillert }
262ce65aaeSmillert
272ce65aaeSmillert char *
mkdtemp(char * path)282ce65aaeSmillert mkdtemp(char *path)
292ce65aaeSmillert {
302ce65aaeSmillert if (__mktemp4(path, 0, 0, mkdtemp_cb) == 0)
312ce65aaeSmillert return path;
322ce65aaeSmillert return NULL;
332ce65aaeSmillert }
34*1aa88f2bSmillert
35*1aa88f2bSmillert char *
mkdtemps(char * path,int slen)36*1aa88f2bSmillert mkdtemps(char *path, int slen)
37*1aa88f2bSmillert {
38*1aa88f2bSmillert if (__mktemp4(path, slen, 0, mkdtemp_cb) == 0)
39*1aa88f2bSmillert return path;
40*1aa88f2bSmillert return NULL;
41*1aa88f2bSmillert }
42