X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=libiberty%2Fmake-temp-file.c;h=cb08c27af6f4534be0116224946d036ecd5a8418;hb=13aa5ceb01cc94a0e617f397c0c5434fc22bb1e5;hp=98e215d15e79b666d99ce75316b723f2786c166b;hpb=e495212d229d58eb4d70c94d7f828a04c386c3b2;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/make-temp-file.c b/libiberty/make-temp-file.c index 98e215d15e..cb08c27af6 100644 --- a/libiberty/make-temp-file.c +++ b/libiberty/make-temp-file.c @@ -1,5 +1,5 @@ /* Utility to pick a temporary filename prefix. - Copyright (C) 1996-2017 Free Software Foundation, Inc. + Copyright (C) 1996-2020 Free Software Foundation, Inc. This file is part of the libiberty library. Libiberty is free software; you can redistribute it and/or @@ -56,7 +56,7 @@ extern int mkstemps (char *, int); /* Name of temporary file. mktemp requires 6 trailing X's. */ -#define TEMP_FILE "ccXXXXXX" +#define TEMP_FILE "XXXXXX" #define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1) #if !defined(_WIN32) || defined(__CYGWIN__) @@ -181,25 +181,31 @@ string is @code{malloc}ed, and the temporary file has been created. */ char * -make_temp_file (const char *suffix) +make_temp_file_with_prefix (const char *prefix, const char *suffix) { const char *base = choose_tmpdir (); char *temp_filename; - int base_len, suffix_len; + int base_len, suffix_len, prefix_len; int fd; + if (prefix == 0) + prefix = "cc"; + if (suffix == 0) suffix = ""; base_len = strlen (base); + prefix_len = strlen (prefix); suffix_len = strlen (suffix); temp_filename = XNEWVEC (char, base_len + TEMP_FILE_LEN - + suffix_len + 1); + + suffix_len + + prefix_len + 1); strcpy (temp_filename, base); - strcpy (temp_filename + base_len, TEMP_FILE); - strcpy (temp_filename + base_len + TEMP_FILE_LEN, suffix); + strcpy (temp_filename + base_len, prefix); + strcpy (temp_filename + base_len + prefix_len, TEMP_FILE); + strcpy (temp_filename + base_len + prefix_len + TEMP_FILE_LEN, suffix); fd = mkstemps (temp_filename, suffix_len); /* Mkstemps failed. It may be EPERM, ENOSPC etc. */ @@ -214,3 +220,9 @@ make_temp_file (const char *suffix) abort (); return temp_filename; } + +char * +make_temp_file (const char *suffix) +{ + return make_temp_file_with_prefix (NULL, suffix); +}