re PR libfortran/19052 (unit 0 not preconnected to standard error)
authorDavid Edelsohn <edelsohn@gnu.org>
Sun, 23 Jan 2005 00:14:31 +0000 (00:14 +0000)
committerDavid Edelsohn <dje@gcc.gnu.org>
Sun, 23 Jan 2005 00:14:31 +0000 (19:14 -0500)
        PR libgfortran/19052
        * libgfortran.h (options_t): Add stderr_unit.
        * io/io.h (error_stream): Declare.
        * io/open.c (new_unit): Do not terminate abnormally if opening
        file preconnected to stdin, stdout, or stderr.
        * io/unit.c (init_units): Initialize stderr_unit.
        * io/unix.c (error_stream): New function.
        * runtime/environ.c (GFORTRAN_STDERR_UNIT): New environment variable.

From-SVN: r94090

libgfortran/ChangeLog
libgfortran/io/io.h
libgfortran/io/open.c
libgfortran/io/unit.c
libgfortran/io/unix.c
libgfortran/libgfortran.h
libgfortran/runtime/environ.c

index 537415f..c2218fb 100644 (file)
@@ -1,3 +1,14 @@
+2005-01-22  David Edelsohn  <edelsohn@gnu.org>
+
+       PR libgfortran/19052
+       * libgfortran.h (options_t): Add stderr_unit.
+       * io/io.h (error_stream): Declare.
+       * io/open.c (new_unit): Do not terminate abnormally if opening
+       file preconnected to stdin, stdout, or stderr.
+       * io/unit.c (init_units): Initialize stderr_unit.
+       * io/unix.c (error_stream): New function.
+       * runtime/environ.c (GFORTRAN_STDERR_UNIT): New environment variable.
+
 2005-01-22  Thomas Koenig  <Thomas.Koenig@online.de>
 
        PR libfortran/18982
index 2975f9e..694ca1d 100644 (file)
@@ -395,6 +395,9 @@ internal_proto(input_stream);
 extern stream *output_stream (void);
 internal_proto(output_stream);
 
+extern stream *error_stream (void);
+internal_proto(error_stream);
+
 extern int compare_file_filename (stream *, const char *, int);
 internal_proto(compare_file_filename);
 
index 9c23131..eaeb5a2 100644 (file)
@@ -323,9 +323,14 @@ new_unit (unit_flags * flags)
       internal_error ("new_unit(): Bad status");
     }
 
-  /* Make sure the file isn't already open someplace else.  */
-
-  if (find_file () != NULL)
+  /* Make sure the file isn't already open someplace else.
+     Do not error if opening file preconnected to stdin, stdout, stderr.  */
+
+  u = find_file ();
+  if (u != NULL
+      && (options.stdin_unit < 0 || u->unit_number != options.stdin_unit)
+      && (options.stdout_unit < 0 || u->unit_number != options.stdout_unit)
+      && (options.stderr_unit < 0 || u->unit_number != options.stderr_unit))
     {
       generate_error (ERROR_ALREADY_OPEN, NULL);
       goto cleanup;
index bf68b78..ae0771f 100644 (file)
@@ -334,6 +334,27 @@ init_units (void)
       insert_unit (u);
     }
 
+  if (options.stderr_unit >= 0)
+    {                          /* STDERR */
+      u = get_mem (sizeof (gfc_unit));
+
+      u->unit_number = options.stderr_unit;
+      u->s = error_stream ();
+
+      u->flags.action = ACTION_WRITE;
+
+      u->flags.access = ACCESS_SEQUENTIAL;
+      u->flags.form = FORM_FORMATTED;
+      u->flags.status = STATUS_OLD;
+      u->flags.blank = BLANK_ZERO;
+      u->flags.position = POSITION_ASIS;
+
+      u->recl = options.default_recl;
+      u->endfile = AT_ENDFILE;
+
+      insert_unit (u);
+    }
+
   /* Calculate the maximum file offset in a portable manner.
    * max will be the largest signed number for the type gfc_offset.
    *
index daa0fb1..5dc31a5 100644 (file)
@@ -1160,7 +1160,7 @@ input_stream (void)
 }
 
 
-/* output_stream()-- Return a stream pointer to the default input stream.
+/* output_stream()-- Return a stream pointer to the default output stream.
  * Called on initialization. */
 
 stream *
@@ -1170,6 +1170,15 @@ output_stream (void)
 }
 
 
+/* error_stream()-- Return a stream pointer to the default error stream.
+ * Called on initialization. */
+
+stream *
+error_stream (void)
+{
+  return fd_to_stream (STDERR_FILENO, PROT_WRITE);
+}
+
 /* init_error_stream()-- Return a pointer to the error stream.  This
  * subroutine is called when the stream is needed, rather than at
  * initialization.  We want to work even if memory has been seriously
index ccafb7c..dfa2e40 100644 (file)
@@ -292,7 +292,7 @@ enum
 
 typedef struct
 {
-  int stdin_unit, stdout_unit, optional_plus;
+  int stdin_unit, stdout_unit, stderr_unit, optional_plus;
   int allocate_init_flag, allocate_init_value;
   int locus;
 
index 87fe565..ae82f56 100644 (file)
@@ -443,6 +443,11 @@ static variable variable_table[] = {
    "Unit number that will be preconnected to standard output\n"
    "(No preconnection if negative)"},
 
+  {"GFORTRAN_STDERR_UNIT", 0, &options.stderr_unit, init_integer,
+   show_integer,
+   "Unit number that will be preconnected to standard error\n"
+   "(No preconnection if negative)"},
+
   {"GFORTRAN_USE_STDERR", 1, &options.use_stderr, init_boolean,
    show_boolean,
    "Sends library output to standard error instead of standard output."},