diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-23 22:55:25 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-23 22:55:25 +0000 |
commit | c93b162248892265eae5f54e9ee409074dfa08c5 (patch) | |
tree | 497549c9ca48814af3de07d185bf7beaa0d360b2 | |
parent | 324d26f9aa7453871e8bc5c2cc7c45ae2627bc35 (diff) | |
download | busybox-w32-c93b162248892265eae5f54e9ee409074dfa08c5.tar.gz busybox-w32-c93b162248892265eae5f54e9ee409074dfa08c5.tar.bz2 busybox-w32-c93b162248892265eae5f54e9ee409074dfa08c5.zip |
patch: shrink by Pascal Bellard <pascal.bellard AT ads-lu.com> (-80 bytes)
*: removal of #include <getopt.h>
-rw-r--r-- | archival/tar.c | 1 | ||||
-rw-r--r-- | console-tools/kbd_mode.c | 1 | ||||
-rw-r--r-- | console-tools/setconsole.c | 1 | ||||
-rw-r--r-- | coreutils/env.c | 1 | ||||
-rw-r--r-- | coreutils/install.c | 3 | ||||
-rw-r--r-- | coreutils/ls.c | 1 | ||||
-rw-r--r-- | coreutils/mkdir.c | 1 | ||||
-rw-r--r-- | coreutils/mv.c | 4 | ||||
-rw-r--r-- | coreutils/od.c | 1 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 1 | ||||
-rw-r--r-- | coreutils/readlink.c | 1 | ||||
-rw-r--r-- | debianutils/run_parts.c | 2 | ||||
-rw-r--r-- | debianutils/start_stop_daemon.c | 1 | ||||
-rw-r--r-- | editors/patch.c | 171 | ||||
-rw-r--r-- | loginutils/chpasswd.c | 2 | ||||
-rw-r--r-- | miscutils/chrt.c | 1 | ||||
-rw-r--r-- | miscutils/strings.c | 2 | ||||
-rw-r--r-- | miscutils/taskset.c | 1 | ||||
-rw-r--r-- | networking/ftpgetput.c | 1 | ||||
-rw-r--r-- | networking/ifupdown.c | 1 | ||||
-rw-r--r-- | networking/ipcalc.c | 1 | ||||
-rw-r--r-- | networking/route.c | 1 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 1 | ||||
-rw-r--r-- | networking/udhcp/dumpleases.c | 1 | ||||
-rw-r--r-- | networking/wget.c | 1 | ||||
-rw-r--r-- | procps/pgrep.c | 2 | ||||
-rw-r--r-- | shell/hush.c | 1 | ||||
-rw-r--r-- | util-linux/hexdump.c | 1 | ||||
-rw-r--r-- | util-linux/hwclock.c | 1 | ||||
-rw-r--r-- | util-linux/losetup.c | 2 | ||||
-rw-r--r-- | util-linux/umount.c | 1 |
31 files changed, 73 insertions, 138 deletions
diff --git a/archival/tar.c b/archival/tar.c index e790f28ea..7bd79552e 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -24,7 +24,6 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <fnmatch.h> | 26 | #include <fnmatch.h> |
27 | #include <getopt.h> | ||
28 | #include "libbb.h" | 27 | #include "libbb.h" |
29 | #include "unarchive.h" | 28 | #include "unarchive.h" |
30 | 29 | ||
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c index 0000ea180..46ec3fd28 100644 --- a/console-tools/kbd_mode.c +++ b/console-tools/kbd_mode.c | |||
@@ -10,7 +10,6 @@ | |||
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <getopt.h> | ||
14 | #include "libbb.h" | 13 | #include "libbb.h" |
15 | #include <linux/kd.h> | 14 | #include <linux/kd.h> |
16 | 15 | ||
diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c index 0aa1d3a35..8765a7c2e 100644 --- a/console-tools/setconsole.c +++ b/console-tools/setconsole.c | |||
@@ -7,7 +7,6 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <getopt.h> | ||
11 | #include "libbb.h" | 10 | #include "libbb.h" |
12 | 11 | ||
13 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS | 12 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
diff --git a/coreutils/env.c b/coreutils/env.c index f678565eb..20cf348d6 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -29,7 +29,6 @@ | |||
29 | * - use xfunc_error_retval | 29 | * - use xfunc_error_retval |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <getopt.h> /* struct option */ | ||
33 | #include "libbb.h" | 32 | #include "libbb.h" |
34 | 33 | ||
35 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | 34 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS |
diff --git a/coreutils/install.c b/coreutils/install.c index 4adcadb94..0b5eda0ac 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
@@ -9,9 +9,6 @@ | |||
9 | * owner/group, will probably modify bb_make_directory(...) | 9 | * owner/group, will probably modify bb_make_directory(...) |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <libgen.h> | ||
13 | #include <getopt.h> /* struct option */ | ||
14 | |||
15 | #include "libbb.h" | 12 | #include "libbb.h" |
16 | #include "libcoreutils/coreutils.h" | 13 | #include "libcoreutils/coreutils.h" |
17 | 14 | ||
diff --git a/coreutils/ls.c b/coreutils/ls.c index 9e5c6dee9..985086634 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -29,7 +29,6 @@ | |||
29 | * 1. requires lstat (BSD) - how do you do it without? | 29 | * 1. requires lstat (BSD) - how do you do it without? |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <getopt.h> | ||
33 | #include "libbb.h" | 32 | #include "libbb.h" |
34 | 33 | ||
35 | /* This is a NOEXEC applet. Be very careful! */ | 34 | /* This is a NOEXEC applet. Be very careful! */ |
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 6bdf76d29..72bd10581 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c | |||
@@ -19,7 +19,6 @@ | |||
19 | /* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support. | 19 | /* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <getopt.h> /* struct option */ | ||
23 | #include "libbb.h" | 22 | #include "libbb.h" |
24 | 23 | ||
25 | /* This is a NOFORK applet. Be very careful! */ | 24 | /* This is a NOFORK applet. Be very careful! */ |
diff --git a/coreutils/mv.c b/coreutils/mv.c index d8dc6c06b..5d02196e3 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c | |||
@@ -13,10 +13,6 @@ | |||
13 | * Size reduction and improved error checking. | 13 | * Size reduction and improved error checking. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <sys/types.h> | ||
17 | #include <sys/stat.h> | ||
18 | #include <dirent.h> | ||
19 | #include <getopt.h> /* struct option */ | ||
20 | #include "libbb.h" | 16 | #include "libbb.h" |
21 | #include "libcoreutils/coreutils.h" | 17 | #include "libcoreutils/coreutils.h" |
22 | 18 | ||
diff --git a/coreutils/od.c b/coreutils/od.c index 85e979f7e..94a6b95df 100644 --- a/coreutils/od.c +++ b/coreutils/od.c | |||
@@ -17,7 +17,6 @@ | |||
17 | /* This one provides -t (busybox's own build script needs it) */ | 17 | /* This one provides -t (busybox's own build script needs it) */ |
18 | #include "od_bloaty.c" | 18 | #include "od_bloaty.c" |
19 | #else | 19 | #else |
20 | #include <getopt.h> | ||
21 | 20 | ||
22 | #include "dump.h" | 21 | #include "dump.h" |
23 | 22 | ||
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index dce2349a3..942cf038e 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -50,7 +50,6 @@ diff -u -a std bbox >bbox.diff || { echo Different!; sleep 1; } | |||
50 | */ | 50 | */ |
51 | 51 | ||
52 | #include "libbb.h" | 52 | #include "libbb.h" |
53 | #include <getopt.h> | ||
54 | 53 | ||
55 | #define assert(a) ((void)0) | 54 | #define assert(a) ((void)0) |
56 | 55 | ||
diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 3f13a3660..0c45e1234 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c | |||
@@ -7,7 +7,6 @@ | |||
7 | * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <getopt.h> | ||
11 | #include "libbb.h" | 10 | #include "libbb.h" |
12 | 11 | ||
13 | int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 12 | int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 2adad026d..47eda8cf6 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -30,8 +30,6 @@ | |||
30 | * -u MASK umask. Set the umask of the program executed to MASK. | 30 | * -u MASK umask. Set the umask of the program executed to MASK. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include <getopt.h> | ||
34 | |||
35 | #include "libbb.h" | 33 | #include "libbb.h" |
36 | 34 | ||
37 | struct globals { | 35 | struct globals { |
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 6f4b6b2bb..a2679f331 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -11,7 +11,6 @@ | |||
11 | /* NB: we have a problem here with /proc/NN/exe usage, similar to | 11 | /* NB: we have a problem here with /proc/NN/exe usage, similar to |
12 | * one fixed in killall/pidof */ | 12 | * one fixed in killall/pidof */ |
13 | 13 | ||
14 | #include <getopt.h> | ||
15 | #include <sys/resource.h> | 14 | #include <sys/resource.h> |
16 | 15 | ||
17 | /* Override ENABLE_FEATURE_PIDFILE */ | 16 | /* Override ENABLE_FEATURE_PIDFILE */ |
diff --git a/editors/patch.c b/editors/patch.c index 9a678e162..a37f4e62f 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -19,15 +19,11 @@ | |||
19 | * - Reject file isnt saved | 19 | * - Reject file isnt saved |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <getopt.h> | ||
23 | |||
24 | #include "libbb.h" | 22 | #include "libbb.h" |
25 | 23 | ||
26 | static unsigned int copy_lines(FILE *src_stream, FILE *dest_stream, const unsigned int lines_count) | 24 | static unsigned copy_lines(FILE *src_stream, FILE *dest_stream, unsigned lines_count) |
27 | { | 25 | { |
28 | unsigned int i = 0; | 26 | while (src_stream && lines_count) { |
29 | |||
30 | while (src_stream && (i < lines_count)) { | ||
31 | char *line; | 27 | char *line; |
32 | line = xmalloc_fgets(src_stream); | 28 | line = xmalloc_fgets(src_stream); |
33 | if (line == NULL) { | 29 | if (line == NULL) { |
@@ -37,60 +33,54 @@ static unsigned int copy_lines(FILE *src_stream, FILE *dest_stream, const unsign | |||
37 | bb_perror_msg_and_die("error writing to new file"); | 33 | bb_perror_msg_and_die("error writing to new file"); |
38 | } | 34 | } |
39 | free(line); | 35 | free(line); |
40 | 36 | lines_count--; | |
41 | i++; | ||
42 | } | 37 | } |
43 | return i; | 38 | return lines_count; |
44 | } | 39 | } |
45 | 40 | ||
46 | /* If patch_level is -1 it will remove all directory names | 41 | /* If patch_level is -1 it will remove all directory names |
47 | * char *line must be greater than 4 chars | 42 | * char *line must be greater than 4 chars |
48 | * returns NULL if the file doesnt exist or error | 43 | * returns NULL if the file doesnt exist or error |
49 | * returns malloc'ed filename | 44 | * returns malloc'ed filename |
45 | * NB: frees 1st argument! | ||
50 | */ | 46 | */ |
51 | 47 | static char *extract_filename_and_free_line(char *line, int patch_level) | |
52 | static char *extract_filename(char *line, int patch_level) | ||
53 | { | 48 | { |
54 | char *temp, *filename_start_ptr = line + 4; | 49 | char *temp, *filename_start_ptr = line + 4; |
55 | int i; | ||
56 | 50 | ||
57 | /* Terminate string at end of source filename */ | 51 | /* Terminate string at end of source filename */ |
58 | temp = strchrnul(filename_start_ptr, '\t'); | 52 | temp = strchrnul(filename_start_ptr, '\t'); |
59 | *temp = '\0'; | 53 | *temp = '\0'; |
60 | 54 | ||
61 | /* Skip over (patch_level) number of leading directories */ | 55 | /* Skip over (patch_level) number of leading directories */ |
62 | if (patch_level == -1) | 56 | while (patch_level--) { |
63 | patch_level = INT_MAX; | ||
64 | for (i = 0; i < patch_level; i++) { | ||
65 | temp = strchr(filename_start_ptr, '/'); | 57 | temp = strchr(filename_start_ptr, '/'); |
66 | if (!temp) | 58 | if (!temp) |
67 | break; | 59 | break; |
68 | filename_start_ptr = temp + 1; | 60 | filename_start_ptr = temp + 1; |
69 | } | 61 | } |
70 | 62 | ||
71 | return xstrdup(filename_start_ptr); | 63 | temp = xstrdup(filename_start_ptr); |
64 | free(line); | ||
65 | return temp; | ||
72 | } | 66 | } |
73 | 67 | ||
74 | int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 68 | int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
75 | int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | 69 | int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) |
76 | { | 70 | { |
77 | int patch_level = -1; | ||
78 | char *patch_line; | ||
79 | int ret; | ||
80 | FILE *patch_file = NULL; | ||
81 | struct stat saved_stat; | 71 | struct stat saved_stat; |
82 | 72 | char *patch_line; | |
73 | FILE *patch_file; | ||
74 | int patch_level; | ||
75 | int ret = 0; | ||
76 | |||
77 | xfunc_error_retval = 2; | ||
83 | { | 78 | { |
84 | char *p, *i; | 79 | const char *p = "-1"; |
85 | ret = getopt32(argv, "p:i:", &p, &i); | 80 | const char *i = "-"; /* compat */ |
86 | if (ret & 1) | 81 | getopt32(argv, "p:i:", &p, &i); |
87 | patch_level = xatol_range(p, -1, USHRT_MAX); | 82 | patch_level = xatoi(p); /* can be negative! */ |
88 | if (ret & 2) { | 83 | patch_file = xfopen_stdin(i); |
89 | patch_file = xfopen(i, "r"); | ||
90 | } else { | ||
91 | patch_file = stdin; | ||
92 | } | ||
93 | ret = 0; | ||
94 | } | 84 | } |
95 | 85 | ||
96 | patch_line = xmalloc_getline(patch_file); | 86 | patch_line = xmalloc_getline(patch_file); |
@@ -100,38 +90,33 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
100 | char *original_filename; | 90 | char *original_filename; |
101 | char *new_filename; | 91 | char *new_filename; |
102 | char *backup_filename; | 92 | char *backup_filename; |
103 | unsigned int src_cur_line = 1; | 93 | unsigned src_cur_line = 1; |
104 | unsigned int dest_cur_line = 0; | 94 | unsigned dest_cur_line = 0; |
105 | unsigned int dest_beg_line; | 95 | unsigned dest_beg_line; |
106 | unsigned int bad_hunk_count = 0; | 96 | unsigned bad_hunk_count = 0; |
107 | unsigned int hunk_count = 0; | 97 | unsigned hunk_count = 0; |
108 | char copy_trailing_lines_flag = 0; | 98 | smallint copy_trailing_lines_flag = 0; |
109 | 99 | ||
110 | /* Skip everything upto the "---" marker | 100 | /* Skip everything upto the "---" marker |
111 | * No need to parse the lines "Only in <dir>", and "diff <args>" | 101 | * No need to parse the lines "Only in <dir>", and "diff <args>" |
112 | */ | 102 | */ |
113 | while (patch_line && strncmp(patch_line, "--- ", 4) != 0) { | 103 | while (strncmp(patch_line, "--- ", 4) != 0) { |
114 | free(patch_line); | 104 | free(patch_line); |
115 | patch_line = xmalloc_getline(patch_file); | 105 | patch_line = xmalloc_getline(patch_file); |
106 | if (!patch_line) | ||
107 | bb_error_msg_and_die("invalid patch"); | ||
116 | } | 108 | } |
117 | /* FIXME: patch_line NULL check?? */ | ||
118 | 109 | ||
119 | /* Extract the filename used before the patch was generated */ | 110 | /* Extract the filename used before the patch was generated */ |
120 | original_filename = extract_filename(patch_line, patch_level); | 111 | original_filename = extract_filename_and_free_line(patch_line, patch_level); |
121 | free(patch_line); | ||
122 | 112 | ||
123 | patch_line = xmalloc_getline(patch_file); | 113 | patch_line = xmalloc_getline(patch_file); |
124 | /* FIXME: NULL check?? */ | 114 | if (!patch_line || strncmp(patch_line, "+++ ", 4) != 0) |
125 | if (strncmp(patch_line, "+++ ", 4) != 0) { | 115 | bb_error_msg_and_die("invalid patch"); |
126 | ret = 2; | 116 | new_filename = extract_filename_and_free_line(patch_line, patch_level); |
127 | bb_error_msg("invalid patch"); | ||
128 | continue; | ||
129 | } | ||
130 | new_filename = extract_filename(patch_line, patch_level); | ||
131 | free(patch_line); | ||
132 | 117 | ||
133 | /* Get access rights from the file to be patched, -1 file does not exist */ | 118 | /* Get access rights from the file to be patched, -1 file does not exist */ |
134 | if (stat(new_filename, &saved_stat)) { | 119 | if (stat(new_filename, &saved_stat) != 0) { |
135 | char *line_ptr; | 120 | char *line_ptr; |
136 | /* Create leading directories */ | 121 | /* Create leading directories */ |
137 | line_ptr = strrchr(new_filename, '/'); | 122 | line_ptr = strrchr(new_filename, '/'); |
@@ -140,53 +125,47 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
140 | bb_make_directory(new_filename, -1, FILEUTILS_RECUR); | 125 | bb_make_directory(new_filename, -1, FILEUTILS_RECUR); |
141 | *line_ptr = '/'; | 126 | *line_ptr = '/'; |
142 | } | 127 | } |
143 | dst_stream = xfopen(new_filename, "w+"); | ||
144 | backup_filename = NULL; | 128 | backup_filename = NULL; |
129 | saved_stat.st_mode = 0644; | ||
145 | } else { | 130 | } else { |
146 | backup_filename = xmalloc(strlen(new_filename) + 6); | 131 | backup_filename = xasprintf("%s.orig", new_filename); |
147 | strcpy(backup_filename, new_filename); | ||
148 | strcat(backup_filename, ".orig"); | ||
149 | xrename(new_filename, backup_filename); | 132 | xrename(new_filename, backup_filename); |
150 | dst_stream = xfopen(new_filename, "w"); | ||
151 | fchmod(fileno(dst_stream), saved_stat.st_mode); | ||
152 | } | 133 | } |
134 | dst_stream = xfopen(new_filename, "w"); | ||
135 | fchmod(fileno(dst_stream), saved_stat.st_mode); | ||
136 | src_stream = NULL; | ||
153 | 137 | ||
154 | if ((backup_filename == NULL) || stat(original_filename, &saved_stat)) { | 138 | if (backup_filename && !stat(original_filename, &saved_stat)) { |
155 | src_stream = NULL; | 139 | src_stream = xfopen((strcmp(original_filename, new_filename)) ? |
156 | } else { | 140 | original_filename : backup_filename, "r"); |
157 | if (strcmp(original_filename, new_filename) == 0) { | ||
158 | src_stream = xfopen(backup_filename, "r"); | ||
159 | } else { | ||
160 | src_stream = xfopen(original_filename, "r"); | ||
161 | } | ||
162 | } | 141 | } |
163 | 142 | ||
164 | printf("patching file %s\n", new_filename); | 143 | printf("patching file %s\n", new_filename); |
165 | 144 | ||
166 | /* Handle each hunk */ | 145 | /* Handle all hunks for this file */ |
167 | patch_line = xmalloc_fgets(patch_file); | 146 | patch_line = xmalloc_fgets(patch_file); |
168 | while (patch_line) { | 147 | while (patch_line) { |
169 | unsigned int count; | 148 | unsigned count; |
170 | unsigned int src_beg_line; | 149 | unsigned src_beg_line; |
171 | unsigned int unused; | 150 | unsigned unused; |
172 | unsigned int hunk_offset_start = 0; | 151 | unsigned hunk_offset_start = 0; |
173 | int hunk_error = 0; | 152 | smallint hunk_error = 0; |
174 | 153 | ||
175 | /* This bit should be improved */ | 154 | /* This bit should be improved */ |
176 | if ((sscanf(patch_line, "@@ -%d,%d +%d,%d @@", &src_beg_line, &unused, &dest_beg_line, &unused) != 4) && | 155 | if ((sscanf(patch_line, "@@ -%d,%d +%d,%d @@", &src_beg_line, &unused, &dest_beg_line, &unused) != 4) |
177 | (sscanf(patch_line, "@@ -%d,%d +%d @@", &src_beg_line, &unused, &dest_beg_line) != 3) && | 156 | && (sscanf(patch_line, "@@ -%d,%d +%d @@", &src_beg_line, &unused, &dest_beg_line) != 3) |
178 | (sscanf(patch_line, "@@ -%d +%d,%d @@", &src_beg_line, &dest_beg_line, &unused) != 3)) { | 157 | && (sscanf(patch_line, "@@ -%d +%d,%d @@", &src_beg_line, &dest_beg_line, &unused) != 3) |
158 | ) { | ||
179 | /* No more hunks for this file */ | 159 | /* No more hunks for this file */ |
180 | break; | 160 | break; |
181 | } | 161 | } |
182 | free(patch_line); | ||
183 | hunk_count++; | 162 | hunk_count++; |
184 | 163 | ||
185 | if (src_beg_line && dest_beg_line) { | 164 | if (src_beg_line && dest_beg_line) { |
186 | /* Copy unmodified lines upto start of hunk */ | 165 | /* Copy unmodified lines upto start of hunk */ |
187 | /* src_beg_line will be 0 if its a new file */ | 166 | /* src_beg_line will be 0 if it's a new file */ |
188 | count = src_beg_line - src_cur_line; | 167 | count = src_beg_line - src_cur_line; |
189 | if (copy_lines(src_stream, dst_stream, count) != count) { | 168 | if (copy_lines(src_stream, dst_stream, count)) { |
190 | bb_error_msg_and_die("bad src file"); | 169 | bb_error_msg_and_die("bad src file"); |
191 | } | 170 | } |
192 | src_cur_line += count; | 171 | src_cur_line += count; |
@@ -195,27 +174,25 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
195 | } | 174 | } |
196 | hunk_offset_start = src_cur_line; | 175 | hunk_offset_start = src_cur_line; |
197 | 176 | ||
198 | while ((patch_line = xmalloc_fgets(patch_file)) != NULL) { | 177 | while (1) { |
178 | free(patch_line); | ||
179 | patch_line = xmalloc_fgets(patch_file); | ||
180 | if (patch_line == NULL) break; | ||
199 | if ((*patch_line == '-') || (*patch_line == ' ')) { | 181 | if ((*patch_line == '-') || (*patch_line == ' ')) { |
200 | char *src_line = NULL; | 182 | char *src_line = NULL; |
201 | if (src_stream) { | 183 | if (src_stream) { |
202 | src_line = xmalloc_fgets(src_stream); | 184 | src_line = xmalloc_fgets(src_stream); |
203 | if (!src_line) { | 185 | if (src_line) { |
204 | hunk_error++; | 186 | int diff = strcmp(src_line, patch_line + 1); |
205 | break; | ||
206 | } else { | ||
207 | src_cur_line++; | 187 | src_cur_line++; |
188 | free(src_line); | ||
189 | if (diff) src_line = NULL; | ||
208 | } | 190 | } |
209 | if (strcmp(src_line, patch_line + 1) != 0) { | 191 | if (!src_line) { |
210 | bb_error_msg("hunk #%d FAILED at %d", hunk_count, hunk_offset_start); | 192 | bb_error_msg("hunk #%d FAILED at %d", hunk_count, hunk_offset_start); |
211 | hunk_error++; | 193 | hunk_error = 1; |
212 | free(patch_line); | ||
213 | /* Probably need to find next hunk, etc... */ | ||
214 | /* but for now we just bail out */ | ||
215 | patch_line = NULL; | ||
216 | break; | 194 | break; |
217 | } | 195 | } |
218 | free(src_line); | ||
219 | } | 196 | } |
220 | if (*patch_line == ' ') { | 197 | if (*patch_line == ' ') { |
221 | fputs(patch_line + 1, dst_stream); | 198 | fputs(patch_line + 1, dst_stream); |
@@ -227,16 +204,15 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
227 | } else { | 204 | } else { |
228 | break; | 205 | break; |
229 | } | 206 | } |
230 | free(patch_line); | 207 | } /* end of while loop handling one hunk */ |
231 | } | ||
232 | if (hunk_error) { | 208 | if (hunk_error) { |
233 | bad_hunk_count++; | 209 | bad_hunk_count++; |
234 | } | 210 | } |
235 | } | 211 | } /* end of while loop handling one file */ |
236 | 212 | ||
237 | /* Cleanup last patched file */ | 213 | /* Cleanup last patched file */ |
238 | if (copy_trailing_lines_flag) { | 214 | if (copy_trailing_lines_flag) { |
239 | copy_lines(src_stream, dst_stream, -1); | 215 | copy_lines(src_stream, dst_stream, (unsigned)(-1)); |
240 | } | 216 | } |
241 | if (src_stream) { | 217 | if (src_stream) { |
242 | fclose(src_stream); | 218 | fclose(src_stream); |
@@ -245,14 +221,13 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
245 | fclose(dst_stream); | 221 | fclose(dst_stream); |
246 | } | 222 | } |
247 | if (bad_hunk_count) { | 223 | if (bad_hunk_count) { |
248 | if (!ret) { | 224 | ret = 1; |
249 | ret = 1; | 225 | bb_error_msg("%u out of %u hunk FAILED", bad_hunk_count, hunk_count); |
250 | } | ||
251 | bb_error_msg("%d out of %d hunk FAILED", bad_hunk_count, hunk_count); | ||
252 | } else { | 226 | } else { |
253 | /* It worked, we can remove the backup */ | 227 | /* It worked, we can remove the backup */ |
254 | if (backup_filename) { | 228 | if (backup_filename) { |
255 | unlink(backup_filename); | 229 | unlink(backup_filename); |
230 | free(backup_filename); | ||
256 | } | 231 | } |
257 | if ((dest_cur_line == 0) || (dest_beg_line == 0)) { | 232 | if ((dest_cur_line == 0) || (dest_beg_line == 0)) { |
258 | /* The new patched file is empty, remove it */ | 233 | /* The new patched file is empty, remove it */ |
@@ -261,11 +236,11 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
261 | xunlink(original_filename); | 236 | xunlink(original_filename); |
262 | } | 237 | } |
263 | } | 238 | } |
264 | } | 239 | } /* end of "while there are patch lines" */ |
265 | 240 | ||
266 | /* 0 = SUCCESS | 241 | /* 0 = SUCCESS |
267 | * 1 = Some hunks failed | 242 | * 1 = Some hunks failed |
268 | * 2 = More serious problems | 243 | * 2 = More serious problems (exited earlier) |
269 | */ | 244 | */ |
270 | return ret; | 245 | return ret; |
271 | } | 246 | } |
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 83e5e0c1f..cb13ebb2d 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
@@ -9,8 +9,6 @@ | |||
9 | #include "libbb.h" | 9 | #include "libbb.h" |
10 | 10 | ||
11 | #if ENABLE_GETOPT_LONG | 11 | #if ENABLE_GETOPT_LONG |
12 | #include <getopt.h> | ||
13 | |||
14 | static const char chpasswd_longopts[] ALIGN1 = | 12 | static const char chpasswd_longopts[] ALIGN1 = |
15 | "encrypted\0" No_argument "e" | 13 | "encrypted\0" No_argument "e" |
16 | "md5\0" No_argument "m" | 14 | "md5\0" No_argument "m" |
diff --git a/miscutils/chrt.c b/miscutils/chrt.c index 0d55e3299..13557feef 100644 --- a/miscutils/chrt.c +++ b/miscutils/chrt.c | |||
@@ -7,7 +7,6 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <sched.h> | 9 | #include <sched.h> |
10 | #include <getopt.h> /* optind */ | ||
11 | #include "libbb.h" | 10 | #include "libbb.h" |
12 | #ifndef _POSIX_PRIORITY_SCHEDULING | 11 | #ifndef _POSIX_PRIORITY_SCHEDULING |
13 | #warning your system may be foobared | 12 | #warning your system may be foobared |
diff --git a/miscutils/strings.c b/miscutils/strings.c index 5efbabf6f..147413741 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
@@ -7,8 +7,6 @@ | |||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <getopt.h> | ||
11 | |||
12 | #include "libbb.h" | 10 | #include "libbb.h" |
13 | 11 | ||
14 | #define WHOLE_FILE 1 | 12 | #define WHOLE_FILE 1 |
diff --git a/miscutils/taskset.c b/miscutils/taskset.c index bf98ea15d..4815b6a76 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c | |||
@@ -7,7 +7,6 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <sched.h> | 9 | #include <sched.h> |
10 | #include <getopt.h> /* optind */ | ||
11 | #include "libbb.h" | 10 | #include "libbb.h" |
12 | 11 | ||
13 | #if ENABLE_FEATURE_TASKSET_FANCY | 12 | #if ENABLE_FEATURE_TASKSET_FANCY |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 6e2d96093..a1ee05426 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -13,7 +13,6 @@ | |||
13 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 13 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <getopt.h> | ||
17 | #include "libbb.h" | 16 | #include "libbb.h" |
18 | 17 | ||
19 | typedef struct ftp_host_info_s { | 18 | typedef struct ftp_host_info_s { |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 174681984..29738c6d0 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -19,7 +19,6 @@ | |||
19 | 19 | ||
20 | #include <sys/utsname.h> | 20 | #include <sys/utsname.h> |
21 | #include <fnmatch.h> | 21 | #include <fnmatch.h> |
22 | #include <getopt.h> | ||
23 | 22 | ||
24 | #include "libbb.h" | 23 | #include "libbb.h" |
25 | 24 | ||
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index d7c968c25..9e92b643e 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -12,7 +12,6 @@ | |||
12 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 12 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <getopt.h> | ||
16 | #include <sys/socket.h> | 15 | #include <sys/socket.h> |
17 | #include <arpa/inet.h> | 16 | #include <arpa/inet.h> |
18 | 17 | ||
diff --git a/networking/route.c b/networking/route.c index 53e3988c1..857424c3b 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -25,7 +25,6 @@ | |||
25 | * remove ridiculous amounts of bloat. | 25 | * remove ridiculous amounts of bloat. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <getopt.h> | ||
29 | #include <net/route.h> | 28 | #include <net/route.h> |
30 | #include <net/if.h> | 29 | #include <net/if.h> |
31 | 30 | ||
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index fe8f4c8fa..bc0676152 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 8 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <getopt.h> | ||
12 | #include <syslog.h> | 11 | #include <syslog.h> |
13 | 12 | ||
14 | /* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */ | 13 | /* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */ |
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 83b384177..c98005f13 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -2,7 +2,6 @@ | |||
2 | /* | 2 | /* |
3 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 3 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
4 | */ | 4 | */ |
5 | #include <getopt.h> | ||
6 | 5 | ||
7 | #include "common.h" | 6 | #include "common.h" |
8 | #include "dhcpd.h" | 7 | #include "dhcpd.h" |
diff --git a/networking/wget.c b/networking/wget.c index f8adcd700..7dd1d36f9 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -6,7 +6,6 @@ | |||
6 | * | 6 | * |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <getopt.h> /* for struct option */ | ||
10 | #include "libbb.h" | 9 | #include "libbb.h" |
11 | 10 | ||
12 | struct host_info { | 11 | struct host_info { |
diff --git a/procps/pgrep.c b/procps/pgrep.c index 1ffc87db0..f20789c81 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c | |||
@@ -7,8 +7,6 @@ | |||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <getopt.h> | ||
11 | |||
12 | #include "libbb.h" | 10 | #include "libbb.h" |
13 | #include "xregex.h" | 11 | #include "xregex.h" |
14 | 12 | ||
diff --git a/shell/hush.c b/shell/hush.c index 4e6d50094..eb0633b18 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -78,7 +78,6 @@ | |||
78 | 78 | ||
79 | 79 | ||
80 | #include <glob.h> /* glob, of course */ | 80 | #include <glob.h> /* glob, of course */ |
81 | #include <getopt.h> /* should be pretty obvious */ | ||
82 | /* #include <dmalloc.h> */ | 81 | /* #include <dmalloc.h> */ |
83 | 82 | ||
84 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ | 83 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ |
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index cdb17ca3b..10c57fd61 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c | |||
@@ -9,7 +9,6 @@ | |||
9 | * Licensed under GPLv2 or later, see file License in this tarball for details. | 9 | * Licensed under GPLv2 or later, see file License in this tarball for details. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <getopt.h> | ||
13 | #include "libbb.h" | 12 | #include "libbb.h" |
14 | #include "dump.h" | 13 | #include "dump.h" |
15 | 14 | ||
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 44522dfd7..a03d61bbf 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -8,7 +8,6 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <sys/utsname.h> | 10 | #include <sys/utsname.h> |
11 | #include <getopt.h> | ||
12 | #include "libbb.h" | 11 | #include "libbb.h" |
13 | #include "rtc_.h" | 12 | #include "rtc_.h" |
14 | 13 | ||
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index d521b7b88..62a1a7363 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -7,8 +7,6 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <getopt.h> | ||
11 | |||
12 | #include "libbb.h" | 10 | #include "libbb.h" |
13 | 11 | ||
14 | int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 12 | int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/util-linux/umount.c b/util-linux/umount.c index 6136fa97c..34c979e0c 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -9,7 +9,6 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <mntent.h> | 11 | #include <mntent.h> |
12 | #include <getopt.h> | ||
13 | #include "libbb.h" | 12 | #include "libbb.h" |
14 | 13 | ||
15 | /* ignored: -v -d -t -i */ | 14 | /* ignored: -v -d -t -i */ |