Repository navigation
dd: implement it - #244
dd: implement it#244metif12 wants to merge 3 commits into
Conversation
Copies a file, converting and formatting according to the operands: if, of, bs, ibs, obs, cbs, count, skip, iseek, seek, status, conv and the iflag/oflag lists. Operand parsing and the copy live in common/dd; src/dd is a thin main that owns the stderr summary, for the same reason the other recent tools keep their logic in a module. skip and seek count blocks unless skip_bytes/seek_bytes make them byte offsets, count counts records unless count_bytes, and conv=sync pads a short final block. The unit suffixes were measured, not guessed: a bare K is 1024 while KB is 1000, so bs=1K and bs=1KB deliberately read different amounts. swab exchanges pairs within a block rather than across the whole buffer, which is why bs=1 leaves the data untouched. status=none prints nothing and status=noxfer drops the byte total, because the elapsed time and rate are not reproducible and so are not printed at all. Differential against uutils 0.0.17 on this machine covers the block sizes, both unit conventions, skip/count with and without their _bytes flags, the conversions, status=none, and the failure cases. Not implemented and refused rather than faked: the EBCDIC-family conversions, which need cbs; --filter; and the iflag/oflag hints that only make sense on POSIX.
common/dd/dd.v called C.write() directly and declared `fn C.write` in the
same pure .v file. The pinned V rejects that outright:
common/dd/dd.v:219:4: error: C code will not be allowed in pure .v files,
please move it to a .c.v file instead
This is the same defect and the same fix as vlang#252 for nohup, which already
landed: the C declaration and the call to it have to sit on opposite sides
of the .c.v boundary. So common/dd/dd.c.v now holds the declaration plus a
pub write_fds wrapper, and dd.v calls that wrapper.
Kept the `unsafe` block at the call site unchanged. It is there for
`data.data`, not for the C call, and moving it would be a behavioural
change this bug fix does not need.
Verified: dd builds and `hello world | dd` still reports 15 bytes copied
through the new wrapper, and v fmt -verify is clean on both files. The
rejection itself is not reproducible on the compiler available here, which
still permits C calls in a .v file; it comes from the pinned CI revision.
|
This PR does not build as it stands. Same defect and same fix as #252, which already landed for The Verified: One limit worth stating: the rejection itself is not reproducible with the compiler available on this machine, which still permits C calls in a |
ddcopies a file, converting and formatting according to the operands:if,of,bs,ibs,obs,cbs,count,skip,iseek,seek,status,convand theiflag/oflaglists.Operand parsing and the copy live in
common/dd;src/ddis a thin main that owns the stderr summary, for the same reason the other recent tools keep their logic in a module —v test <dir>compiles only_test.vfiles.skipandseekcount blocks unlessskip_bytes/seek_bytesmake them byte offsets,countcounts records unlesscount_bytes, andconv=syncpads a short final block.The unit suffixes were measured, not guessed: a bare
Kis 1024 whileKBis 1000, sobs=1Kandbs=1KBdeliberately read different amounts of the same input.swabexchanges pairs within a block rather than across the whole buffer, which is whybs=1leaves the data untouched — a distinction the first draft got wrong and the differential test caught.status=noneprints nothing andstatus=noxferdrops the byte total. The elapsed time and rate are not printed at all, because they are not reproducible and a test that compares them would be comparing noise.Differential against uutils 0.0.17 on this machine covers the block sizes, both unit conventions, skip and count with and without their
_bytesflags, the conversions,status=none, and the failure cases. There is a control run too: makingswaba no-op turns the suite red with0123456789where the reference gives1032547698.Not implemented, and refused rather than faked: the EBCDIC-family conversions, which need
cbs;--filter; and theiflag/oflaghints that only mean something on POSIX.