diff options
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 8c7272b5c..11508614f 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -62,19 +62,19 @@ int dd_main(int argc, char **argv) | |||
62 | int ifd; | 62 | int ifd; |
63 | int ofd; | 63 | int ofd; |
64 | int i; | 64 | int i; |
65 | char *infile = NULL; | 65 | const char *infile = NULL; |
66 | char *outfile = NULL; | 66 | const char *outfile = NULL; |
67 | char *buf; | 67 | char *buf; |
68 | 68 | ||
69 | for (i = 1; i < argc; i++) { | 69 | for (i = 1; i < argc; i++) { |
70 | if (strncmp("bs=", argv[i], 3) == 0) | 70 | if (strncmp("bs=", argv[i], 3) == 0) |
71 | bs = parse_number(argv[i]+3, dd_suffixes); | 71 | bs = bb_xparse_number(argv[i]+3, dd_suffixes); |
72 | else if (strncmp("count=", argv[i], 6) == 0) | 72 | else if (strncmp("count=", argv[i], 6) == 0) |
73 | count = parse_number(argv[i]+6, dd_suffixes); | 73 | count = bb_xparse_number(argv[i]+6, dd_suffixes); |
74 | else if (strncmp("seek=", argv[i], 5) == 0) | 74 | else if (strncmp("seek=", argv[i], 5) == 0) |
75 | seek = parse_number(argv[i]+5, dd_suffixes); | 75 | seek = bb_xparse_number(argv[i]+5, dd_suffixes); |
76 | else if (strncmp("skip=", argv[i], 5) == 0) | 76 | else if (strncmp("skip=", argv[i], 5) == 0) |
77 | skip = parse_number(argv[i]+5, dd_suffixes); | 77 | skip = bb_xparse_number(argv[i]+5, dd_suffixes); |
78 | else if (strncmp("if=", argv[i], 3) == 0) | 78 | else if (strncmp("if=", argv[i], 3) == 0) |
79 | infile = argv[i]+3; | 79 | infile = argv[i]+3; |
80 | else if (strncmp("of=", argv[i], 3) == 0) | 80 | else if (strncmp("of=", argv[i], 3) == 0) |
@@ -92,7 +92,7 @@ int dd_main(int argc, char **argv) | |||
92 | noerror = TRUE; | 92 | noerror = TRUE; |
93 | buf += 7; | 93 | buf += 7; |
94 | } else { | 94 | } else { |
95 | error_msg_and_die("invalid conversion `%s'", argv[i]+5); | 95 | bb_error_msg_and_die("invalid conversion `%s'", argv[i]+5); |
96 | } | 96 | } |
97 | if (buf[0] == '\0') | 97 | if (buf[0] == '\0') |
98 | break; | 98 | break; |
@@ -100,18 +100,18 @@ int dd_main(int argc, char **argv) | |||
100 | buf++; | 100 | buf++; |
101 | } | 101 | } |
102 | } else | 102 | } else |
103 | show_usage(); | 103 | bb_show_usage(); |
104 | } | 104 | } |
105 | 105 | ||
106 | buf = xmalloc(bs); | 106 | buf = xmalloc(bs); |
107 | 107 | ||
108 | if (infile != NULL) { | 108 | if (infile != NULL) { |
109 | if ((ifd = open(infile, O_RDONLY)) < 0) { | 109 | if ((ifd = open(infile, O_RDONLY)) < 0) { |
110 | perror_msg_and_die("%s", infile); | 110 | bb_perror_msg_and_die("%s", infile); |
111 | } | 111 | } |
112 | } else { | 112 | } else { |
113 | ifd = STDIN_FILENO; | 113 | ifd = STDIN_FILENO; |
114 | infile = "standard input"; | 114 | infile = bb_msg_standard_input; |
115 | } | 115 | } |
116 | 116 | ||
117 | if (outfile != NULL) { | 117 | if (outfile != NULL) { |
@@ -122,7 +122,7 @@ int dd_main(int argc, char **argv) | |||
122 | } | 122 | } |
123 | 123 | ||
124 | if ((ofd = open(outfile, oflag, 0666)) < 0) { | 124 | if ((ofd = open(outfile, oflag, 0666)) < 0) { |
125 | perror_msg_and_die("%s", outfile); | 125 | bb_perror_msg_and_die("%s", outfile); |
126 | } | 126 | } |
127 | 127 | ||
128 | if (seek && trunc) { | 128 | if (seek && trunc) { |
@@ -131,24 +131,24 @@ int dd_main(int argc, char **argv) | |||
131 | 131 | ||
132 | if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) || | 132 | if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) || |
133 | S_ISDIR (st.st_mode)) { | 133 | S_ISDIR (st.st_mode)) { |
134 | perror_msg_and_die("%s", outfile); | 134 | bb_perror_msg_and_die("%s", outfile); |
135 | } | 135 | } |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | ofd = STDOUT_FILENO; | 139 | ofd = STDOUT_FILENO; |
140 | outfile = "standard output"; | 140 | outfile = bb_msg_standard_output; |
141 | } | 141 | } |
142 | 142 | ||
143 | if (skip) { | 143 | if (skip) { |
144 | if (lseek(ifd, skip * bs, SEEK_CUR) < 0) { | 144 | if (lseek(ifd, skip * bs, SEEK_CUR) < 0) { |
145 | perror_msg_and_die("%s", infile); | 145 | bb_perror_msg_and_die("%s", infile); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | if (seek) { | 149 | if (seek) { |
150 | if (lseek(ofd, seek * bs, SEEK_CUR) < 0) { | 150 | if (lseek(ofd, seek * bs, SEEK_CUR) < 0) { |
151 | perror_msg_and_die("%s", outfile); | 151 | bb_perror_msg_and_die("%s", outfile); |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
@@ -161,9 +161,9 @@ int dd_main(int argc, char **argv) | |||
161 | if (n < 0) { | 161 | if (n < 0) { |
162 | if (noerror) { | 162 | if (noerror) { |
163 | n = bs; | 163 | n = bs; |
164 | perror_msg("%s", infile); | 164 | bb_perror_msg("%s", infile); |
165 | } else { | 165 | } else { |
166 | perror_msg_and_die("%s", infile); | 166 | bb_perror_msg_and_die("%s", infile); |
167 | } | 167 | } |
168 | } | 168 | } |
169 | if (n == 0) { | 169 | if (n == 0) { |
@@ -178,9 +178,9 @@ int dd_main(int argc, char **argv) | |||
178 | memset(buf + n, '\0', bs - n); | 178 | memset(buf + n, '\0', bs - n); |
179 | n = bs; | 179 | n = bs; |
180 | } | 180 | } |
181 | n = full_write(ofd, buf, n); | 181 | n = bb_full_write(ofd, buf, n); |
182 | if (n < 0) { | 182 | if (n < 0) { |
183 | perror_msg_and_die("%s", outfile); | 183 | bb_perror_msg_and_die("%s", outfile); |
184 | } | 184 | } |
185 | if (n == bs) { | 185 | if (n == bs) { |
186 | out_full++; | 186 | out_full++; |
@@ -190,15 +190,16 @@ int dd_main(int argc, char **argv) | |||
190 | } | 190 | } |
191 | 191 | ||
192 | if (close (ifd) < 0) { | 192 | if (close (ifd) < 0) { |
193 | perror_msg_and_die("%s", infile); | 193 | bb_perror_msg_and_die("%s", infile); |
194 | } | 194 | } |
195 | 195 | ||
196 | if (close (ofd) < 0) { | 196 | if (close (ofd) < 0) { |
197 | perror_msg_and_die("%s", outfile); | 197 | bb_perror_msg_and_die("%s", outfile); |
198 | } | 198 | } |
199 | 199 | ||
200 | fprintf(stderr, "%ld+%ld records in\n", (long)in_full, (long)in_part); | 200 | fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n", |
201 | fprintf(stderr, "%ld+%ld records out\n", (long)out_full, (long)out_part); | 201 | (long)in_full, (long)in_part, |
202 | (long)out_full, (long)out_part); | ||
202 | 203 | ||
203 | return EXIT_SUCCESS; | 204 | return EXIT_SUCCESS; |
204 | } | 205 | } |