4 #define BIG ((1UL<<31)-1)
5 #define VBIG ((1ULL<<63)-1)
55 vlong number(vlong big);
66 #define iskey(s) ((key[0] == '-') && (strcmp(key+1, s) == 0))
69 main(int argc, char *argv[])
77 for(c=1; c<argc; c++) {
80 fprint(2, "dd: arg %s needs a value\n", key);
109 dotrunc = number(BIG);
120 if(iskey("seek") || iskey("oseek")) {
121 oseekn = number(VBIG);
125 iseekn = number(VBIG);
129 count = number(VBIG);
142 if(match("ebcdic")) {
158 if(match("unblock")) {
174 if(match("noerror")) {
182 fprint(2, "dd: bad conv %s\n", argv[c]);
185 fprint(2, "dd: bad arg: %s\n", key);
188 if(conv == null && cflag&(LCASE|UCASE))
191 ibf = open(ifile, 0);
195 fprint(2, "dd: open %s: %r\n", ifile);
200 obf = create(ofile, 1, 0664);
202 obf = open(ofile, 1);
204 fprint(2, "dd: create %s: %r\n", ofile);
210 fprint(2, "dd: can't dup file descriptor: %s: %r\n", ofile);
216 if(ibs == obs && conv == null)
218 if(ibs == 0 || obs == 0) {
219 fprint(2, "dd: counts: cannot be zero\n");
227 sbrk(64); /* For good measure */
228 if(ibuf == (char *)-1 || obuf == (char *)-1) {
229 fprint(2, "dd: not enough memory: %r\n");
238 if(signal(SIGINT, SIG_IGN) != SIG_IGN)
239 signal(SIGINT, term);
241 seek(obf, obs*oseekn, 1);
242 seek(ibf, ibs*iseekn, 1);
244 read(ibf, ibuf, ibs);
252 if(count==0 || nifr+nipr!=count) {
253 if(cflag&(NERR|SYNC))
254 for(ip=ibuf+ibs; ip>ibuf;)
256 ibc = read(ibf, ibuf, ibs);
260 if((cflag&NERR) == 0) {
270 }else if(ibc == 0 && --files<=0) {
309 /* don't perror dregs of previous errors on a short write */
311 c = write(obf, obuf, obc);
352 while(*cs >= '0' && *cs <= '9')
353 n = n*10 + *cs++ - '0';
372 fprint(2, "dd: argument %llud out of range\n", n);
377 /* never gets here */
386 if((cflag&UCASE) && c>='a' && c<='z')
388 if((cflag&LCASE) && c>='A' && c<='Z')
467 if(cflag&UCASE && c>='a' && c<='z')
469 if(cflag&LCASE && c>='A' && c<='Z')
497 if(cflag&UCASE && c>='a' && c<='z')
499 if(cflag&LCASE && c>='A' && c<='Z')
501 c = atoibm[c] & 0377;
527 if(cflag&UCASE && c>='a' && c<='z')
529 if(cflag&LCASE && c>='A' && c<='Z')
563 fprint(2, "%lud+%lud records in\n", nifr, nipr);
564 fprint(2, "%lud+%lud records out\n", nofr, nopr);
566 fprint(2, "%lud truncated records\n", ntrunc);
571 0000,0001,0002,0003,0234,0011,0206,0177,
572 0227,0215,0216,0013,0014,0015,0016,0017,
573 0020,0021,0022,0023,0235,0205,0010,0207,
574 0030,0031,0222,0217,0034,0035,0036,0037,
575 0200,0201,0202,0203,0204,0012,0027,0033,
576 0210,0211,0212,0213,0214,0005,0006,0007,
577 0220,0221,0026,0223,0224,0225,0226,0004,
578 0230,0231,0232,0233,0024,0025,0236,0032,
579 0040,0240,0241,0242,0243,0244,0245,0246,
580 0247,0250,0133,0056,0074,0050,0053,0041,
581 0046,0251,0252,0253,0254,0255,0256,0257,
582 0260,0261,0135,0044,0052,0051,0073,0136,
583 0055,0057,0262,0263,0264,0265,0266,0267,
584 0270,0271,0174,0054,0045,0137,0076,0077,
585 0272,0273,0274,0275,0276,0277,0300,0301,
586 0302,0140,0072,0043,0100,0047,0075,0042,
587 0303,0141,0142,0143,0144,0145,0146,0147,
588 0150,0151,0304,0305,0306,0307,0310,0311,
589 0312,0152,0153,0154,0155,0156,0157,0160,
590 0161,0162,0313,0314,0315,0316,0317,0320,
591 0321,0176,0163,0164,0165,0166,0167,0170,
592 0171,0172,0322,0323,0324,0325,0326,0327,
593 0330,0331,0332,0333,0334,0335,0336,0337,
594 0340,0341,0342,0343,0344,0345,0346,0347,
595 0173,0101,0102,0103,0104,0105,0106,0107,
596 0110,0111,0350,0351,0352,0353,0354,0355,
597 0175,0112,0113,0114,0115,0116,0117,0120,
598 0121,0122,0356,0357,0360,0361,0362,0363,
599 0134,0237,0123,0124,0125,0126,0127,0130,
600 0131,0132,0364,0365,0366,0367,0370,0371,
601 0060,0061,0062,0063,0064,0065,0066,0067,
602 0070,0071,0372,0373,0374,0375,0376,0377,
606 0000,0001,0002,0003,0067,0055,0056,0057,
607 0026,0005,0045,0013,0014,0015,0016,0017,
608 0020,0021,0022,0023,0074,0075,0062,0046,
609 0030,0031,0077,0047,0034,0035,0036,0037,
610 0100,0117,0177,0173,0133,0154,0120,0175,
611 0115,0135,0134,0116,0153,0140,0113,0141,
612 0360,0361,0362,0363,0364,0365,0366,0367,
613 0370,0371,0172,0136,0114,0176,0156,0157,
614 0174,0301,0302,0303,0304,0305,0306,0307,
615 0310,0311,0321,0322,0323,0324,0325,0326,
616 0327,0330,0331,0342,0343,0344,0345,0346,
617 0347,0350,0351,0112,0340,0132,0137,0155,
618 0171,0201,0202,0203,0204,0205,0206,0207,
619 0210,0211,0221,0222,0223,0224,0225,0226,
620 0227,0230,0231,0242,0243,0244,0245,0246,
621 0247,0250,0251,0300,0152,0320,0241,0007,
622 0040,0041,0042,0043,0044,0025,0006,0027,
623 0050,0051,0052,0053,0054,0011,0012,0033,
624 0060,0061,0032,0063,0064,0065,0066,0010,
625 0070,0071,0072,0073,0004,0024,0076,0341,
626 0101,0102,0103,0104,0105,0106,0107,0110,
627 0111,0121,0122,0123,0124,0125,0126,0127,
628 0130,0131,0142,0143,0144,0145,0146,0147,
629 0150,0151,0160,0161,0162,0163,0164,0165,
630 0166,0167,0170,0200,0212,0213,0214,0215,
631 0216,0217,0220,0232,0233,0234,0235,0236,
632 0237,0240,0252,0253,0254,0255,0256,0257,
633 0260,0261,0262,0263,0264,0265,0266,0267,
634 0270,0271,0272,0273,0274,0275,0276,0277,
635 0312,0313,0314,0315,0316,0317,0332,0333,
636 0334,0335,0336,0337,0352,0353,0354,0355,
637 0356,0357,0372,0373,0374,0375,0376,0377,
641 0000,0001,0002,0003,0067,0055,0056,0057,
642 0026,0005,0045,0013,0014,0015,0016,0017,
643 0020,0021,0022,0023,0074,0075,0062,0046,
644 0030,0031,0077,0047,0034,0035,0036,0037,
645 0100,0132,0177,0173,0133,0154,0120,0175,
646 0115,0135,0134,0116,0153,0140,0113,0141,
647 0360,0361,0362,0363,0364,0365,0366,0367,
648 0370,0371,0172,0136,0114,0176,0156,0157,
649 0174,0301,0302,0303,0304,0305,0306,0307,
650 0310,0311,0321,0322,0323,0324,0325,0326,
651 0327,0330,0331,0342,0343,0344,0345,0346,
652 0347,0350,0351,0255,0340,0275,0137,0155,
653 0171,0201,0202,0203,0204,0205,0206,0207,
654 0210,0211,0221,0222,0223,0224,0225,0226,
655 0227,0230,0231,0242,0243,0244,0245,0246,
656 0247,0250,0251,0300,0117,0320,0241,0007,
657 0040,0041,0042,0043,0044,0025,0006,0027,
658 0050,0051,0052,0053,0054,0011,0012,0033,
659 0060,0061,0032,0063,0064,0065,0066,0010,
660 0070,0071,0072,0073,0004,0024,0076,0341,
661 0101,0102,0103,0104,0105,0106,0107,0110,
662 0111,0121,0122,0123,0124,0125,0126,0127,
663 0130,0131,0142,0143,0144,0145,0146,0147,
664 0150,0151,0160,0161,0162,0163,0164,0165,
665 0166,0167,0170,0200,0212,0213,0214,0215,
666 0216,0217,0220,0232,0233,0234,0235,0236,
667 0237,0240,0252,0253,0254,0255,0256,0257,
668 0260,0261,0262,0263,0264,0265,0266,0267,
669 0270,0271,0272,0273,0274,0275,0276,0277,
670 0312,0313,0314,0315,0316,0317,0332,0333,
671 0334,0335,0336,0337,0352,0353,0354,0355,
672 0356,0357,0372,0373,0374,0375,0376,0377,