diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-07 16:24:46 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-07 16:24:46 +0000 |
commit | 5625415085e68ac5e150f54e685417c866620d76 (patch) | |
tree | 4146667d4080f97bc39ac96d844c01a8956aeeca /coreutils/dd.c | |
parent | 890ac9deb2cc57cadd7aba4ee91bd012e19e239d (diff) | |
download | busybox-w32-5625415085e68ac5e150f54e685417c866620d76.tar.gz busybox-w32-5625415085e68ac5e150f54e685417c866620d76.tar.bz2 busybox-w32-5625415085e68ac5e150f54e685417c866620d76.zip |
dd: make it recognize not only 'k' but 'K' too;
make it (partially) CONFIG_LFS-aware
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 8d859ef5c..e63244d81 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -17,6 +17,7 @@ static const struct suffix_mult dd_suffixes[] = { | |||
17 | { "b", 512 }, | 17 | { "b", 512 }, |
18 | { "kD", 1000 }, | 18 | { "kD", 1000 }, |
19 | { "k", 1024 }, | 19 | { "k", 1024 }, |
20 | { "K", 1024 }, // compat with coreutils dd | ||
20 | { "MD", 1000000 }, | 21 | { "MD", 1000000 }, |
21 | { "M", 1048576 }, | 22 | { "M", 1048576 }, |
22 | { "GD", 1000000000 }, | 23 | { "GD", 1000000000 }, |
@@ -24,25 +25,26 @@ static const struct suffix_mult dd_suffixes[] = { | |||
24 | { NULL, 0 } | 25 | { NULL, 0 } |
25 | }; | 26 | }; |
26 | 27 | ||
27 | static size_t out_full, out_part, in_full, in_part; | 28 | static FILEOFF_TYPE out_full, out_part, in_full, in_part; |
28 | 29 | ||
29 | static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal) | 30 | static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal) |
30 | { | 31 | { |
31 | bb_fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n", | 32 | bb_fprintf(stderr, FILEOFF_FMT"+"FILEOFF_FMT" records in\n" |
32 | (long)in_full, (long)in_part, | 33 | FILEOFF_FMT"+"FILEOFF_FMT" records out\n", |
33 | (long)out_full, (long)out_part); | 34 | in_full, in_part, |
35 | out_full, out_part); | ||
34 | } | 36 | } |
35 | 37 | ||
36 | int dd_main(int argc, char **argv) | 38 | int dd_main(int argc, char **argv) |
37 | { | 39 | { |
38 | #define sync_flag (1<<0) | 40 | #define sync_flag (1<<0) |
39 | #define noerror (1<<1) | 41 | #define noerror (1<<1) |
40 | #define trunc_flag (1<<2) | 42 | #define trunc_flag (1<<2) |
41 | #define twobufs_flag (1<<3) | 43 | #define twobufs_flag (1<<3) |
42 | int flags = trunc_flag; | 44 | int flags = trunc_flag; |
43 | size_t count = -1, oc = 0, ibs = 512, obs = 512; | 45 | size_t oc = 0, ibs = 512, obs = 512; |
44 | ssize_t n; | 46 | ssize_t n; |
45 | off_t seek = 0, skip = 0; | 47 | FILEOFF_TYPE seek = 0, skip = 0, count = MAX_FILEOFF_TYPE; |
46 | int oflag, ifd, ofd; | 48 | int oflag, ifd, ofd; |
47 | const char *infile = NULL, *outfile = NULL; | 49 | const char *infile = NULL, *outfile = NULL; |
48 | char *ibuf, *obuf; | 50 | char *ibuf, *obuf; |
@@ -58,6 +60,7 @@ int dd_main(int argc, char **argv) | |||
58 | } | 60 | } |
59 | 61 | ||
60 | for (n = 1; n < argc; n++) { | 62 | for (n = 1; n < argc; n++) { |
63 | // FIXME: make them capable of eating LARGE numbers | ||
61 | if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) { | 64 | if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) { |
62 | ibs = bb_xparse_number(argv[n]+4, dd_suffixes); | 65 | ibs = bb_xparse_number(argv[n]+4, dd_suffixes); |
63 | flags |= twobufs_flag; | 66 | flags |= twobufs_flag; |
@@ -80,7 +83,7 @@ int dd_main(int argc, char **argv) | |||
80 | ibuf = argv[n]+5; | 83 | ibuf = argv[n]+5; |
81 | while (1) { | 84 | while (1) { |
82 | if (!strncmp("notrunc", ibuf, 7)) { | 85 | if (!strncmp("notrunc", ibuf, 7)) { |
83 | flags ^= trunc_flag; | 86 | flags &= ~trunc_flag; |
84 | ibuf += 7; | 87 | ibuf += 7; |
85 | } else if (!strncmp("sync", ibuf, 4)) { | 88 | } else if (!strncmp("sync", ibuf, 4)) { |
86 | flags |= sync_flag; | 89 | flags |= sync_flag; |
@@ -105,14 +108,14 @@ int dd_main(int argc, char **argv) | |||
105 | obuf = ibuf; | 108 | obuf = ibuf; |
106 | 109 | ||
107 | if (infile != NULL) | 110 | if (infile != NULL) |
108 | ifd = xopen(infile, O_RDONLY); | 111 | ifd = xopen(infile, O_RDONLY | (O_LARGEFILE * ENABLE_LFS)); |
109 | else { | 112 | else { |
110 | ifd = STDIN_FILENO; | 113 | ifd = STDIN_FILENO; |
111 | infile = bb_msg_standard_input; | 114 | infile = bb_msg_standard_input; |
112 | } | 115 | } |
113 | 116 | ||
114 | if (outfile != NULL) { | 117 | if (outfile != NULL) { |
115 | oflag = O_WRONLY | O_CREAT; | 118 | oflag = O_WRONLY | O_CREAT | (O_LARGEFILE * ENABLE_LFS); |
116 | 119 | ||
117 | if (!seek && (flags & trunc_flag)) | 120 | if (!seek && (flags & trunc_flag)) |
118 | oflag |= O_TRUNC; | 121 | oflag |= O_TRUNC; |
@@ -134,7 +137,7 @@ int dd_main(int argc, char **argv) | |||
134 | } | 137 | } |
135 | 138 | ||
136 | if (skip) { | 139 | if (skip) { |
137 | if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { | 140 | if (LSEEK(ifd, skip * ibs, SEEK_CUR) < 0) { |
138 | while (skip-- > 0) { | 141 | while (skip-- > 0) { |
139 | n = safe_read(ifd, ibuf, ibs); | 142 | n = safe_read(ifd, ibuf, ibs); |
140 | if (n < 0) | 143 | if (n < 0) |
@@ -146,7 +149,7 @@ int dd_main(int argc, char **argv) | |||
146 | } | 149 | } |
147 | 150 | ||
148 | if (seek) { | 151 | if (seek) { |
149 | if (lseek(ofd, seek * obs, SEEK_CUR) < 0) | 152 | if (LSEEK(ofd, seek * obs, SEEK_CUR) < 0) |
150 | goto die_outfile; | 153 | goto die_outfile; |
151 | } | 154 | } |
152 | 155 | ||