diff options
author | Jim Meyering <jim@meyering.net> | 1999-04-26 13:31:49 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-04-26 13:31:49 +0000 |
commit | 9622d451400664794421c44343dbbdfc7b2d6704 (patch) | |
tree | 21fabac533d03516da2092ec9bb41a463adab870 /src | |
parent | 890a087101afdaf2de7442c3d737e8d29b92ded8 (diff) | |
download | coreutils-9622d451400664794421c44343dbbdfc7b2d6704.tar.xz |
(main): If you can't open an output file (with seek=...) read-write,
then open it for write and report an error if we can't seek.
Diffstat (limited to 'src')
-rw-r--r-- | src/dd.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1043,16 +1043,18 @@ main (int argc, char **argv) if (output_file != NULL) { + mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + int opts + = (O_CREAT + | (seek_record || (conversions_mask & C_NOTRUNC) ? 0 : O_TRUNC)); + /* Open the output file with *read* access only if we might - need to read to satisfy a `seek=' request. */ - int omode = (seek_record ? O_RDWR : O_WRONLY) | O_CREAT; - - if (seek_record == 0 && !(conversions_mask & C_NOTRUNC)) - omode |= O_TRUNC; - output_fd = open (output_file, omode, - (S_IRUSR | S_IWUSR - | S_IRGRP | S_IWGRP - | S_IROTH | S_IWOTH)); + need to read to satisfy a `seek=' request. If we can't read + the file, go ahead with write-only access; it might work. */ + if (! seek_record + || (output_fd = open (output_file, O_RDWR | opts, perms)) < 0) + output_fd = open (output_file, O_WRONLY | opts, perms); + if (output_fd < 0) error (1, errno, "%s", output_file); #if HAVE_FTRUNCATE |