diff --git a/ChangeLog b/ChangeLog index 9ff3579..cbbb5b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-07-18 Paolo Bonzini + + * sed.c (write_mode): New. + (main): Initialize it to "wb" if --binary is passed. + * sed.h (write_mode): New. + * compile.c (mark_subst_opts, compile_program): Use it instead + of "w". + * execute.c (open_next_file): Pass write_mode to ck_mkstemp. + * utils.c (ck_mkstemp): Accept mode, pass it to fdopen. Constify. + * utils.h (ck_mkstemp): Adjust prototype. + 2010-08-17 Paolo Bonzini Fix imprecision in the documentation of `D'. diff --git a/NEWS b/NEWS index 8f97886..89ea757 100644 --- a/NEWS +++ b/NEWS @@ -6,7 +6,8 @@ Sed 4.2.2 * New command `F' to print current input file name -* -i does not convert the input file to binary (LF-terminated) on Cygwin +* sed -i, s///w, and the `w' and `W' commands also obey the --binary option + (and create CR/LF-terminated files if the option is absent) * --posix fails for scripts (or fragments as passed to the -e option) that end in a backslash, as they are not portable. diff --git a/sed/compile.c b/sed/compile.c index 4e6c303..b842e1b 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -652,7 +652,7 @@ mark_subst_opts(cmd) break; case 'w': - cmd->outf = get_openfile(&file_write, "w", true); + cmd->outf = get_openfile(&file_write, write_mode, true); return flags; case '0': case '1': case '2': case '3': case '4': @@ -1262,7 +1262,7 @@ compile_program(vector) case 'W': case 'w': - cur_cmd->x.outf = get_openfile(&file_write, "w", true); + cur_cmd->x.outf = get_openfile(&file_write, write_mode, true); break; case 's': diff --git a/sed/execute.c b/sed/execute.c index af8c4d2..14fd4e4 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -767,7 +767,8 @@ open_next_file(name, input) } #endif - output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed"); + output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed", + write_mode); output_file.missing_newline = false; free (tmpdir); diff --git a/sed/sed.c b/sed/sed.c index 723958d..637722d 100644 --- a/sed/sed.c +++ b/sed/sed.c @@ -75,8 +75,9 @@ 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 files, either "rt" or "rb". */ +/* The mode to use to read/write files, either "rt"/"w" or "rb"/"wb". */ char *read_mode = "rt"; +char *write_mode = "w"; /* Do we need to be pedantically POSIX compliant? */ enum posixicity_types posixicity; @@ -284,6 +285,7 @@ main(argc, argv) case 'b': read_mode = "rb"; + write_mode = "wb"; break; /* Undocumented, for compatibility with BSD sed. */ diff --git a/sed/sed.h b/sed/sed.h index 6b4101d..f8ccccc 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -233,8 +233,9 @@ extern countT lcmd_out_line_len; /* How do we edit files in-place? (we don't if NULL) */ extern char *in_place_extension; -/* The mode to use to read files, either "rt" or "rb". */ +/* The mode to use to read and write files, either "rt"/"w" or "rb"/"wb". */ extern char *read_mode; +extern char *write_mode; /* Should we use EREs? */ extern bool use_extended_syntax_p; diff --git a/sed/utils.c b/sed/utils.c index 226089a..d5722f6 100644 --- a/sed/utils.c +++ b/sed/utils.c @@ -185,9 +185,10 @@ ck_fdopen(fd, name, mode, fail) } FILE * -ck_mkstemp (p_filename, tmpdir, base) +ck_mkstemp (p_filename, tmpdir, base, mode) char **p_filename; - char *base, *tmpdir; + const char *base, *tmpdir; + const char *mode; { char *template; FILE *fp; @@ -221,7 +222,7 @@ ck_mkstemp (p_filename, tmpdir, base) panic(_("couldn't open temporary file %s: %s"), template, strerror(errno)); *p_filename = template; - fp = fdopen (fd, "w"); + fp = fdopen (fd, mode); register_open_file (fp, template, true); return fp; } diff --git a/sed/utils.h b/sed/utils.h index d3f431d..aef8e65 100644 --- a/sed/utils.h +++ b/sed/utils.h @@ -30,7 +30,8 @@ void ck_fflush P_((FILE *stream)); void ck_fclose P_((FILE *stream)); const char *follow_symlink P_((const char *path)); size_t ck_getline P_((char **text, size_t *buflen, FILE *stream)); -FILE * ck_mkstemp P_((char **p_filename, char *tmpdir, char *base)); +FILE * ck_mkstemp P_((char **p_filename, const char *tmpdir, const char *base, + const char *mode)); void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail)); VOID *ck_malloc P_((size_t size));