aboutsummaryrefslogtreecommitdiff
path: root/editors/sed.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/sed.c')
-rw-r--r--editors/sed.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 7950b9303..1b6ed2b0f 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -135,7 +135,7 @@ static sed_cmd_t sed_cmd_head;
135static sed_cmd_t *sed_cmd_tail = &sed_cmd_head; 135static sed_cmd_t *sed_cmd_tail = &sed_cmd_head;
136 136
137/* Linked list of append lines */ 137/* Linked list of append lines */
138static struct append_list { 138struct append_list {
139 char *string; 139 char *string;
140 struct append_list *next; 140 struct append_list *next;
141}; 141};
@@ -1187,10 +1187,7 @@ extern int sed_main(int argc, char **argv)
1187 * files were specified or '-' was specified, take input from stdin. 1187 * files were specified or '-' was specified, take input from stdin.
1188 * Otherwise, we process all the files specified. */ 1188 * Otherwise, we process all the files specified. */
1189 if (argv[optind] == NULL) { 1189 if (argv[optind] == NULL) {
1190 if(in_place) { 1190 if(in_place) bb_error_msg_and_die("Filename required for -i");
1191 fprintf(stderr,"sed: Filename required for -i\n");
1192 exit(1);
1193 }
1194 add_input_file(stdin); 1191 add_input_file(stdin);
1195 process_files(); 1192 process_files();
1196 } else { 1193 } else {
@@ -1206,14 +1203,16 @@ extern int sed_main(int argc, char **argv)
1206 if (file) { 1203 if (file) {
1207 if(in_place) { 1204 if(in_place) {
1208 struct stat statbuf; 1205 struct stat statbuf;
1206 int nonstdoutfd;
1207
1209 outname=bb_xstrndup(argv[i],strlen(argv[i])+6); 1208 outname=bb_xstrndup(argv[i],strlen(argv[i])+6);
1210 strcat(outname,"XXXXXX"); 1209 strcat(outname,"XXXXXX");
1211 mkstemp(outname); 1210 if(-1==(nonstdoutfd=mkstemp(outname)))
1212 nonstdout=bb_wfopen(outname,"w"); 1211 bb_error_msg_and_die("no temp file");
1212 nonstdout=fdopen(nonstdoutfd,"w");
1213 /* Set permissions of output file */ 1213 /* Set permissions of output file */
1214 fstat(fileno(file),&statbuf); 1214 fstat(fileno(file),&statbuf);
1215 fchmod(fileno(nonstdout),statbuf.st_mode); 1215 fchmod(nonstdoutfd,statbuf.st_mode);
1216 atexit(cleanup_outname);
1217 add_input_file(file); 1216 add_input_file(file);
1218 process_files(); 1217 process_files();
1219 fclose(nonstdout); 1218 fclose(nonstdout);