projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hush: remove superfluous assignment
[oweals/busybox.git]
/
editors
/
patch.c
diff --git
a/editors/patch.c
b/editors/patch.c
index d5f6df2752241fce58bef1d06cade7ef6368fada..4a97151449751e5fc21c8d1369aaf28110ac679b 100644
(file)
--- a/
editors/patch.c
+++ b/
editors/patch.c
@@
-74,12
+74,18
@@
int patch_main(int argc UNUSED_PARAM, char **argv)
int patch_level;
int ret = 0;
char plus = '+';
int patch_level;
int ret = 0;
char plus = '+';
+ unsigned opt;
+ enum {
+ OPT_R = (1 << 2),
+ OPT_N = (1 << 3),
+ };
xfunc_error_retval = 2;
{
const char *p = "-1";
const char *i = "-"; /* compat */
xfunc_error_retval = 2;
{
const char *p = "-1";
const char *i = "-"; /* compat */
- if (getopt32(argv, "p:i:R", &p, &i) & 4)
+ opt = getopt32(argv, "p:i:RN", &p, &i);
+ if (opt & OPT_R)
plus = '-';
patch_level = xatoi(p); /* can be negative! */
patch_file = xfopen_stdin(i);
plus = '-';
patch_level = xatoi(p); /* can be negative! */
patch_file = xfopen_stdin(i);
@@
-131,9
+137,9
@@
int patch_main(int argc UNUSED_PARAM, char **argv)
} else {
backup_filename = xasprintf("%s.orig", new_filename);
xrename(new_filename, backup_filename);
} else {
backup_filename = xasprintf("%s.orig", new_filename);
xrename(new_filename, backup_filename);
- src_stream = xfopen
(backup_filename, "r"
);
+ src_stream = xfopen
_for_read(backup_filename
);
}
}
- dst_stream = xfopen
(new_filename, "w"
);
+ dst_stream = xfopen
_for_write(new_filename
);
fchmod(fileno(dst_stream), saved_stat.st_mode);
printf("patching file %s\n", new_filename);
fchmod(fileno(dst_stream), saved_stat.st_mode);
printf("patching file %s\n", new_filename);
@@
-202,6
+208,10
@@
int patch_main(int argc UNUSED_PARAM, char **argv)
src_line = NULL;
}
}
src_line = NULL;
}
}
+ /* Do not patch an already patched hunk with -N */
+ if (src_line == 0 && (opt & OPT_N)) {
+ continue;
+ }
if (!src_line) {
bb_error_msg("hunk #%u FAILED at %u", hunk_count, hunk_offset_start);
bad_hunk_count++;
if (!src_line) {
bb_error_msg("hunk #%u FAILED at %u", hunk_count, hunk_offset_start);
bad_hunk_count++;