diff options
author | dje <dje@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-01-23 00:14:31 +0000 |
---|---|---|
committer | dje <dje@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-01-23 00:14:31 +0000 |
commit | ff81ee3b6e43e270bebd2400f3521f2d6da8cc59 (patch) | |
tree | 58334819ab2857c14b05d08b9782ac195c0413b5 /libgfortran/io | |
parent | 8e2779612f337c1cda856597cbed11d136a1209e (diff) | |
download | gcc-ff81ee3b6e43e270bebd2400f3521f2d6da8cc59.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94090 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/io.h | 3 | ||||
-rw-r--r-- | libgfortran/io/open.c | 11 | ||||
-rw-r--r-- | libgfortran/io/unit.c | 21 | ||||
-rw-r--r-- | libgfortran/io/unix.c | 11 |
4 files changed, 42 insertions, 4 deletions
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h index 2975f9e73ad..694ca1d7ac5 100644 --- a/libgfortran/io/io.h +++ b/libgfortran/io/io.h @@ -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); diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c index 9c23131f97e..eaeb5a298c0 100644 --- a/libgfortran/io/open.c +++ b/libgfortran/io/open.c @@ -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; diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index bf68b7880f1..ae0771f0816 100644 --- a/libgfortran/io/unit.c +++ b/libgfortran/io/unit.c @@ -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. * diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index daa0fb11072..5dc31a513d9 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -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 |