aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/diff.c27
-rw-r--r--editors/sed.c9
-rw-r--r--editors/vi.c1
3 files changed, 31 insertions, 6 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 07594e8d8..a3ca2b660 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -121,6 +121,7 @@ typedef struct FILE_and_pos_t {
121struct globals { 121struct globals {
122 smallint exit_status; 122 smallint exit_status;
123 int opt_U_context; 123 int opt_U_context;
124 const char *other_dir;
124 char *label[2]; 125 char *label[2];
125 struct stat stb[2]; 126 struct stat stb[2];
126}; 127};
@@ -760,9 +761,11 @@ static int FAST_FUNC add_to_dirlist(const char *filename,
760 void *userdata, int depth UNUSED_PARAM) 761 void *userdata, int depth UNUSED_PARAM)
761{ 762{
762 struct dlist *const l = userdata; 763 struct dlist *const l = userdata;
764 const char *file = filename + l->len;
765 while (*file == '/')
766 file++;
763 l->dl = xrealloc_vector(l->dl, 6, l->e); 767 l->dl = xrealloc_vector(l->dl, 6, l->e);
764 /* + 1 skips "/" after dirname */ 768 l->dl[l->e] = xstrdup(file);
765 l->dl[l->e] = xstrdup(filename + l->len + 1);
766 l->e++; 769 l->e++;
767 return TRUE; 770 return TRUE;
768} 771}
@@ -778,6 +781,25 @@ static int FAST_FUNC skip_dir(const char *filename,
778 add_to_dirlist(filename, sb, userdata, depth); 781 add_to_dirlist(filename, sb, userdata, depth);
779 return SKIP; 782 return SKIP;
780 } 783 }
784 if (!(option_mask32 & FLAG(N))) {
785 /* -r without -N: no need to recurse into dirs
786 * which do not exist on the "other side".
787 * Testcase: diff -r /tmp /
788 * (it would recurse deep into /proc without this code) */
789 struct dlist *const l = userdata;
790 filename += l->len;
791 if (filename[0]) {
792 struct stat osb;
793 char *othername = concat_path_file(G.other_dir, filename);
794 int r = stat(othername, &osb);
795 free(othername);
796 if (r != 0 || !S_ISDIR(osb.st_mode)) {
797 /* other dir doesn't have similarly named
798 * directory, don't recurse */
799 return SKIP;
800 }
801 }
802 }
781 return TRUE; 803 return TRUE;
782} 804}
783 805
@@ -791,6 +813,7 @@ static void diffdir(char *p[2], const char *s_start)
791 /*list[i].s = list[i].e = 0; - memset did it */ 813 /*list[i].s = list[i].e = 0; - memset did it */
792 /*list[i].dl = NULL; */ 814 /*list[i].dl = NULL; */
793 815
816 G.other_dir = p[1 - i];
794 /* We need to trim root directory prefix. 817 /* We need to trim root directory prefix.
795 * Using list.len to specify its length, 818 * Using list.len to specify its length,
796 * add_to_dirlist will remove it. */ 819 * add_to_dirlist will remove it. */
diff --git a/editors/sed.c b/editors/sed.c
index 28f0c7318..7af8f867a 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1333,7 +1333,6 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1333 if (opt & OPT_in_place) 1333 if (opt & OPT_in_place)
1334 bb_error_msg_and_die(bb_msg_requires_arg, "-i"); 1334 bb_error_msg_and_die(bb_msg_requires_arg, "-i");
1335 add_input_file(stdin); 1335 add_input_file(stdin);
1336 process_files();
1337 } else { 1336 } else {
1338 int i; 1337 int i;
1339 FILE *file; 1338 FILE *file;
@@ -1379,9 +1378,13 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1379 free(G.outname); 1378 free(G.outname);
1380 G.outname = NULL; 1379 G.outname = NULL;
1381 } 1380 }
1382 if (G.input_file_count > G.current_input_file) 1381 /* Here, to handle "sed 'cmds' nonexistent_file" case we did:
1383 process_files(); 1382 * if (G.current_input_file >= G.input_file_count)
1383 * return status;
1384 * but it's not needed since process_files() works correctly
1385 * in this case too. */
1384 } 1386 }
1387 process_files();
1385 1388
1386 return status; 1389 return status;
1387} 1390}
diff --git a/editors/vi.c b/editors/vi.c
index 9b050e115..0f412c362 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2385,7 +2385,6 @@ static int file_write(char *fn, char *first, char *last)
2385 status_line_bold("No current filename"); 2385 status_line_bold("No current filename");
2386 return -2; 2386 return -2;
2387 } 2387 }
2388 charcnt = 0;
2389 /* By popular request we do not open file with O_TRUNC, 2388 /* By popular request we do not open file with O_TRUNC,
2390 * but instead ftruncate() it _after_ successful write. 2389 * but instead ftruncate() it _after_ successful write.
2391 * Might reduce amount of data lost on power fail etc. 2390 * Might reduce amount of data lost on power fail etc.