{ "b", 512 },
{ "kD", 1000 },
{ "k", 1024 },
+ { "K", 1024 }, // compat with coreutils dd
{ "MD", 1000000 },
{ "M", 1048576 },
{ "GD", 1000000000 },
{ NULL, 0 }
};
-static size_t out_full, out_part, in_full, in_part;
+static FILEOFF_TYPE out_full, out_part, in_full, in_part;
static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
{
- bb_fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n",
- (long)in_full, (long)in_part,
- (long)out_full, (long)out_part);
+ bb_fprintf(stderr, FILEOFF_FMT"+"FILEOFF_FMT" records in\n"
+ FILEOFF_FMT"+"FILEOFF_FMT" records out\n",
+ in_full, in_part,
+ out_full, out_part);
}
int dd_main(int argc, char **argv)
{
-#define sync_flag (1<<0)
-#define noerror (1<<1)
-#define trunc_flag (1<<2)
+#define sync_flag (1<<0)
+#define noerror (1<<1)
+#define trunc_flag (1<<2)
#define twobufs_flag (1<<3)
int flags = trunc_flag;
- size_t count = -1, oc = 0, ibs = 512, obs = 512;
+ size_t oc = 0, ibs = 512, obs = 512;
ssize_t n;
- off_t seek = 0, skip = 0;
+ FILEOFF_TYPE seek = 0, skip = 0, count = MAX_FILEOFF_TYPE;
int oflag, ifd, ofd;
const char *infile = NULL, *outfile = NULL;
char *ibuf, *obuf;
}
for (n = 1; n < argc; n++) {
+ // FIXME: make them capable of eating LARGE numbers
if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) {
ibs = bb_xparse_number(argv[n]+4, dd_suffixes);
flags |= twobufs_flag;
ibuf = argv[n]+5;
while (1) {
if (!strncmp("notrunc", ibuf, 7)) {
- flags ^= trunc_flag;
+ flags &= ~trunc_flag;
ibuf += 7;
} else if (!strncmp("sync", ibuf, 4)) {
flags |= sync_flag;
obuf = ibuf;
if (infile != NULL)
- ifd = xopen(infile, O_RDONLY);
+ ifd = xopen(infile, O_RDONLY | (O_LARGEFILE * ENABLE_LFS));
else {
ifd = STDIN_FILENO;
infile = bb_msg_standard_input;
}
if (outfile != NULL) {
- oflag = O_WRONLY | O_CREAT;
+ oflag = O_WRONLY | O_CREAT | (O_LARGEFILE * ENABLE_LFS);
if (!seek && (flags & trunc_flag))
oflag |= O_TRUNC;
}
if (skip) {
- if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
+ if (LSEEK(ifd, skip * ibs, SEEK_CUR) < 0) {
while (skip-- > 0) {
n = safe_read(ifd, ibuf, ibs);
if (n < 0)
}
if (seek) {
- if (lseek(ofd, seek * obs, SEEK_CUR) < 0)
+ if (LSEEK(ofd, seek * obs, SEEK_CUR) < 0)
goto die_outfile;
}
#define PATH_MAX 256
#endif
+/* Large file support */
+#ifdef CONFIG_LFS
+# define FILEOFF_TYPE off64_t
+# define FILEOFF_FMT "%lld"
+# define LSEEK lseek64
+# define STAT stat64
+# define LSTAT lstat64
+# define STRUCT_STAT struct stat64
+# define STRTOOFF strtoll
+# define SAFE_STRTOOFF safe_strtoll
+#else
+# define FILEOFF_TYPE off_t
+# define FILEOFF_FMT "%ld"
+# define LSEEK lseek
+# define STAT stat
+# define LSTAT lstat
+# define STRUCT_STAT struct stat
+# define STRTOOFF strtol
+# define SAFE_STRTOOFF safe_strtol
+/* Do we need to undefine O_LARGEFILE? */
+#endif
+/* scary. better ideas? (but do *test* them first!) */
+#define MAX_FILEOFF_TYPE \
+ ((FILEOFF_TYPE)~((FILEOFF_TYPE)1 << (sizeof(FILEOFF_TYPE)*8-1)))
+
/* Some useful definitions */
#undef FALSE
#define FALSE ((int) 0)
static const char httpd_conf[] = "httpd.conf";
static const char home[] = "./";
-#if ENABLE_LFS
-# define cont_l_fmt "%lld"
-# define cont_l_type (long long)
-#else
-# define cont_l_fmt "%ld"
-# define cont_l_type (long)
-#endif
-
#define TIMEOUT 60
// Note: busybox xfuncs are not used because we want the server to keep running
if (config->ContentLength != -1) { /* file */
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod));
- len += sprintf(buf+len, "Last-Modified: %s\r\n%s " cont_l_fmt "\r\n",
- timeStr, Content_length, cont_l_type config->ContentLength);
+ len += sprintf(buf+len, "Last-Modified: %s\r\n%s "FILEOFF_FMT"\r\n",
+ timeStr, Content_length, (FILEOFF_TYPE) config->ContentLength);
}
strcat(buf, "\r\n");
len += 2;
#include "busybox.h"
#include <getopt.h> /* for struct option */
-#ifdef CONFIG_LFS
-# define FILEOFF_TYPE off64_t
-# define FILEOFF_FMT "%lld"
-# define LSEEK lseek64
-# define STRTOOFF strtoll
-# define SAFE_STRTOOFF safe_strtoll
-/* stat64 etc as needed... */
-#else
-# define FILEOFF_TYPE off_t
-# define FILEOFF_FMT "%ld"
-# define LSEEK lseek
-# define STRTOOFF strtol
-# define SAFE_STRTOOFF safe_strtol
-/* Do we need to undefine O_LARGEFILE? */
-#endif
-
struct host_info {
// May be used if we ever will want to free() all xstrdup()s...
/* char *allocated; */