use "w" or "wb" modes for sed -i, s///w, w' and W' depending on --binary

2010-07-18  Paolo Bonzini  <bonzini@gnu.org>

	* 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.
This commit is contained in:
Paolo Bonzini committed 2010-08-17 01:56:55 +02:00
1 parent e1c76b0344
commit 7355d316a5
8 files changed
+28 -10

No files matched your search

+11
View File
@@ -1,3 +1,14 @@
2010-07-18 Paolo Bonzini <bonzini@gnu.org>
* 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 <bonzini@gnu.org>
Fix imprecision in the documentation of `D'.
+2 -1
View File
@@ -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.
+2 -2
View File
@@ -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':
+2 -1
View File
@@ -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);
+3 -1
View File
@@ -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. */
+2 -1
View File
@@ -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;
+4 -3
View File
@@ -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;
}
+2 -1
View File
@@ -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));