- char *inFile = NULL;
- char *outFile = NULL;
- char *cp;
- int inFd;
- int outFd;
- int inCc = 0;
- int outCc;
- long blockSize = 512;
- uintmax_t skipBlocks = 0;
- uintmax_t seekBlocks = 0;
- uintmax_t count = (uintmax_t) - 1;
- uintmax_t intotal;
- uintmax_t outTotal;
- unsigned char *buf;
-
- argc--;
- argv++;
-
- /* Parse any options */
- while (argc) {
- if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
- inFile = ((strchr(*argv, '=')) + 1);
- else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
- outFile = ((strchr(*argv, '=')) + 1);
- else if (strncmp("count", *argv, 5) == 0) {
- count = getNum((strchr(*argv, '=')) + 1);
- if (count <= 0) {
- errorMsg("Bad count value %s\n", *argv);
- goto usage;
- }
- } else if (strncmp(*argv, "bs", 2) == 0) {
- blockSize = getNum((strchr(*argv, '=')) + 1);
- if (blockSize <= 0) {
- errorMsg("Bad block size value %s\n", *argv);
- goto usage;
- }
- } else if (strncmp(*argv, "skip", 4) == 0) {
- skipBlocks = getNum((strchr(*argv, '=')) + 1);
- if (skipBlocks <= 0) {
- errorMsg("Bad skip value %s\n", *argv);
- goto usage;
+ size_t out_full = 0;
+ size_t out_part = 0;
+ size_t in_full = 0;
+ size_t in_part = 0;
+ size_t count = -1;
+ size_t bs = 512;
+ ssize_t n;
+ off_t seek = 0;
+ off_t skip = 0;
+ int sync_flag = FALSE;
+ int noerror = FALSE;
+ int trunc = TRUE;
+ int oflag;
+ int ifd;
+ int ofd;
+ int i;
+ const char *infile = NULL;
+ const char *outfile = NULL;
+ char *buf;
+
+ for (i = 1; i < argc; i++) {
+ if (strncmp("bs=", argv[i], 3) == 0)
+ bs = bb_xparse_number(argv[i]+3, dd_suffixes);
+ else if (strncmp("count=", argv[i], 6) == 0)
+ count = bb_xparse_number(argv[i]+6, dd_suffixes);
+ else if (strncmp("seek=", argv[i], 5) == 0)
+ seek = bb_xparse_number(argv[i]+5, dd_suffixes);
+ else if (strncmp("skip=", argv[i], 5) == 0)
+ skip = bb_xparse_number(argv[i]+5, dd_suffixes);
+ else if (strncmp("if=", argv[i], 3) == 0)
+ infile = argv[i]+3;
+ else if (strncmp("of=", argv[i], 3) == 0)
+ outfile = argv[i]+3;
+ else if (strncmp("conv=", argv[i], 5) == 0) {
+ buf = argv[i]+5;
+ while (1) {
+ if (strncmp("notrunc", buf, 7) == 0) {
+ trunc = FALSE;
+ buf += 7;
+ } else if (strncmp("sync", buf, 4) == 0) {
+ sync_flag = TRUE;
+ buf += 4;
+ } else if (strncmp("noerror", buf, 7) == 0) {
+ noerror = TRUE;
+ buf += 7;
+ } else {
+ bb_error_msg_and_die("invalid conversion `%s'", argv[i]+5);
+ }
+ if (buf[0] == '\0')
+ break;
+ if (buf[0] == ',')
+ buf++;