diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-24 15:54:42 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-24 15:54:42 +0000 |
commit | 990d0f63eeb502c8762076e5c5499196e09cba55 (patch) | |
tree | 30a2091a8159b1694d65f9952e2aba2667d7dc11 /coreutils/dd.c | |
parent | bcb66ec22e82f6b1ab93f3aec917269393a5b464 (diff) | |
download | busybox-w32-990d0f63eeb502c8762076e5c5499196e09cba55.tar.gz busybox-w32-990d0f63eeb502c8762076e5c5499196e09cba55.tar.bz2 busybox-w32-990d0f63eeb502c8762076e5c5499196e09cba55.zip |
Replace index_in_[sub]str_array with index_in_[sub]strings,
which scans thru "abc\0def\0123\0\0" type strings. Saves 250 bytes.
text data bss dec hex filename
781266 1328 11844 794438 c1f46 busybox_old
781010 1328 11844 794182 c1e46 busybox_unstripped
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index dd311d86a..22ad19287 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -51,7 +51,7 @@ static ssize_t full_write_or_warn(int fd, const void *buf, size_t len, | |||
51 | } | 51 | } |
52 | 52 | ||
53 | static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs, | 53 | static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs, |
54 | const char * const filename) | 54 | const char *filename) |
55 | { | 55 | { |
56 | ssize_t n = full_write_or_warn(fd, buf, len, filename); | 56 | ssize_t n = full_write_or_warn(fd, buf, len, filename); |
57 | if (n < 0) | 57 | if (n < 0) |
@@ -78,13 +78,12 @@ int dd_main(int argc, char **argv) | |||
78 | TRUNC_FLAG = 1 << 2, | 78 | TRUNC_FLAG = 1 << 2, |
79 | TWOBUFS_FLAG = 1 << 3, | 79 | TWOBUFS_FLAG = 1 << 3, |
80 | }; | 80 | }; |
81 | static const char * const keywords[] = { | 81 | static const char keywords[] = |
82 | "bs=", "count=", "seek=", "skip=", "if=", "of=", | 82 | "bs=\0""count=\0""seek=\0""skip=\0""if=\0""of=\0" |
83 | #if ENABLE_FEATURE_DD_IBS_OBS | 83 | #if ENABLE_FEATURE_DD_IBS_OBS |
84 | "ibs=", "obs=", "conv=", "notrunc", "sync", "noerror", | 84 | "ibs=\0""obs=\0""conv=\0""notrunc\0""sync\0""noerror\0" |
85 | #endif | 85 | #endif |
86 | NULL | 86 | ; |
87 | }; | ||
88 | enum { | 87 | enum { |
89 | OP_bs = 1, | 88 | OP_bs = 1, |
90 | OP_count, | 89 | OP_count, |
@@ -134,7 +133,7 @@ int dd_main(int argc, char **argv) | |||
134 | bb_show_usage(); | 133 | bb_show_usage(); |
135 | key_len = key - arg + 1; | 134 | key_len = key - arg + 1; |
136 | key = xstrndup(arg, key_len); | 135 | key = xstrndup(arg, key_len); |
137 | what = index_in_str_array(keywords, key) + 1; | 136 | what = index_in_strings(keywords, key) + 1; |
138 | if (ENABLE_FEATURE_CLEAN_UP) | 137 | if (ENABLE_FEATURE_CLEAN_UP) |
139 | free(key); | 138 | free(key); |
140 | if (what == 0) | 139 | if (what == 0) |
@@ -153,13 +152,13 @@ int dd_main(int argc, char **argv) | |||
153 | if (what == OP_conv) { | 152 | if (what == OP_conv) { |
154 | while (1) { | 153 | while (1) { |
155 | /* find ',', replace them with nil so we can use arg for | 154 | /* find ',', replace them with nil so we can use arg for |
156 | * index_in_str_array without copying. | 155 | * index_in_strings() without copying. |
157 | * We rely on arg being non-null, else strchr would fault. | 156 | * We rely on arg being non-null, else strchr would fault. |
158 | */ | 157 | */ |
159 | key = strchr(arg, ','); | 158 | key = strchr(arg, ','); |
160 | if (key) | 159 | if (key) |
161 | *key = '\0'; | 160 | *key = '\0'; |
162 | what = index_in_str_array(keywords, arg) + 1; | 161 | what = index_in_strings(keywords, arg) + 1; |
163 | if (what < OP_conv_notrunc) | 162 | if (what < OP_conv_notrunc) |
164 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); | 163 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); |
165 | if (what == OP_conv_notrunc) | 164 | if (what == OP_conv_notrunc) |
@@ -298,15 +297,15 @@ int dd_main(int argc, char **argv) | |||
298 | G.out_part++; | 297 | G.out_part++; |
299 | } | 298 | } |
300 | if (close(ifd) < 0) { | 299 | if (close(ifd) < 0) { |
301 | die_infile: | 300 | die_infile: |
302 | bb_perror_msg_and_die("%s", infile); | 301 | bb_perror_msg_and_die("%s", infile); |
303 | } | 302 | } |
304 | 303 | ||
305 | if (close(ofd) < 0) { | 304 | if (close(ofd) < 0) { |
306 | die_outfile: | 305 | die_outfile: |
307 | bb_perror_msg_and_die("%s", outfile); | 306 | bb_perror_msg_and_die("%s", outfile); |
308 | } | 307 | } |
309 | out_status: | 308 | out_status: |
310 | dd_output_status(0); | 309 | dd_output_status(0); |
311 | 310 | ||
312 | return EXIT_SUCCESS; | 311 | return EXIT_SUCCESS; |