diff options
author | Paolo Bonzini <bonzini@gnu.org> | 2012-02-13 15:46:14 +0100 |
---|---|---|
committer | Paolo Bonzini <bonzini@gnu.org> | 2012-03-16 08:50:10 +0100 |
commit | 8d489fa8cbc0b25cc72cf3f23f1d6eec71a185b9 (patch) | |
tree | 48e0c4b6d5efc478cb864e3cf926649ddd940023 | |
parent | ee2a5bd0faa19f57107a1f3d17a6bc99600436a7 (diff) | |
download | sed-8d489fa8cbc0b25cc72cf3f23f1d6eec71a185b9.tar.gz |
do not open input files with "rt" mode, do not assume "rt" is supported
2012-02-13 Paolo Bonzini <bonzini@gnu.org>
* configure.ac: Test whether fopen("foo", "rt") works.
* sed/compile.c: Do not open scripts with "rt" mode if it doesn't.
* sed/sed.c: Never open input files with "rt" mode.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | configure.ac | 24 | ||||
-rw-r--r-- | sed/compile.c | 8 | ||||
-rw-r--r-- | sed/sed.c | 4 |
4 files changed, 39 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2012-02-13 Paolo Bonzini <bonzini@gnu.org> + + * configure.ac: Test whether fopen("foo", "rt") works. + * sed/compile.c: Do not open scripts with "rt" mode if it doesn't. + * sed/sed.c: Never open input files with "rt" mode. + 2012-02-05 Paolo Bonzini <bonzini@gnu.org> Jim Hill <gjthill@gmail.com> diff --git a/configure.ac b/configure.ac index 673e4f5..bd4a305 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,30 @@ AC_PROG_CC gl_EARLY gl_INIT gl_DISABLE_THREADS +AC_CACHE_CHECK([whether "rt" can be used with fopen], [sed_cv_fopen_rt], [ +AC_TRY_RUN([ +#include <stdio.h> +#include <errno.h> + +int main() +{ + FILE *fp; + int result; + errno = 0; + fp = fopen ("conftest.c", "rt"); + if (fp) fclose (fp); + return fp ? 0 : 1; +}], [sed_cv_fopen_rt=yes], + [sed_cv_fopen_rt=no], + [case $host in + *cygwin* | *mingw*) sed_cv_fopen_rt=yes ;; + *) sed_cv_fopen_rt='assuming no' ;; + esac])]) +if test "$sed_cv_fopen_rt" = yes; then + AC_DEFINE([HAVE_FOPEN_RT], [1], + [Defined if "rt" can be used as a mode to fopen.]) +fi + AC_CACHE_CHECK([whether -lcP is needed], [sed_cv_libcp_needed], [ AC_TRY_RUN([ #include <stdio.h> diff --git a/sed/compile.c b/sed/compile.c index de2984c..61c45f7 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -1610,7 +1610,13 @@ compile_file(cur_program, cmdfile) prog.file = stdin; if (cmdfile[0] != '-' || cmdfile[1] != '\0') - prog.file = ck_fopen(cmdfile, "rt", true); + { +#ifdef HAVE_FOPEN_RT + prog.file = ck_fopen(cmdfile, "rt", true); +#else + prog.file = ck_fopen(cmdfile, "r", true); +#endif + } cur_input.line = 1; cur_input.name = cmdfile; @@ -84,8 +84,8 @@ bool follow_symlinks = false; /* How do we edit files in-place? (we don't if NULL) */ char *in_place_extension = NULL; -/* The mode to use to read/write files, either "rt"/"w" or "rb"/"wb". */ -char *read_mode = "rt"; +/* The mode to use to read/write files, either "r"/"w" or "rb"/"wb". */ +char *read_mode = "r"; char *write_mode = "w"; /* Do we need to be pedantically POSIX compliant? */ |