dd: support iseek= and oseek=

Alias iseek=N to skip=N, oseek=N to seek=N (Bug#45648).
* src/dd.c (scanargs): Parse iseek= and oseek=.
* tests/dd/skip-seek.pl (sk-seek5): New test case.
This commit is contained in:
Paul Eggert
2022-02-21 11:23:02 -08:00
parent 3f7519130a
commit 4439ef3ec4
4 changed files with 27 additions and 10 deletions

3
NEWS
View File

@@ -57,6 +57,9 @@ GNU coreutils NEWS -*- outline -*-
dd conv=fsync now synchronizes output even after a write error,
and similarly for dd conv=fdatasync.
dd now supports the aliases iseek=N for skip=N, and oseek=N for seek=N,
like FreeBSD and other operating systems.
timeout --foreground --kill-after=... will now exit with status 137
if the kill signal was sent, which is consistent with the behavior
when the --foreground option is not specified. This allows users to

View File

@@ -9189,8 +9189,7 @@ Read from @var{file} instead of standard input.
@item of=@var{file}
@opindex of
Write to @var{file} instead of standard output. Unless
@samp{conv=notrunc} is given, @command{dd} truncates @var{file} to zero
bytes (or the size specified with @samp{seek=}).
@samp{conv=notrunc} is given, truncate @var{file} before writing it.
@item ibs=@var{bytes}
@opindex ibs
@@ -9230,15 +9229,20 @@ When converting variable-length records to fixed-length ones
use @var{bytes} as the fixed record length.
@item skip=@var{n}
@itemx iseek=@var{n}
@opindex skip
@opindex iseek
Skip @var{n} @samp{ibs}-byte blocks in the input file before copying.
If @samp{iflag=skip_bytes} is specified, @var{n} is interpreted
as a byte count rather than a block count.
@item seek=@var{n}
@itemx oseek=@var{n}
@opindex seek
Skip @var{n} @samp{obs}-byte blocks in the output file before copying.
if @samp{oflag=seek_bytes} is specified, @var{n} is interpreted
@opindex oseek
Skip @var{n} @samp{obs}-byte blocks in the output file before
truncating or copying.
If @samp{oflag=seek_bytes} is specified, @var{n} is interpreted
as a byte count rather than a block count.
@item count=@var{n}
@@ -9588,14 +9592,14 @@ This flag can be used only with @code{iflag}.
@item skip_bytes
@opindex skip_bytes
Interpret the @samp{skip=} operand as a byte count,
Interpret the @samp{skip=} or @samp{iseek=} operand as a byte count,
rather than a block count, which allows specifying
an offset that is not a multiple of the I/O block size.
This flag can be used only with @code{iflag}.
@item seek_bytes
@opindex seek_bytes
Interpret the @samp{seek=} operand as a byte count,
Interpret the @samp{seek=} or @samp{oseek=} operand as a byte count,
rather than a block count, which allows specifying
an offset that is not a multiple of the I/O block size.
This flag can be used only with @code{oflag}.

View File

@@ -562,8 +562,8 @@ Copy a file, converting and formatting according to the operands.\n\
obs=BYTES write BYTES bytes at a time (default: 512)\n\
of=FILE write to FILE instead of stdout\n\
oflag=FLAGS write as per the comma separated symbol list\n\
seek=N skip N obs-sized blocks at start of output\n\
skip=N skip N ibs-sized blocks at start of input\n\
seek=N (or oseek=N) skip N obs-sized output blocks\n\
skip=N (or iseek=N) skip N ibs-sized input blocks\n\
status=LEVEL The LEVEL of information to print to stderr;\n\
'none' suppresses everything but error messages,\n\
'noxfer' suppresses the final transfer statistics,\n\
@@ -1564,9 +1564,9 @@ scanargs (int argc, char *const *argv)
n_max = MIN (SIZE_MAX, IDX_MAX);
converted_idx = &conversion_blocksize;
}
else if (operand_is (name, "skip"))
else if (operand_is (name, "skip") || operand_is (name, "iseek"))
skip = n;
else if (operand_is (name, "seek"))
else if (operand_is (name + (*name == 'o'), "seek"))
seek = n;
else if (operand_is (name, "count"))
count = n;

View File

@@ -68,6 +68,16 @@ my @Tests =
{OUT=> "bc\n"},
{ERR=> "3+0 records in\n3+0 records out\n"},
],
[
# Check that iseek and oseek aliases work too.
'sk-seek5',
qw (bs=1 iseek=1 oseek=2 conv=notrunc count=3 status=noxfer of=@AUX@ < ),
{IN=> '0123456789abcdef'},
{AUX=> 'zyxwvutsrqponmlkji'},
{OUT=> ''},
{ERR=> "3+0 records in\n3+0 records out\n"},
{CMP=> ['zy123utsrqponmlkji', {'@AUX@'=> undef}]},
],
);
my $save_temps = $ENV{DEBUG};