aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-18 11:44:57 +0100
committerRon Yorston <rmy@pobox.com>2023-04-18 11:44:57 +0100
commit2eeb7a1e5c5242784a0c24a88042f98b9e69963a (patch)
tree5b7919d95012cd6db7c3edb45cb0a59cb220d934
parent8cdeb571cfbf3bb6edc44779e46537b072b8cd08 (diff)
downloadbusybox-w32-2eeb7a1e5c5242784a0c24a88042f98b9e69963a.tar.gz
busybox-w32-2eeb7a1e5c5242784a0c24a88042f98b9e69963a.tar.bz2
busybox-w32-2eeb7a1e5c5242784a0c24a88042f98b9e69963a.zip
dd: omit direct flag
O_DIRECT isn't supported with open(2) on Microsoft Windows. All code related to the 'direct' input/output flag can be omitted. Saves 160 bytes.
-rw-r--r--coreutils/dd.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index a704ca99b..0989c9c2c 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -59,8 +59,13 @@
59//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]" 59//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]"
60//usage: IF_FEATURE_DD_IBS_OBS("\n" 60//usage: IF_FEATURE_DD_IBS_OBS("\n"
61//usage: " [conv=notrunc|noerror|sync|fsync]\n" 61//usage: " [conv=notrunc|noerror|sync|fsync]\n"
62//usage: IF_NOT_PLATFORM_MINGW32(
62//usage: " [iflag=skip_bytes|count_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]" 63//usage: " [iflag=skip_bytes|count_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]"
63//usage: ) 64//usage: )
65//usage: IF_PLATFORM_MINGW32(
66//usage: " [iflag=skip_bytes|count_bytes|fullblock] [oflag=seek_bytes|append]"
67//usage: )
68//usage: )
64//usage:#define dd_full_usage "\n\n" 69//usage:#define dd_full_usage "\n\n"
65//usage: "Copy a file with converting and formatting\n" 70//usage: "Copy a file with converting and formatting\n"
66//usage: "\n if=FILE Read from FILE instead of stdin" 71//usage: "\n if=FILE Read from FILE instead of stdin"
@@ -84,8 +89,10 @@
84//usage: "\n iflag=skip_bytes skip=N is in bytes" 89//usage: "\n iflag=skip_bytes skip=N is in bytes"
85//usage: "\n iflag=count_bytes count=N is in bytes" 90//usage: "\n iflag=count_bytes count=N is in bytes"
86//usage: "\n oflag=seek_bytes seek=N is in bytes" 91//usage: "\n oflag=seek_bytes seek=N is in bytes"
92//usage: IF_NOT_PLATFORM_MINGW32(
87//usage: "\n iflag=direct O_DIRECT input" 93//usage: "\n iflag=direct O_DIRECT input"
88//usage: "\n oflag=direct O_DIRECT output" 94//usage: "\n oflag=direct O_DIRECT output"
95//usage: )
89//usage: "\n iflag=fullblock Read full blocks" 96//usage: "\n iflag=fullblock Read full blocks"
90//usage: "\n oflag=append Open output in append mode" 97//usage: "\n oflag=append Open output in append mode"
91//usage: ) 98//usage: )
@@ -107,6 +114,10 @@
107#include "libbb.h" 114#include "libbb.h"
108#include "common_bufsiz.h" 115#include "common_bufsiz.h"
109 116
117#if ENABLE_PLATFORM_MINGW32
118# undef O_DIRECT
119#endif
120
110/* This is a NOEXEC applet. Be very careful! */ 121/* This is a NOEXEC applet. Be very careful! */
111 122
112 123
@@ -144,13 +155,13 @@ enum {
144 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, 155 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
145 FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, 156 FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
146 FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS, 157 FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
147 FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS, 158 FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS * ENABLE_PLATFORM_POSIX,
148 /* end of input flags */ 159 /* end of input flags */
149 /* start of output flags */ 160 /* start of output flags */
150 FLAG_OFLAG_SHIFT = 9, 161 FLAG_OFLAG_SHIFT = 9,
151 FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS, 162 FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
152 FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS, 163 FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS,
153 FLAG_ODIRECT = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS, 164 FLAG_ODIRECT = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS * ENABLE_PLATFORM_POSIX,
154 /* end of output flags */ 165 /* end of output flags */
155 FLAG_TWOBUFS = (1 << 12) * ENABLE_FEATURE_DD_IBS_OBS, 166 FLAG_TWOBUFS = (1 << 12) * ENABLE_FEATURE_DD_IBS_OBS,
156 FLAG_COUNT = 1 << 13, 167 FLAG_COUNT = 1 << 13,
@@ -223,7 +234,9 @@ static ssize_t dd_read(void *ibuf, size_t ibs)
223 ssize_t n; 234 ssize_t n;
224 235
225#if ENABLE_FEATURE_DD_IBS_OBS 236#if ENABLE_FEATURE_DD_IBS_OBS
237# if !ENABLE_PLATFORM_MINGW32
226 read_again: 238 read_again:
239# endif
227 if (G.flags & FLAG_FULLBLOCK) 240 if (G.flags & FLAG_FULLBLOCK)
228 n = full_read(ifd, ibuf, ibs); 241 n = full_read(ifd, ibuf, ibs);
229 else 242 else
@@ -243,7 +256,9 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
243{ 256{
244 ssize_t n; 257 ssize_t n;
245 258
259#if !ENABLE_PLATFORM_MINGW32
246 IF_FEATURE_DD_IBS_OBS(write_again:) 260 IF_FEATURE_DD_IBS_OBS(write_again:)
261#endif
247 n = full_write(ofd, buf, len); 262 n = full_write(ofd, buf, len);
248#if ENABLE_FEATURE_DD_IBS_OBS 263#if ENABLE_FEATURE_DD_IBS_OBS
249# ifdef O_DIRECT 264# ifdef O_DIRECT
@@ -331,9 +346,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
331 static const char conv_words[] ALIGN1 = 346 static const char conv_words[] ALIGN1 =
332 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; 347 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
333 static const char iflag_words[] ALIGN1 = 348 static const char iflag_words[] ALIGN1 =
334 "skip_bytes\0""count_bytes\0""fullblock\0""direct\0"; 349 "skip_bytes\0""count_bytes\0""fullblock\0"IF_PLATFORM_POSIX("direct\0");
335 static const char oflag_words[] ALIGN1 = 350 static const char oflag_words[] ALIGN1 =
336 "seek_bytes\0append\0""direct\0"; 351 "seek_bytes\0append\0"IF_PLATFORM_POSIX("direct\0");
337#endif 352#endif
338#if ENABLE_FEATURE_DD_STATUS 353#if ENABLE_FEATURE_DD_STATUS
339 static const char status_words[] ALIGN1 = 354 static const char status_words[] ALIGN1 =