]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Open the output file with *read* access
authorJim Meyering <jim@meyering.net>
Sun, 18 Apr 1999 13:32:35 +0000 (13:32 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 18 Apr 1999 13:32:35 +0000 (13:32 +0000)
only if we might need to read to satisfy a `seek=' request.
From Matthias Urlichs.

src/dd.c

index e4d3cc9e4e1bdc2d950c1dab7563d9951b2653be..c4a013ec169bd86180fea30385ca4e48bca5878a 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -1121,7 +1121,9 @@ main (int argc, char **argv)
 
   if (output_file != NULL)
     {
-      int omode = O_RDWR | O_CREAT;
+      /* 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;