- const char * str;
- const PARAM * par;
- const char * inFile;
- const char * outFile;
- char * cp;
- int inFd;
- int outFd;
- int inCc=0;
- int outCc;
- int blockSize;
- long count;
- long intotal;
- long outTotal;
- unsigned char* buf;
- unsigned char localBuf[BUF_SIZE];
-
- inFile = NULL;
- outFile = NULL;
- blockSize = 512;
- count = 1;
-
-
- while (--argc > 0)
- {
- str = *++argv;
- cp = strchr(str, '=');
-
- if (cp == NULL)
- {
- fprintf(stderr, "Bad dd argument\n");
- goto usage;
- }
-
- *cp++ = '\0';
-
- for (par = params; par->name; par++)
- {
- if (strcmp(str, par->name) == 0)
- break;
- }
-
- switch (par->value)
- {
- case PAR_IF:
- if (inFile)
- {
- fprintf(stderr, "Multiple input files illegal\n");
- goto usage;
- }
-
- //fprintf(stderr, "if=%s\n", cp);
- inFile = cp;
- break;
-
- case PAR_OF:
- if (outFile)
- {
- fprintf(stderr, "Multiple output files illegal\n");
- goto usage;
- }
-
- //fprintf(stderr, "of=%s\n", cp);
- outFile = cp;
- break;
-
- case PAR_BS:
- blockSize = getNum(cp);
- //fprintf(stderr, "bs=%d\n", blockSize);
-
- if (blockSize <= 0)
- {
- fprintf(stderr, "Bad block size value\n");
- goto usage;
- }
-
- break;
-
- case PAR_COUNT:
- count = getNum(cp);
- //fprintf(stderr, "count=%ld\n", count);
-
- if (count < 0)
- {
- fprintf(stderr, "Bad count value\n");
- goto usage;
- }
-
- break;
-
- default:
+ char *inFile = NULL;
+ char *outFile = NULL;
+ int inFd;
+ int outFd;
+ int inCc = 0;
+ int outCc;
+ int trunc=TRUE;
+ int sync=FALSE;
+ long blockSize = 512,ibs;
+ uintmax_t skipBlocks = 0;
+ uintmax_t seekBlocks = 0;
+ uintmax_t count = (uintmax_t) - 1;
+ uintmax_t inTotal = 0;
+ uintmax_t outTotal = 0;
+ uintmax_t totalSize;
+
+ unsigned char buf[BUFSIZ];
+ char *keyword = NULL;
+
+ 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);