Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site oddjob.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!oddjob!matt From: matt@oddjob.UUCP (Matt Crawford) Newsgroups: net.bugs.4bsd Subject: dd bug -- clobbers output file Message-ID: <679@oddjob.UUCP> Date: Thu, 18-Apr-85 15:51:57 EST Article-I.D.: oddjob.679 Posted: Thu Apr 18 15:51:57 1985 Date-Received: Fri, 19-Apr-85 01:22:43 EST Reply-To: matt@oddjob.UUCP (Matt Crawford) Organization: U. Chicago, Astronomy & Astrophysics Lines: 35 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 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@anl-mcs.arpa Crawford of Chicago ihnp4!oddjob!matt