xref: /netbsd-src/external/gpl3/gdb/dist/gnulib/import/mkdtemp.c (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
1*4b169a6bSchristos /* Copyright (C) 1999, 2001-2003, 2006-2007, 2009-2022 Free Software
28dffb485Schristos    Foundation, Inc.
38dffb485Schristos    This file is part of the GNU C Library.
48dffb485Schristos 
5*4b169a6bSchristos    This file is free software: you can redistribute it and/or modify
6*4b169a6bSchristos    it under the terms of the GNU Lesser General Public License as
7*4b169a6bSchristos    published by the Free Software Foundation; either version 2.1 of the
8*4b169a6bSchristos    License, or (at your option) any later version.
98dffb485Schristos 
10*4b169a6bSchristos    This file is distributed in the hope that it will be useful,
118dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
128dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*4b169a6bSchristos    GNU Lesser General Public License for more details.
148dffb485Schristos 
15*4b169a6bSchristos    You should have received a copy of the GNU Lesser General Public License
168dffb485Schristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
178dffb485Schristos 
188dffb485Schristos /* Extracted from misc/mkdtemp.c.  */
198dffb485Schristos 
208dffb485Schristos #include <config.h>
218dffb485Schristos 
228dffb485Schristos /* Specification.  */
238dffb485Schristos #include <stdlib.h>
248dffb485Schristos 
258dffb485Schristos #include "tempname.h"
268dffb485Schristos 
278dffb485Schristos /* Generate a unique temporary directory from XTEMPLATE.
288dffb485Schristos    The last six characters of XTEMPLATE must be "XXXXXX";
298dffb485Schristos    they are replaced with a string that makes the filename unique.
308dffb485Schristos    The directory is created, mode 700, and its name is returned.
318dffb485Schristos    (This function comes from OpenBSD.) */
328dffb485Schristos char *
mkdtemp(char * xtemplate)338dffb485Schristos mkdtemp (char *xtemplate)
348dffb485Schristos {
358dffb485Schristos   if (gen_tempname (xtemplate, 0, 0, GT_DIR))
368dffb485Schristos     return NULL;
378dffb485Schristos   else
388dffb485Schristos     return xtemplate;
398dffb485Schristos }
40