This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA]: Add make_cwd_temp_file to libiberty


This patch is a new feature in libiberty to allow temporary files
to be created in $CWD.

It was introduced by this patch
http://gcc.gnu.org/ml/gcc-patches/2008-10/msg01200.html in the
context of this thread http://gcc.gnu.org/ml/gcc-patches/2008-10/msg01032.html

Ian reviewed it for the LTO branch, but now I would like to port
it to mainline.  The new function will be used later by other LTO
patches.

OK for mainline and src?  Tested on x86_64.


Diego.


include/ChangeLog

2009-04-17  Simon Baldwin  <simonb@google.com>

	* libiberty.h (make_cwd_temp_file): New declaration.


libiberty/ChangeLog

2009-04-17  Simon Baldwin  <simonb@google.com>

	* make-temp-file.c (make_temp_file_common): Split out from original
	make_temp_file() function.
	* (make_temp_file): Call make_temp_file_common() with tmp dir.
	* (make_cwd_temp_file): New.  Call make_temp_file_common() with "./".

Index: include/libiberty.h
===================================================================
--- include/libiberty.h	(revision 146200)
+++ include/libiberty.h	(working copy)
@@ -215,6 +215,7 @@ extern char *choose_temp_base (void) ATT
 /* Return a temporary file name or NULL if unable to create one.  */

 extern char *make_temp_file (const char *) ATTRIBUTE_MALLOC;
+extern char *make_cwd_temp_file (const char *) ATTRIBUTE_MALLOC;

 /* Remove a link to a file unless it is special. */

Index: libiberty/make-temp-file.c
===================================================================
--- libiberty/make-temp-file.c	(revision 146200)
+++ libiberty/make-temp-file.c	(working copy)
@@ -85,6 +85,7 @@ static const char usrtmp[] =
 { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
 static const char vartmp[] =
 { DIR_SEPARATOR, 'v', 'a', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
+static const char cwd[] = { '.', DIR_SEPARATOR, 0 };

 #endif

@@ -158,22 +159,15 @@ choose_tmpdir (void)
   return memoized_tmpdir;
 }

-/*
-
-@deftypefn Replacement char* make_temp_file (const char *@var{suffix})
-
-Return a temporary file name (as a string) or @code{NULL} if unable to
-create one.  @var{suffix} is a suffix to append to the file name.  The
-string is @code{malloc}ed, and the temporary file has been created.
-
-@end deftypefn
-
-*/
+/* Common function to create temporary files.
+   Returns a temporary file name (as a string) or NULL if unable to
+   create one.  SUFFIX is a suffix to append to the file name, and BASE
+   is a prefix.  The return string is allocated, and the temporary file
+   created before returning.  */

 char *
-make_temp_file (const char *suffix)
+make_temp_file_common (const char *suffix, const char *base)
 {
-  const char *base = choose_tmpdir ();
   char *temp_filename;
   int base_len, suffix_len;
   int fd;
@@ -204,3 +198,41 @@ make_temp_file (const char *suffix)
     abort ();
   return temp_filename;
 }
+
+/*
+
+@deftypefn Replacement char* make_temp_file (const char *@var{suffix})
+
+Return a temporary file name (as a string) or @code{NULL} if unable to
+create one.  @var{suffix} is a suffix to append to the file name.  The
+string is @code{malloc}ed, and the temporary file has been created.  The
+temporary file is created in an appropriate temporary directory.
+
+@end deftypefn
+
+*/
+
+char *
+make_temp_file (const char *suffix)
+{
+  return make_temp_file_common (suffix, choose_tmpdir ());
+}
+
+/*
+
+@deftypefn Supplemental char* make_cwd_temp_file (const char *@var{suffix})
+
+Return a temporary file name (as a string) or @code{NULL} if unable to
+create one.  @var{suffix} is a suffix to append to the file name.  The
+string is @code{malloc}ed, and the temporary file has been created.  The
+temporary file is created in the current working directory.
+
+@end deftypefn
+
+*/
+
+char *
+make_cwd_temp_file (const char *suffix)
+{
+  return make_temp_file_common (suffix, cwd);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]