]> git.saurik.com Git - bison.git/commitdiff
* subpipe.c (init_subpipe): Check the environment variables
authorJuan Manuel Guerrero <juan.guerrero@gmx.de>
Wed, 6 Feb 2008 09:58:56 +0000 (09:58 +0000)
committerJuan Manuel Guerrero <juan.guerrero@gmx.de>
Wed, 6 Feb 2008 09:58:56 +0000 (09:58 +0000)
TMPDIR, TMP and TEMP, in that order, to determinate where the temp
files shall be created.  Before trying to use the temp dir where the
environment variable points to check that the dir really exists. If
not default to the cwd as temp dir.  Copyright timestamp adjusted.

djgpp/subpipe.c

index 881ebaa2f141229af0c3e4ccf33e7aa313fe27e3..955dcd2e7a633ee8d290736b54d09033da5ea2d0 100644 (file)
@@ -1,6 +1,6 @@
 /* Subprocesses with pipes.
 
 /* Subprocesses with pipes.
 
-   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -67,15 +67,26 @@ static char tmp_file_name[2][L_tmpnam];
 void
 init_subpipe(void)
 {
 void
 init_subpipe(void)
 {
+  char *tmpdir;
   int fd;
 
   int fd;
 
-  strcpy(tmp_file_name[0], "/dev/env/TMPDIR/bnXXXXXX");
+  tmpdir = getenv("TMPDIR");
+  if (tmpdir == NULL)
+    tmpdir = getenv("TMP");
+  if (tmpdir == NULL)
+    tmpdir = getenv("TEMP");
+  if (access(tmpdir, D_OK))
+    tmpdir = ".";
+
+  strcpy(tmp_file_name[0], tmpdir);
+  strcat(tmp_file_name[0], "/bnXXXXXX");
   fd = mkstemp(tmp_file_name[0]);
   if (fd < 0)
     error(EXIT_FAILURE, 0, _("creation of a temporary file failed"));
   close (fd);
 
   fd = mkstemp(tmp_file_name[0]);
   if (fd < 0)
     error(EXIT_FAILURE, 0, _("creation of a temporary file failed"));
   close (fd);
 
-  strcpy(tmp_file_name[1], "/dev/env/TMPDIR/bnXXXXXX");
+  strcpy(tmp_file_name[1], tmpdir);
+  strcat(tmp_file_name[1], "/bnXXXXXX");
   fd = mkstemp(tmp_file_name[1]);
   if (fd < 0)
     error(EXIT_FAILURE, 0, _("creation of a temporary file failed"));
   fd = mkstemp(tmp_file_name[1]);
   if (fd < 0)
     error(EXIT_FAILURE, 0, _("creation of a temporary file failed"));