dd bug -- clobbers output file
Matt Crawford
matt at oddjob.UUCP
Fri Apr 19 06:51:57 AEST 1985
I can hardly believe that this hasn't been discovered before, but
since I've seen no mention of it I'm sending it out.
Subject: dd clobbers output file
Index: bin/dd.c 4.2BSD
Description:
dd truncates its output file before writing. This is clearly
not a `feature' because it makes the seek=n option useless.
Repeat-By:
Create a file "infile" longer than, say, 50 bytes.
dd if=infile of=outfile bs=50 count=1
dd if=infile of=outfile bs=50 skip=1 seek=1
outfile and infile should now be identical but in fact the
first 50 bytes of outfile will be zeros.
Fix:
dd opens its output file by calling creat(). This truncates.
The later lseek() fills the first record with zeros.
RCS file: RCS/dd.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -r1.1 -r1.2
3a4
> #include <sys/file.h>
258c259
< obf = creat(ofile, 0666);
---
> obf = open(ofile, O_WRONLY|O_CREAT, 0666);
"It's true, your honor. This node has no disk."
_____________________________________________________
Matt University crawford at anl-mcs.arpa
Crawford of Chicago ihnp4!oddjob!matt
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list