diff --git a/ChangeLog b/ChangeLog index ae9f998..335351a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-02-13 Paolo Bonzini + + * 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 Jim Hill 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 +#include + +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 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; diff --git a/sed/sed.c b/sed/sed.c index 91f5668..ac58dea 100644 --- a/sed/sed.c +++ b/sed/sed.c @@ -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? */