aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/open.c
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2014-09-17 00:40:28 +0300
committerJanne Blomqvist <jb@gcc.gnu.org>2014-09-17 00:40:28 +0300
commit0e05c303e5c3c7882d5e36a4d5b66f0563ae6478 (patch)
tree34b3e91356fc23c2feb76d92e78fad28bd83a126 /libgfortran/io/open.c
parent7425e424b5222704558591fc6cf26eaa57fb81de (diff)
downloadgcc-0e05c303e5c3c7882d5e36a4d5b66f0563ae6478.zip
gcc-0e05c303e5c3c7882d5e36a4d5b66f0563ae6478.tar.gz
gcc-0e05c303e5c3c7882d5e36a4d5b66f0563ae6478.tar.bz2
PR libfortran/62768 Handle filenames with embedded null characters.
testsuite ChangeLog: 2014-09-17 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/62768 * gfortran.dg/filename_null.f90: New test. libgfortran ChangeLog: 2014-09-17 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/62768 * io/io.h (gfc_unit): Store C string for the filename. * io/close.c (st_close): Use gfc_unit.filename. * io/inquire.c (inquire_via_unit): Likewise. * io/open.c (new_unit): Likewise. (already_open): Likewise, unlink file before freeing filename. * io/unit.c (init_units): Likewise. (close_unit_1): Likewise. (filename_from_unit): Likewise. * io/unix.c (compare_file_filename): Likewise. (find_file0): Likewise. (delete_file): Likewise. From-SVN: r215307
Diffstat (limited to 'libgfortran/io/open.c')
-rw-r--r--libgfortran/io/open.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index b803859..67fa9ac 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -541,7 +541,6 @@ new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags * flags)
/* Create the unit structure. */
- u->file = xmalloc (opp->file_len);
if (u->unit_number != opp->common.unit)
internal_error (&opp->common, "Unit number changed");
u->s = s;
@@ -618,8 +617,7 @@ new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags * flags)
u->strm_pos = stell (u->s) + 1;
}
- memmove (u->file, opp->file, opp->file_len);
- u->file_len = opp->file_len;
+ u->filename = fc_strdup (opp->file, opp->file_len);
/* Curiously, the standard requires that the
position specifier be ignored for new files so a newly connected
@@ -685,20 +683,13 @@ already_open (st_parameter_open *opp, gfc_unit * u, unit_flags * flags)
}
u->s = NULL;
- free (u->file);
- u->file = NULL;
- u->file_len = 0;
-
+
#if !HAVE_UNLINK_OPEN_FILE
- char *path = NULL;
- if (u->file && u->flags.status == STATUS_SCRATCH)
- path = fc_strdup (u->file, u->file_len);
- if (path != NULL)
- {
- unlink (path);
- free (path);
- }
+ if (u->filename && u->flags.status == STATUS_SCRATCH)
+ unlink (u->filename);
#endif
+ free (u->filename);
+ u->filename = NULL;
u = new_unit (opp, u, flags);
if (u != NULL)