svn commit: trunk/busybox: coreutils e2fsprogs include networking

vda at busybox.net vda at busybox.net
Sat Oct 7 16:24:47 UTC 2006


Author: vda
Date: 2006-10-07 09:24:46 -0700 (Sat, 07 Oct 2006)
New Revision: 16340

Log:
dd: make it recognize not only 'k' but 'K' too;
make it (partially) CONFIG_LFS-aware


Modified:
   trunk/busybox/coreutils/dd.c
   trunk/busybox/e2fsprogs/chattr.c
   trunk/busybox/e2fsprogs/lsattr.c
   trunk/busybox/e2fsprogs/util.c
   trunk/busybox/include/libbb.h
   trunk/busybox/networking/httpd.c
   trunk/busybox/networking/wget.c


Changeset:
Modified: trunk/busybox/coreutils/dd.c
===================================================================
--- trunk/busybox/coreutils/dd.c	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/coreutils/dd.c	2006-10-07 16:24:46 UTC (rev 16340)
@@ -17,6 +17,7 @@
 	{ "b", 512 },
 	{ "kD", 1000 },
 	{ "k", 1024 },
+	{ "K", 1024 },	// compat with coreutils dd
 	{ "MD", 1000000 },
 	{ "M", 1048576 },
 	{ "GD", 1000000000 },
@@ -24,25 +25,26 @@
 	{ 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;
@@ -58,6 +60,7 @@
 	}
 
 	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;
@@ -80,7 +83,7 @@
 			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;
@@ -105,14 +108,14 @@
 		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;
@@ -134,7 +137,7 @@
 	}
 
 	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)
@@ -146,7 +149,7 @@
 	}
 
 	if (seek) {
-		if (lseek(ofd, seek * obs, SEEK_CUR) < 0)
+		if (LSEEK(ofd, seek * obs, SEEK_CUR) < 0)
 			goto die_outfile;
 	}
 

Modified: trunk/busybox/e2fsprogs/chattr.c
===================================================================
--- trunk/busybox/e2fsprogs/chattr.c	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/e2fsprogs/chattr.c	2006-10-07 16:24:46 UTC (rev 16340)
@@ -53,14 +53,6 @@
 static unsigned long rf;
 static unsigned long sf;
 
-#ifdef CONFIG_LFS
-# define LSTAT lstat64
-# define STRUCT_STAT struct stat64
-#else
-# define LSTAT lstat
-# define STRUCT_STAT struct stat
-#endif
-
 struct flags_char {
 	unsigned long flag;
 	char optchar;

Modified: trunk/busybox/e2fsprogs/lsattr.c
===================================================================
--- trunk/busybox/e2fsprogs/lsattr.c	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/e2fsprogs/lsattr.c	2006-10-07 16:24:46 UTC (rev 16340)
@@ -41,14 +41,6 @@
 #define OPT_GENERATION 16
 static int flags;
 
-#ifdef CONFIG_LFS
-# define LSTAT lstat64
-# define STRUCT_STAT struct stat64
-#else
-# define LSTAT lstat
-# define STRUCT_STAT struct stat
-#endif
-
 static void list_attributes(const char *name)
 {
 	unsigned long fsflags;

Modified: trunk/busybox/e2fsprogs/util.c
===================================================================
--- trunk/busybox/e2fsprogs/util.c	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/e2fsprogs/util.c	2006-10-07 16:24:46 UTC (rev 16340)
@@ -33,13 +33,8 @@
 void check_plausibility(const char *device, int force)
 {
 	int val;
-#ifdef CONFIG_LFS
-	struct stat64 s;
-	val = stat64(device, &s);
-#else
-	struct stat s;
-	val = stat(device, &s);
-#endif
+	STRUCT_STAT s;
+	val = STAT(device, &s);
 	if (force)
 		return;
 	if(val == -1)

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/include/libbb.h	2006-10-07 16:24:46 UTC (rev 16340)
@@ -61,6 +61,31 @@
 #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)

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/networking/httpd.c	2006-10-07 16:24:46 UTC (rev 16340)
@@ -97,14 +97,6 @@
 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
@@ -927,8 +919,8 @@
 
 	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;

Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2006-10-07 15:16:19 UTC (rev 16339)
+++ trunk/busybox/networking/wget.c	2006-10-07 16:24:46 UTC (rev 16340)
@@ -13,22 +13,6 @@
 #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; */




More information about the busybox-cvs mailing list