From: Jim Meyering Date: Mon, 26 Apr 1999 13:31:49 +0000 (+0000) Subject: (main): If you can't open an output file (with seek=...) read-write, X-Git-Tag: SH-UTILS-1_16h~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9622d451400664794421c44343dbbdfc7b2d6704;p=thirdparty%2Fcoreutils.git (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. --- diff --git a/src/dd.c b/src/dd.c index eebd2143e0..09d5f44b19 100644 --- a/src/dd.c +++ b/src/dd.c @@ -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