1997-08-22 06:57:35 +08:00
|
|
|
/* Utility to pick a temporary filename prefix.
|
1998-02-26 07:09:55 +08:00
|
|
|
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
|
1997-08-22 06:57:35 +08:00
|
|
|
|
|
|
|
This file is part of the libiberty library.
|
|
|
|
Libiberty is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
Libiberty is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with libiberty; see the file COPYING.LIB. If not,
|
|
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
1998-12-14 15:01:03 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
1998-01-18 05:23:29 +08:00
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1998-12-14 15:01:03 +08:00
|
|
|
#include <stdio.h> /* May get P_tmpdir. */
|
1998-12-22 14:57:17 +08:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
1999-07-15 01:29:38 +08:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
1997-08-22 06:57:35 +08:00
|
|
|
|
1998-11-27 18:28:57 +08:00
|
|
|
#include "libiberty.h"
|
2001-03-21 15:29:37 +08:00
|
|
|
extern char *choose_tmpdir PARAMS ((void));
|
1997-08-22 06:57:35 +08:00
|
|
|
|
|
|
|
/* Name of temporary file.
|
|
|
|
mktemp requires 6 trailing X's. */
|
|
|
|
#define TEMP_FILE "ccXXXXXX"
|
2001-03-21 15:29:37 +08:00
|
|
|
#define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1)
|
1997-08-22 06:57:35 +08:00
|
|
|
|
Makefile.in (TEXIFILES): Add fnmatch.txh.
* Makefile.in (TEXIFILES): Add fnmatch.txh.
(maint-undoc): New.
maint-tool: Add "undoc" tool.
* alloca.c, argv.c, asprintf.c, choose-temp.c, concat.c,
fdmatch.c, ffs.c, getruntime.c, insque.c, lbasename.c,
make-temp-file.c, mkstemps.c, pexecute.c, random.c, spaces.c,
strerror.s, strsignal.c, strtol.c, vasprintf.c: Add or update
documentation.
* fnmatch.txh: New.
* functions.texi: Regenerate.
From-SVN: r46274
2001-10-16 10:50:13 +08:00
|
|
|
/*
|
1998-09-05 19:09:09 +08:00
|
|
|
|
argv.c, [...]: Improve manual formatting.
* argv.c, asprintf.c, choose-temp.c, concat.c, cplus-dem.c,
ffs.c, fnmatch.txh, getruntime.c, make-temp-file.c,
mkstemps.c, pexecute.c, random.c, strsitnal.c, vasprintf.c:
Improve manual formatting.
* functions.texi: Regenerate.
From-SVN: r46323
2001-10-18 05:15:41 +08:00
|
|
|
@deftypefn Extension char* choose_temp_base (void)
|
Makefile.in (TEXIFILES): Add fnmatch.txh.
* Makefile.in (TEXIFILES): Add fnmatch.txh.
(maint-undoc): New.
maint-tool: Add "undoc" tool.
* alloca.c, argv.c, asprintf.c, choose-temp.c, concat.c,
fdmatch.c, ffs.c, getruntime.c, insque.c, lbasename.c,
make-temp-file.c, mkstemps.c, pexecute.c, random.c, spaces.c,
strerror.s, strsignal.c, strtol.c, vasprintf.c: Add or update
documentation.
* fnmatch.txh: New.
* functions.texi: Regenerate.
From-SVN: r46274
2001-10-16 10:50:13 +08:00
|
|
|
|
|
|
|
Return a prefix for temporary file names or @code{NULL} if unable to
|
|
|
|
find one. The current directory is chosen if all else fails so the
|
|
|
|
program is exited if a temporary directory can't be found (@code{mktemp}
|
|
|
|
fails). The buffer for the result is obtained with @code{xmalloc}.
|
|
|
|
|
|
|
|
This function is provided for backwards compatability only. Its use is
|
|
|
|
not recommended.
|
|
|
|
|
|
|
|
@end deftypefn
|
|
|
|
|
|
|
|
*/
|
1997-08-22 06:57:35 +08:00
|
|
|
|
|
|
|
char *
|
|
|
|
choose_temp_base ()
|
|
|
|
{
|
2001-03-21 15:29:37 +08:00
|
|
|
const char *base = choose_tmpdir ();
|
1997-08-22 06:57:35 +08:00
|
|
|
char *temp_filename;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen (base);
|
2001-03-21 15:29:37 +08:00
|
|
|
temp_filename = xmalloc (len + TEMP_FILE_LEN + 1);
|
1997-08-22 06:57:35 +08:00
|
|
|
strcpy (temp_filename, base);
|
|
|
|
strcpy (temp_filename + len, TEMP_FILE);
|
|
|
|
|
|
|
|
mktemp (temp_filename);
|
|
|
|
if (strlen (temp_filename) == 0)
|
|
|
|
abort ();
|
|
|
|
return temp_filename;
|
|
|
|
}
|