aboutsummaryrefslogtreecommitdiff
path: root/editors/sed.c
diff options
context:
space:
mode:
authorGravatar Denys Vlasenko <vda.linux@googlemail.com>2016-01-24 15:52:16 +0100
committerGravatar Denys Vlasenko <vda.linux@googlemail.com>2016-01-24 15:52:16 +0100
commit2a4bba3ce2e00e55e6690fa8ba2607679277eed4 (patch)
treee26381d4a648bb3834272b02849602ff240d1d78 /editors/sed.c
parenteb5091070f6876993d868d2b2bb49b4b4d3ed002 (diff)
downloadbusybox-2a4bba3ce2e00e55e6690fa8ba2607679277eed4.tar.gz
busybox-2a4bba3ce2e00e55e6690fa8ba2607679277eed4.tar.bz2
sed: make 's///w FILE' actually write to FILE. Closes 8251
function old new delta add_cmd 1167 1210 +43 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors/sed.c')
-rw-r--r--editors/sed.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/editors/sed.c b/editors/sed.c
index a8c35388b..4c7f75521 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -113,7 +113,7 @@ typedef struct sed_cmd_s {
int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */
int end_line_orig;
- FILE *sw_file; /* File (sw) command writes to, -1 for none. */
+ FILE *sw_file; /* File (sw) command writes to, NULL for none. */
char *string; /* Data string for (saicytb) commands. */
unsigned which_match; /* (s) Which match to replace (0 for all) */
@@ -179,7 +179,7 @@ static void sed_free_and_close_stuff(void)
sed_cmd_t *sed_cmd_next = sed_cmd->next;
if (sed_cmd->sw_file)
- xprint_and_close_file(sed_cmd->sw_file);
+ fclose(sed_cmd->sw_file);
if (sed_cmd->beg_match) {
regfree(sed_cmd->beg_match);
@@ -426,8 +426,11 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
/* Write to file */
case 'w':
{
- char *temp;
- idx += parse_file_cmd(/*sed_cmd,*/ substr+idx, &temp);
+ char *fname;
+ idx += parse_file_cmd(/*sed_cmd,*/ substr+idx+1, &fname);
+ sed_cmd->sw_file = xfopen_for_write(fname);
+ sed_cmd->sw_last_char = '\n';
+ free(fname);
break;
}
/* Ignore case (gnu exension) */