aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-07 16:24:46 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-07 16:24:46 +0000
commit81177b14907e73f11560f69e0b4ec34371f1a7d5 (patch)
tree4146667d4080f97bc39ac96d844c01a8956aeeca
parentf7d58374dc37783b8033054dc284567c8c1d03fb (diff)
downloadbusybox-w32-81177b14907e73f11560f69e0b4ec34371f1a7d5.tar.gz
busybox-w32-81177b14907e73f11560f69e0b4ec34371f1a7d5.tar.bz2
busybox-w32-81177b14907e73f11560f69e0b4ec34371f1a7d5.zip
dd: make it recognize not only 'k' but 'K' too;
make it (partially) CONFIG_LFS-aware git-svn-id: svn://busybox.net/trunk/busybox@16340 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/dd.c31
-rw-r--r--e2fsprogs/chattr.c8
-rw-r--r--e2fsprogs/lsattr.c8
-rw-r--r--e2fsprogs/util.c9
-rw-r--r--include/libbb.h25
-rw-r--r--networking/httpd.c12
-rw-r--r--networking/wget.c16
7 files changed, 46 insertions, 63 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 8d859ef5c..e63244d81 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -17,6 +17,7 @@ static const struct suffix_mult dd_suffixes[] = {
17 { "b", 512 }, 17 { "b", 512 },
18 { "kD", 1000 }, 18 { "kD", 1000 },
19 { "k", 1024 }, 19 { "k", 1024 },
20 { "K", 1024 }, // compat with coreutils dd
20 { "MD", 1000000 }, 21 { "MD", 1000000 },
21 { "M", 1048576 }, 22 { "M", 1048576 },
22 { "GD", 1000000000 }, 23 { "GD", 1000000000 },
@@ -24,25 +25,26 @@ static const struct suffix_mult dd_suffixes[] = {
24 { NULL, 0 } 25 { NULL, 0 }
25}; 26};
26 27
27static size_t out_full, out_part, in_full, in_part; 28static FILEOFF_TYPE out_full, out_part, in_full, in_part;
28 29
29static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal) 30static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
30{ 31{
31 bb_fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n", 32 bb_fprintf(stderr, FILEOFF_FMT"+"FILEOFF_FMT" records in\n"
32 (long)in_full, (long)in_part, 33 FILEOFF_FMT"+"FILEOFF_FMT" records out\n",
33 (long)out_full, (long)out_part); 34 in_full, in_part,
35 out_full, out_part);
34} 36}
35 37
36int dd_main(int argc, char **argv) 38int dd_main(int argc, char **argv)
37{ 39{
38#define sync_flag (1<<0) 40#define sync_flag (1<<0)
39#define noerror (1<<1) 41#define noerror (1<<1)
40#define trunc_flag (1<<2) 42#define trunc_flag (1<<2)
41#define twobufs_flag (1<<3) 43#define twobufs_flag (1<<3)
42 int flags = trunc_flag; 44 int flags = trunc_flag;
43 size_t count = -1, oc = 0, ibs = 512, obs = 512; 45 size_t oc = 0, ibs = 512, obs = 512;
44 ssize_t n; 46 ssize_t n;
45 off_t seek = 0, skip = 0; 47 FILEOFF_TYPE seek = 0, skip = 0, count = MAX_FILEOFF_TYPE;
46 int oflag, ifd, ofd; 48 int oflag, ifd, ofd;
47 const char *infile = NULL, *outfile = NULL; 49 const char *infile = NULL, *outfile = NULL;
48 char *ibuf, *obuf; 50 char *ibuf, *obuf;
@@ -58,6 +60,7 @@ int dd_main(int argc, char **argv)
58 } 60 }
59 61
60 for (n = 1; n < argc; n++) { 62 for (n = 1; n < argc; n++) {
63 // FIXME: make them capable of eating LARGE numbers
61 if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) { 64 if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) {
62 ibs = bb_xparse_number(argv[n]+4, dd_suffixes); 65 ibs = bb_xparse_number(argv[n]+4, dd_suffixes);
63 flags |= twobufs_flag; 66 flags |= twobufs_flag;
@@ -80,7 +83,7 @@ int dd_main(int argc, char **argv)
80 ibuf = argv[n]+5; 83 ibuf = argv[n]+5;
81 while (1) { 84 while (1) {
82 if (!strncmp("notrunc", ibuf, 7)) { 85 if (!strncmp("notrunc", ibuf, 7)) {
83 flags ^= trunc_flag; 86 flags &= ~trunc_flag;
84 ibuf += 7; 87 ibuf += 7;
85 } else if (!strncmp("sync", ibuf, 4)) { 88 } else if (!strncmp("sync", ibuf, 4)) {
86 flags |= sync_flag; 89 flags |= sync_flag;
@@ -105,14 +108,14 @@ int dd_main(int argc, char **argv)
105 obuf = ibuf; 108 obuf = ibuf;
106 109
107 if (infile != NULL) 110 if (infile != NULL)
108 ifd = xopen(infile, O_RDONLY); 111 ifd = xopen(infile, O_RDONLY | (O_LARGEFILE * ENABLE_LFS));
109 else { 112 else {
110 ifd = STDIN_FILENO; 113 ifd = STDIN_FILENO;
111 infile = bb_msg_standard_input; 114 infile = bb_msg_standard_input;
112 } 115 }
113 116
114 if (outfile != NULL) { 117 if (outfile != NULL) {
115 oflag = O_WRONLY | O_CREAT; 118 oflag = O_WRONLY | O_CREAT | (O_LARGEFILE * ENABLE_LFS);
116 119
117 if (!seek && (flags & trunc_flag)) 120 if (!seek && (flags & trunc_flag))
118 oflag |= O_TRUNC; 121 oflag |= O_TRUNC;
@@ -134,7 +137,7 @@ int dd_main(int argc, char **argv)
134 } 137 }
135 138
136 if (skip) { 139 if (skip) {
137 if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { 140 if (LSEEK(ifd, skip * ibs, SEEK_CUR) < 0) {
138 while (skip-- > 0) { 141 while (skip-- > 0) {
139 n = safe_read(ifd, ibuf, ibs); 142 n = safe_read(ifd, ibuf, ibs);
140 if (n < 0) 143 if (n < 0)
@@ -146,7 +149,7 @@ int dd_main(int argc, char **argv)
146 } 149 }
147 150
148 if (seek) { 151 if (seek) {
149 if (lseek(ofd, seek * obs, SEEK_CUR) < 0) 152 if (LSEEK(ofd, seek * obs, SEEK_CUR) < 0)
150 goto die_outfile; 153 goto die_outfile;
151 } 154 }
152 155
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c
index 2cb75e86f..618d8c440 100644
--- a/e2fsprogs/chattr.c
+++ b/e2fsprogs/chattr.c
@@ -53,14 +53,6 @@ static unsigned long af;
53static unsigned long rf; 53static unsigned long rf;
54static unsigned long sf; 54static unsigned long sf;
55 55
56#ifdef CONFIG_LFS
57# define LSTAT lstat64
58# define STRUCT_STAT struct stat64
59#else
60# define LSTAT lstat
61# define STRUCT_STAT struct stat
62#endif
63
64struct flags_char { 56struct flags_char {
65 unsigned long flag; 57 unsigned long flag;
66 char optchar; 58 char optchar;
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c
index e76f8d9d7..1b7cf44aa 100644
--- a/e2fsprogs/lsattr.c
+++ b/e2fsprogs/lsattr.c
@@ -41,14 +41,6 @@
41#define OPT_GENERATION 16 41#define OPT_GENERATION 16
42static int flags; 42static int flags;
43 43
44#ifdef CONFIG_LFS
45# define LSTAT lstat64
46# define STRUCT_STAT struct stat64
47#else
48# define LSTAT lstat
49# define STRUCT_STAT struct stat
50#endif
51
52static void list_attributes(const char *name) 44static void list_attributes(const char *name)
53{ 45{
54 unsigned long fsflags; 46 unsigned long fsflags;
diff --git a/e2fsprogs/util.c b/e2fsprogs/util.c
index efb128f59..aaee50ae6 100644
--- a/e2fsprogs/util.c
+++ b/e2fsprogs/util.c
@@ -33,13 +33,8 @@ void proceed_question(void)
33void check_plausibility(const char *device, int force) 33void check_plausibility(const char *device, int force)
34{ 34{
35 int val; 35 int val;
36#ifdef CONFIG_LFS 36 STRUCT_STAT s;
37 struct stat64 s; 37 val = STAT(device, &s);
38 val = stat64(device, &s);
39#else
40 struct stat s;
41 val = stat(device, &s);
42#endif
43 if (force) 38 if (force)
44 return; 39 return;
45 if(val == -1) 40 if(val == -1)
diff --git a/include/libbb.h b/include/libbb.h
index 84c8af4b6..11e1e62d9 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -61,6 +61,31 @@
61#define PATH_MAX 256 61#define PATH_MAX 256
62#endif 62#endif
63 63
64/* Large file support */
65#ifdef CONFIG_LFS
66# define FILEOFF_TYPE off64_t
67# define FILEOFF_FMT "%lld"
68# define LSEEK lseek64
69# define STAT stat64
70# define LSTAT lstat64
71# define STRUCT_STAT struct stat64
72# define STRTOOFF strtoll
73# define SAFE_STRTOOFF safe_strtoll
74#else
75# define FILEOFF_TYPE off_t
76# define FILEOFF_FMT "%ld"
77# define LSEEK lseek
78# define STAT stat
79# define LSTAT lstat
80# define STRUCT_STAT struct stat
81# define STRTOOFF strtol
82# define SAFE_STRTOOFF safe_strtol
83/* Do we need to undefine O_LARGEFILE? */
84#endif
85/* scary. better ideas? (but do *test* them first!) */
86#define MAX_FILEOFF_TYPE \
87 ((FILEOFF_TYPE)~((FILEOFF_TYPE)1 << (sizeof(FILEOFF_TYPE)*8-1)))
88
64/* Some useful definitions */ 89/* Some useful definitions */
65#undef FALSE 90#undef FALSE
66#define FALSE ((int) 0) 91#define FALSE ((int) 0)
diff --git a/networking/httpd.c b/networking/httpd.c
index 8f985774e..0e471ba58 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -97,14 +97,6 @@ static const char default_path_httpd_conf[] = "/etc";
97static const char httpd_conf[] = "httpd.conf"; 97static const char httpd_conf[] = "httpd.conf";
98static const char home[] = "./"; 98static const char home[] = "./";
99 99
100#if ENABLE_LFS
101# define cont_l_fmt "%lld"
102# define cont_l_type (long long)
103#else
104# define cont_l_fmt "%ld"
105# define cont_l_type (long)
106#endif
107
108#define TIMEOUT 60 100#define TIMEOUT 60
109 101
110// Note: busybox xfuncs are not used because we want the server to keep running 102// Note: busybox xfuncs are not used because we want the server to keep running
@@ -927,8 +919,8 @@ static int sendHeaders(HttpResponseNum responseNum)
927 919
928 if (config->ContentLength != -1) { /* file */ 920 if (config->ContentLength != -1) { /* file */
929 strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod)); 921 strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod));
930 len += sprintf(buf+len, "Last-Modified: %s\r\n%s " cont_l_fmt "\r\n", 922 len += sprintf(buf+len, "Last-Modified: %s\r\n%s "FILEOFF_FMT"\r\n",
931 timeStr, Content_length, cont_l_type config->ContentLength); 923 timeStr, Content_length, (FILEOFF_TYPE) config->ContentLength);
932 } 924 }
933 strcat(buf, "\r\n"); 925 strcat(buf, "\r\n");
934 len += 2; 926 len += 2;
diff --git a/networking/wget.c b/networking/wget.c
index 788c291b9..eda0bb87c 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -13,22 +13,6 @@
13#include "busybox.h" 13#include "busybox.h"
14#include <getopt.h> /* for struct option */ 14#include <getopt.h> /* for struct option */
15 15
16#ifdef CONFIG_LFS
17# define FILEOFF_TYPE off64_t
18# define FILEOFF_FMT "%lld"
19# define LSEEK lseek64
20# define STRTOOFF strtoll
21# define SAFE_STRTOOFF safe_strtoll
22/* stat64 etc as needed... */
23#else
24# define FILEOFF_TYPE off_t
25# define FILEOFF_FMT "%ld"
26# define LSEEK lseek
27# define STRTOOFF strtol
28# define SAFE_STRTOOFF safe_strtol
29/* Do we need to undefine O_LARGEFILE? */
30#endif
31
32struct host_info { 16struct host_info {
33 // May be used if we ever will want to free() all xstrdup()s... 17 // May be used if we ever will want to free() all xstrdup()s...
34 /* char *allocated; */ 18 /* char *allocated; */