diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-08 17:54:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-08 17:54:47 +0000 |
commit | 7039a66b58706457c7423de60556e04545432943 (patch) | |
tree | a512daebc3674c819766664c8ea17d41ef7fef02 | |
parent | 1385899416a4396385ad421ae1f532be7103738a (diff) | |
download | busybox-w32-7039a66b58706457c7423de60556e04545432943.tar.gz busybox-w32-7039a66b58706457c7423de60556e04545432943.tar.bz2 busybox-w32-7039a66b58706457c7423de60556e04545432943.zip |
correct largefile support, add comments about it.
-rw-r--r-- | Makefile.flags | 26 | ||||
-rw-r--r-- | archival/tar.c | 2 | ||||
-rw-r--r-- | archival/unzip.c | 5 | ||||
-rw-r--r-- | coreutils/cat.c | 7 | ||||
-rw-r--r-- | coreutils/catv.c | 6 | ||||
-rw-r--r-- | coreutils/dd.c | 16 | ||||
-rw-r--r-- | e2fsprogs/chattr.c | 4 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 8 | ||||
-rw-r--r-- | e2fsprogs/util.c | 6 | ||||
-rw-r--r-- | include/libbb.h | 70 | ||||
-rw-r--r-- | libbb/copyfd.c | 10 | ||||
-rw-r--r-- | libbb/loop.c | 4 | ||||
-rw-r--r-- | networking/ftpgetput.c | 20 | ||||
-rw-r--r-- | networking/httpd.c | 4 | ||||
-rw-r--r-- | networking/wget.c | 24 |
15 files changed, 121 insertions, 91 deletions
diff --git a/Makefile.flags b/Makefile.flags index 39c544e60..f5eb65faf 100644 --- a/Makefile.flags +++ b/Makefile.flags | |||
@@ -4,16 +4,16 @@ | |||
4 | 4 | ||
5 | BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) | 5 | BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) |
6 | 6 | ||
7 | CPPFLAGS += \ | 7 | CPPFLAGS += \ |
8 | -Iinclude -Ilibbb \ | 8 | -Iinclude -Ilibbb \ |
9 | $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \ | 9 | $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \ |
10 | -include include/autoconf.h \ | 10 | -include include/autoconf.h \ |
11 | -D_GNU_SOURCE -DNDEBUG \ | 11 | -D_GNU_SOURCE -DNDEBUG \ |
12 | -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \ | 12 | $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \ |
13 | -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP \ | 13 | -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP \ |
14 | -Wall -Wstrict-prototypes -Wshadow -Werror \ | 14 | -Wall -Wstrict-prototypes -Wshadow -Werror \ |
15 | -funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \ | 15 | -funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \ |
16 | -Os -march=i386 -mpreferred-stack-boundary=2 \ | 16 | -Os -march=i386 -mpreferred-stack-boundary=2 \ |
17 | -falign-functions=1 -falign-jumps=1 -falign-loops=1 \ | 17 | -falign-functions=1 -falign-jumps=1 -falign-loops=1 \ |
18 | -fomit-frame-pointer -ffunction-sections -fdata-sections \ | 18 | -fomit-frame-pointer -ffunction-sections -fdata-sections \ |
19 | -funsigned-char -fno-builtin-strlen \ | 19 | -funsigned-char -fno-builtin-strlen \ |
diff --git a/archival/tar.c b/archival/tar.c index b2ae3b2af..28bb14776 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -376,7 +376,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
376 | 376 | ||
377 | /* If it was a regular file, write out the body */ | 377 | /* If it was a regular file, write out the body */ |
378 | if (inputFileFd >= 0) { | 378 | if (inputFileFd >= 0) { |
379 | ssize_t readSize = 0; | 379 | off_t readSize = 0; |
380 | 380 | ||
381 | /* write the file to the archive */ | 381 | /* write the file to the archive */ |
382 | readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd); | 382 | readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd); |
diff --git a/archival/unzip.c b/archival/unzip.c index f70baebf9..2aa380dc8 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -51,7 +51,6 @@ typedef union { | |||
51 | } formatted ATTRIBUTE_PACKED; | 51 | } formatted ATTRIBUTE_PACKED; |
52 | } zip_header_t; | 52 | } zip_header_t; |
53 | 53 | ||
54 | /* This one never works with LARGEFILE-sized skips */ | ||
55 | static void unzip_skip(int fd, off_t skip) | 54 | static void unzip_skip(int fd, off_t skip) |
56 | { | 55 | { |
57 | if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { | 56 | if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { |
@@ -75,7 +74,7 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | |||
75 | { | 74 | { |
76 | if (zip_header->formatted.method == 0) { | 75 | if (zip_header->formatted.method == 0) { |
77 | /* Method 0 - stored (not compressed) */ | 76 | /* Method 0 - stored (not compressed) */ |
78 | int size = zip_header->formatted.ucmpsize; | 77 | off_t size = zip_header->formatted.ucmpsize; |
79 | if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) { | 78 | if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) { |
80 | bb_error_msg_and_die("cannot complete extraction"); | 79 | bb_error_msg_and_die("cannot complete extraction"); |
81 | } | 80 | } |
@@ -202,7 +201,7 @@ int unzip_main(int argc, char **argv) | |||
202 | } | 201 | } |
203 | if (src_fd == -1) { | 202 | if (src_fd == -1) { |
204 | src_fn[orig_src_fn_len] = 0; | 203 | src_fn[orig_src_fn_len] = 0; |
205 | bb_error_msg_and_die("Cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn); | 204 | bb_error_msg_and_die("cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn); |
206 | } | 205 | } |
207 | } | 206 | } |
208 | 207 | ||
diff --git a/coreutils/cat.c b/coreutils/cat.c index f3baf0a2d..10eb29c4d 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file License in this tarball for details. | 7 | * Licensed under GPLv2, see file License in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | /* BB_AUDIT SUSv3 compliant */ | 10 | /* BB_AUDIT SUSv3 compliant */ |
@@ -26,8 +26,9 @@ int cat_main(int argc, char **argv) | |||
26 | } | 26 | } |
27 | 27 | ||
28 | do { | 28 | do { |
29 | if ((f = bb_wfopen_input(*argv)) != NULL) { | 29 | f = bb_wfopen_input(*argv); |
30 | int r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); | 30 | if (f) { |
31 | off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); | ||
31 | bb_fclose_nonstdin(f); | 32 | bb_fclose_nonstdin(f); |
32 | if (r >= 0) { | 33 | if (r >= 0) { |
33 | continue; | 34 | continue; |
diff --git a/coreutils/catv.c b/coreutils/catv.c index 55656b4b2..a5a8b43e4 100644 --- a/coreutils/catv.c +++ b/coreutils/catv.c | |||
@@ -15,7 +15,7 @@ | |||
15 | int catv_main(int argc, char **argv) | 15 | int catv_main(int argc, char **argv) |
16 | { | 16 | { |
17 | int retval = EXIT_SUCCESS, fd; | 17 | int retval = EXIT_SUCCESS, fd; |
18 | unsigned long flags; | 18 | unsigned flags; |
19 | 19 | ||
20 | flags = getopt32(argc, argv, "etv"); | 20 | flags = getopt32(argc, argv, "etv"); |
21 | #define CATV_OPT_e (1<<0) | 21 | #define CATV_OPT_e (1<<0) |
@@ -51,8 +51,8 @@ int catv_main(int argc, char **argv) | |||
51 | } | 51 | } |
52 | if (c < 32) { | 52 | if (c < 32) { |
53 | if (c == 10) { | 53 | if (c == 10) { |
54 | if (flags & CATV_OPT_e) | 54 | if (flags & CATV_OPT_e) |
55 | putchar('$'); | 55 | putchar('$'); |
56 | } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) { | 56 | } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) { |
57 | bb_printf("^%c", c+'@'); | 57 | bb_printf("^%c", c+'@'); |
58 | continue; | 58 | continue; |
diff --git a/coreutils/dd.c b/coreutils/dd.c index d557ae46d..d60192e7c 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -25,12 +25,12 @@ static const struct suffix_mult dd_suffixes[] = { | |||
25 | { NULL, 0 } | 25 | { NULL, 0 } |
26 | }; | 26 | }; |
27 | 27 | ||
28 | static FILEOFF_TYPE out_full, out_part, in_full, in_part; | 28 | static off_t out_full, out_part, in_full, in_part; |
29 | 29 | ||
30 | static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal) | 30 | static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal) |
31 | { | 31 | { |
32 | bb_fprintf(stderr, FILEOFF_FMT"+"FILEOFF_FMT" records in\n" | 32 | bb_fprintf(stderr, OFF_FMT"+"OFF_FMT" records in\n" |
33 | FILEOFF_FMT"+"FILEOFF_FMT" records out\n", | 33 | OFF_FMT"+"OFF_FMT" records out\n", |
34 | in_full, in_part, | 34 | in_full, in_part, |
35 | out_full, out_part); | 35 | out_full, out_part); |
36 | } | 36 | } |
@@ -44,7 +44,7 @@ int dd_main(int argc, char **argv) | |||
44 | int flags = trunc_flag; | 44 | int flags = trunc_flag; |
45 | size_t oc = 0, ibs = 512, obs = 512; | 45 | size_t oc = 0, ibs = 512, obs = 512; |
46 | ssize_t n; | 46 | ssize_t n; |
47 | FILEOFF_TYPE seek = 0, skip = 0, count = MAX_FILEOFF_TYPE; | 47 | off_t seek = 0, skip = 0, count = OFF_T_MAX; |
48 | int oflag, ifd, ofd; | 48 | int oflag, ifd, ofd; |
49 | const char *infile = NULL, *outfile = NULL; | 49 | const char *infile = NULL, *outfile = NULL; |
50 | char *ibuf, *obuf; | 50 | char *ibuf, *obuf; |
@@ -108,14 +108,14 @@ int dd_main(int argc, char **argv) | |||
108 | obuf = ibuf; | 108 | obuf = ibuf; |
109 | 109 | ||
110 | if (infile != NULL) | 110 | if (infile != NULL) |
111 | ifd = xopen(infile, O_RDONLY | (O_LARGEFILE * ENABLE_LFS)); | 111 | ifd = xopen(infile, O_RDONLY); |
112 | else { | 112 | else { |
113 | ifd = STDIN_FILENO; | 113 | ifd = STDIN_FILENO; |
114 | infile = bb_msg_standard_input; | 114 | infile = bb_msg_standard_input; |
115 | } | 115 | } |
116 | 116 | ||
117 | if (outfile != NULL) { | 117 | if (outfile != NULL) { |
118 | oflag = O_WRONLY | O_CREAT | (O_LARGEFILE * ENABLE_LFS); | 118 | oflag = O_WRONLY | O_CREAT; |
119 | 119 | ||
120 | if (!seek && (flags & trunc_flag)) | 120 | if (!seek && (flags & trunc_flag)) |
121 | oflag |= O_TRUNC; | 121 | oflag |= O_TRUNC; |
@@ -137,7 +137,7 @@ int dd_main(int argc, char **argv) | |||
137 | } | 137 | } |
138 | 138 | ||
139 | if (skip) { | 139 | if (skip) { |
140 | if (LSEEK(ifd, skip * ibs, SEEK_CUR) < 0) { | 140 | if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { |
141 | while (skip-- > 0) { | 141 | while (skip-- > 0) { |
142 | n = safe_read(ifd, ibuf, ibs); | 142 | n = safe_read(ifd, ibuf, ibs); |
143 | if (n < 0) | 143 | if (n < 0) |
@@ -149,7 +149,7 @@ int dd_main(int argc, char **argv) | |||
149 | } | 149 | } |
150 | 150 | ||
151 | if (seek) { | 151 | if (seek) { |
152 | if (LSEEK(ofd, seek * obs, SEEK_CUR) < 0) | 152 | if (lseek(ofd, seek * obs, SEEK_CUR) < 0) |
153 | goto die_outfile; | 153 | goto die_outfile; |
154 | } | 154 | } |
155 | 155 | ||
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index 618d8c440..4c341627e 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c | |||
@@ -112,9 +112,9 @@ static int chattr_dir_proc(const char *, struct dirent *, void *); | |||
112 | static void change_attributes(const char * name) | 112 | static void change_attributes(const char * name) |
113 | { | 113 | { |
114 | unsigned long fsflags; | 114 | unsigned long fsflags; |
115 | STRUCT_STAT st; | 115 | struct stat st; |
116 | 116 | ||
117 | if (LSTAT(name, &st) == -1) { | 117 | if (lstat(name, &st) == -1) { |
118 | bb_error_msg("stat %s failed", name); | 118 | bb_error_msg("stat %s failed", name); |
119 | return; | 119 | return; |
120 | } | 120 | } |
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 1b7cf44aa..13d5acf01 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -72,9 +72,9 @@ static int lsattr_dir_proc(const char *, struct dirent *, void *); | |||
72 | 72 | ||
73 | static void lsattr_args(const char *name) | 73 | static void lsattr_args(const char *name) |
74 | { | 74 | { |
75 | STRUCT_STAT st; | 75 | struct stat st; |
76 | 76 | ||
77 | if (LSTAT(name, &st) == -1) { | 77 | if (lstat(name, &st) == -1) { |
78 | bb_perror_msg("stating %s", name); | 78 | bb_perror_msg("stating %s", name); |
79 | } else { | 79 | } else { |
80 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) | 80 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) |
@@ -87,12 +87,12 @@ static void lsattr_args(const char *name) | |||
87 | static int lsattr_dir_proc(const char *dir_name, struct dirent *de, | 87 | static int lsattr_dir_proc(const char *dir_name, struct dirent *de, |
88 | void *private) | 88 | void *private) |
89 | { | 89 | { |
90 | STRUCT_STAT st; | 90 | struct stat st; |
91 | char *path; | 91 | char *path; |
92 | 92 | ||
93 | path = concat_path_file(dir_name, de->d_name); | 93 | path = concat_path_file(dir_name, de->d_name); |
94 | 94 | ||
95 | if (LSTAT(path, &st) == -1) | 95 | if (lstat(path, &st) == -1) |
96 | bb_perror_msg(path); | 96 | bb_perror_msg(path); |
97 | else { | 97 | else { |
98 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { | 98 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { |
diff --git a/e2fsprogs/util.c b/e2fsprogs/util.c index aaee50ae6..e68c457e7 100644 --- a/e2fsprogs/util.c +++ b/e2fsprogs/util.c | |||
@@ -33,12 +33,12 @@ void proceed_question(void) | |||
33 | void check_plausibility(const char *device, int force) | 33 | void check_plausibility(const char *device, int force) |
34 | { | 34 | { |
35 | int val; | 35 | int val; |
36 | STRUCT_STAT s; | 36 | struct stat s; |
37 | val = STAT(device, &s); | 37 | val = stat(device, &s); |
38 | if (force) | 38 | if (force) |
39 | return; | 39 | return; |
40 | if(val == -1) | 40 | if(val == -1) |
41 | bb_perror_msg_and_die("Could not stat %s", device); | 41 | bb_perror_msg_and_die("cannot stat %s", device); |
42 | if (!S_ISBLK(s.st_mode)) { | 42 | if (!S_ISBLK(s.st_mode)) { |
43 | printf("%s is not a block special device.\n", device); | 43 | printf("%s is not a block special device.\n", device); |
44 | proceed_question(); | 44 | proceed_question(); |
diff --git a/include/libbb.h b/include/libbb.h index a7c770400..bc86e5faf 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -61,30 +61,56 @@ | |||
61 | #define PATH_MAX 256 | 61 | #define PATH_MAX 256 |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | /* Not (yet) used, but tested to work correctly | ||
65 | #define MAXINT(T) (T)( \ | ||
66 | ((T)-1) > 0 \ | ||
67 | ? (T)-1 \ | ||
68 | : (T)~((T)1 << (sizeof(T)*8-1)) \ | ||
69 | ) | ||
70 | |||
71 | #define MININT(T) (T)( \ | ||
72 | ((T)-1) > 0 \ | ||
73 | ? (T)0 \ | ||
74 | : ((T)1 << (sizeof(T)*8-1)) \ | ||
75 | ) | ||
76 | */ | ||
77 | |||
64 | /* Large file support */ | 78 | /* Large file support */ |
65 | #ifdef CONFIG_LFS | 79 | /* Note that CONFIG_LFS forces bbox to be built with all common ops |
66 | # define FILEOFF_TYPE off64_t | 80 | * (stat, lseek etc) mapped to "largefile" variants by libc. |
67 | # define FILEOFF_FMT "%lld" | 81 | * Practically it means that open() automatically has O_LARGEFILE added |
68 | # define LSEEK lseek64 | 82 | * and all filesize/file_offset parameters and struct members are "large" |
69 | # define STAT stat64 | 83 | * (in today's world - signed 64bit). For full support of large files, |
70 | # define LSTAT lstat64 | 84 | * we need a few helper #defines (below) and careful use of off_t |
71 | # define STRUCT_STAT struct stat64 | 85 | * instead of int/ssize_t. No lseek64(), O_LARGEFILE etc necessary */ |
72 | # define STRTOOFF strtoll | 86 | #if ENBALE_LFS |
73 | # define SAFE_STRTOOFF safe_strtoll | 87 | /* CONFIG_LFS is on */ |
88 | # if ULONG_MAX > 0xffffffff | ||
89 | /* "long" is long enough on this system */ | ||
90 | # define STRTOOFF strtol | ||
91 | # define SAFE_STRTOOFF safe_strtol | ||
92 | # define OFF_FMT "%ld" | ||
93 | # else | ||
94 | /* "long" is too short, need "lomg long" */ | ||
95 | # define STRTOOFF strtoll | ||
96 | # define SAFE_STRTOOFF safe_strtoll | ||
97 | # define OFF_FMT "%lld" | ||
98 | # endif | ||
74 | #else | 99 | #else |
75 | # define FILEOFF_TYPE off_t | 100 | # if 0 /* UINT_MAX == 0xffffffff */ |
76 | # define FILEOFF_FMT "%ld" | 101 | /* Doesn't work. off_t is a long. gcc will throw warnings on printf("%d", off_t) |
77 | # define LSEEK lseek | 102 | * even if long==int on this arch. Crap... */ |
78 | # define STAT stat | 103 | # define STRTOOFF strtol |
79 | # define LSTAT lstat | 104 | # define SAFE_STRTOOFF safe_strtoi |
80 | # define STRUCT_STAT struct stat | 105 | # define OFF_FMT "%d" |
81 | # define STRTOOFF strtol | 106 | # else |
82 | # define SAFE_STRTOOFF safe_strtol | 107 | # define STRTOOFF strtol |
83 | /* Do we need to undefine O_LARGEFILE? */ | 108 | # define SAFE_STRTOOFF safe_strtol |
109 | # define OFF_FMT "%ld" | ||
110 | # endif | ||
84 | #endif | 111 | #endif |
85 | /* scary. better ideas? (but do *test* them first!) */ | 112 | /* scary. better ideas? (but do *test* them first!) */ |
86 | #define MAX_FILEOFF_TYPE \ | 113 | #define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1))) |
87 | ((FILEOFF_TYPE)~((FILEOFF_TYPE)1 << (sizeof(FILEOFF_TYPE)*8-1))) | ||
88 | 114 | ||
89 | /* Some useful definitions */ | 115 | /* Some useful definitions */ |
90 | #undef FALSE | 116 | #undef FALSE |
@@ -203,8 +229,8 @@ extern char *find_block_device(char *path); | |||
203 | extern char *bb_get_line_from_file(FILE *file); | 229 | extern char *bb_get_line_from_file(FILE *file); |
204 | extern char *bb_get_chomped_line_from_file(FILE *file); | 230 | extern char *bb_get_chomped_line_from_file(FILE *file); |
205 | extern char *bb_get_chunk_from_file(FILE *file, int *end); | 231 | extern char *bb_get_chunk_from_file(FILE *file, int *end); |
206 | extern int bb_copyfd_size(int fd1, int fd2, const off_t size); | 232 | extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); |
207 | extern int bb_copyfd_eof(int fd1, int fd2); | 233 | extern off_t bb_copyfd_eof(int fd1, int fd2); |
208 | extern char bb_process_escape_sequence(const char **ptr); | 234 | extern char bb_process_escape_sequence(const char **ptr); |
209 | extern char *bb_get_last_path_component(char *path); | 235 | extern char *bb_get_last_path_component(char *path); |
210 | extern FILE *bb_wfopen(const char *path, const char *mode); | 236 | extern FILE *bb_wfopen(const char *path, const char *mode); |
diff --git a/libbb/copyfd.c b/libbb/copyfd.c index e9300a97d..87126eb72 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c | |||
@@ -21,10 +21,10 @@ | |||
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | 23 | ||
24 | static ssize_t bb_full_fd_action(int src_fd, int dst_fd, size_t size) | 24 | static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) |
25 | { | 25 | { |
26 | int status = -1; | 26 | int status = -1; |
27 | size_t total = 0; | 27 | off_t total = 0; |
28 | RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); | 28 | RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); |
29 | 29 | ||
30 | if (src_fd < 0) goto out; | 30 | if (src_fd < 0) goto out; |
@@ -56,11 +56,11 @@ static ssize_t bb_full_fd_action(int src_fd, int dst_fd, size_t size) | |||
56 | out: | 56 | out: |
57 | RELEASE_CONFIG_BUFFER(buffer); | 57 | RELEASE_CONFIG_BUFFER(buffer); |
58 | 58 | ||
59 | return status ? status : (ssize_t)total; | 59 | return status ? status : total; |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | int bb_copyfd_size(int fd1, int fd2, const off_t size) | 63 | off_t bb_copyfd_size(int fd1, int fd2, off_t size) |
64 | { | 64 | { |
65 | if (size) { | 65 | if (size) { |
66 | return bb_full_fd_action(fd1, fd2, size); | 66 | return bb_full_fd_action(fd1, fd2, size); |
@@ -68,7 +68,7 @@ int bb_copyfd_size(int fd1, int fd2, const off_t size) | |||
68 | return 0; | 68 | return 0; |
69 | } | 69 | } |
70 | 70 | ||
71 | int bb_copyfd_eof(int fd1, int fd2) | 71 | off_t bb_copyfd_eof(int fd1, int fd2) |
72 | { | 72 | { |
73 | return bb_full_fd_action(fd1, fd2, 0); | 73 | return bb_full_fd_action(fd1, fd2, 0); |
74 | } | 74 | } |
diff --git a/libbb/loop.c b/libbb/loop.c index 1b296d99b..14835ec24 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -133,7 +133,9 @@ int set_loop(char **device, const char *file, unsigned long long offset) | |||
133 | without using losetup manually is problematic.) | 133 | without using losetup manually is problematic.) |
134 | */ | 134 | */ |
135 | } else if (strcmp(file,(char *)loopinfo.lo_file_name) | 135 | } else if (strcmp(file,(char *)loopinfo.lo_file_name) |
136 | || offset!=loopinfo.lo_offset) rc = -1; | 136 | || offset != loopinfo.lo_offset) { |
137 | rc = -1; | ||
138 | } | ||
137 | close(dfd); | 139 | close(dfd); |
138 | try_again: | 140 | try_again: |
139 | if (*device) break; | 141 | if (*device) break; |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 902528f93..5d13e289b 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -104,9 +104,11 @@ static FILE *ftp_login(ftp_host_info_t *server) | |||
104 | } | 104 | } |
105 | 105 | ||
106 | #if !ENABLE_FTPGET | 106 | #if !ENABLE_FTPGET |
107 | #define ftp_receive 0 | 107 | int ftp_receive(ftp_host_info_t *server, FILE *control_stream, |
108 | const char *local_path, char *server_path); | ||
108 | #else | 109 | #else |
109 | static int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | 110 | static |
111 | int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | ||
110 | const char *local_path, char *server_path) | 112 | const char *local_path, char *server_path) |
111 | { | 113 | { |
112 | char buf[512]; | 114 | char buf[512]; |
@@ -122,10 +124,8 @@ static int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | |||
122 | fd_data = xconnect_ftpdata(server, buf); | 124 | fd_data = xconnect_ftpdata(server, buf); |
123 | 125 | ||
124 | if (ftpcmd("SIZE ", server_path, control_stream, buf) == 213) { | 126 | if (ftpcmd("SIZE ", server_path, control_stream, buf) == 213) { |
125 | unsigned long value=filesize; | 127 | if (SAFE_STRTOOFF(buf + 4, &filesize)) |
126 | if (safe_strtoul(buf + 4, &value)) | ||
127 | bb_error_msg_and_die("SIZE error: %s", buf + 4); | 128 | bb_error_msg_and_die("SIZE error: %s", buf + 4); |
128 | filesize = value; | ||
129 | } else { | 129 | } else { |
130 | filesize = -1; | 130 | filesize = -1; |
131 | do_continue = 0; | 131 | do_continue = 0; |
@@ -139,7 +139,7 @@ static int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | |||
139 | if (do_continue) { | 139 | if (do_continue) { |
140 | struct stat sbuf; | 140 | struct stat sbuf; |
141 | if (lstat(local_path, &sbuf) < 0) { | 141 | if (lstat(local_path, &sbuf) < 0) { |
142 | bb_perror_msg_and_die("fstat()"); | 142 | bb_perror_msg_and_die("lstat"); |
143 | } | 143 | } |
144 | if (sbuf.st_size > 0) { | 144 | if (sbuf.st_size > 0) { |
145 | beg_range = sbuf.st_size; | 145 | beg_range = sbuf.st_size; |
@@ -149,7 +149,7 @@ static int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | |||
149 | } | 149 | } |
150 | 150 | ||
151 | if (do_continue) { | 151 | if (do_continue) { |
152 | sprintf(buf, "REST %ld", (long)beg_range); | 152 | sprintf(buf, "REST "OFF_FMT, beg_range); |
153 | if (ftpcmd(buf, NULL, control_stream, buf) != 350) { | 153 | if (ftpcmd(buf, NULL, control_stream, buf) != 350) { |
154 | do_continue = 0; | 154 | do_continue = 0; |
155 | } else { | 155 | } else { |
@@ -191,9 +191,11 @@ static int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | |||
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | #if !ENABLE_FTPPUT | 193 | #if !ENABLE_FTPPUT |
194 | #define ftp_send 0 | 194 | int ftp_send(ftp_host_info_t *server, FILE *control_stream, |
195 | const char *server_path, char *local_path); | ||
195 | #else | 196 | #else |
196 | static int ftp_send(ftp_host_info_t *server, FILE *control_stream, | 197 | static |
198 | int ftp_send(ftp_host_info_t *server, FILE *control_stream, | ||
197 | const char *server_path, char *local_path) | 199 | const char *server_path, char *local_path) |
198 | { | 200 | { |
199 | struct stat sbuf; | 201 | struct stat sbuf; |
diff --git a/networking/httpd.c b/networking/httpd.c index f3fe49cae..bbb2dfe7f 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -919,8 +919,8 @@ static int sendHeaders(HttpResponseNum responseNum) | |||
919 | 919 | ||
920 | if (config->ContentLength != -1) { /* file */ | 920 | if (config->ContentLength != -1) { /* file */ |
921 | strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod)); | 921 | strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod)); |
922 | len += sprintf(buf+len, "Last-Modified: %s\r\n%s "FILEOFF_FMT"\r\n", | 922 | len += sprintf(buf+len, "Last-Modified: %s\r\n%s "OFF_FMT"\r\n", |
923 | timeStr, Content_length, (FILEOFF_TYPE) config->ContentLength); | 923 | timeStr, Content_length, (off_t) config->ContentLength); |
924 | } | 924 | } |
925 | strcat(buf, "\r\n"); | 925 | strcat(buf, "\r\n"); |
926 | len += 2; | 926 | len += 2; |
diff --git a/networking/wget.c b/networking/wget.c index e7b19f2ef..74feccc36 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -29,9 +29,9 @@ static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); | |||
29 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); | 29 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); |
30 | 30 | ||
31 | /* Globals (can be accessed from signal handlers */ | 31 | /* Globals (can be accessed from signal handlers */ |
32 | static FILEOFF_TYPE content_len; /* Content-length of the file */ | 32 | static off_t content_len; /* Content-length of the file */ |
33 | static FILEOFF_TYPE beg_range; /* Range at which continue begins */ | 33 | static off_t beg_range; /* Range at which continue begins */ |
34 | static FILEOFF_TYPE transferred; /* Number of bytes transferred so far */ | 34 | static off_t transferred; /* Number of bytes transferred so far */ |
35 | static int chunked; /* chunked transfer encoding */ | 35 | static int chunked; /* chunked transfer encoding */ |
36 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 36 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
37 | static void progressmeter(int flag); | 37 | static void progressmeter(int flag); |
@@ -215,10 +215,10 @@ int wget_main(int argc, char **argv) | |||
215 | opt |= WGET_OPT_QUIET; | 215 | opt |= WGET_OPT_QUIET; |
216 | opt &= ~WGET_OPT_CONTINUE; | 216 | opt &= ~WGET_OPT_CONTINUE; |
217 | } else if (opt & WGET_OPT_CONTINUE) { | 217 | } else if (opt & WGET_OPT_CONTINUE) { |
218 | output_fd = open(fname_out, O_WRONLY|O_LARGEFILE); | 218 | output_fd = open(fname_out, O_WRONLY); |
219 | if (output_fd >= 0) { | 219 | if (output_fd >= 0) { |
220 | beg_range = LSEEK(output_fd, 0, SEEK_END); | 220 | beg_range = lseek(output_fd, 0, SEEK_END); |
221 | if (beg_range == (FILEOFF_TYPE)-1) | 221 | if (beg_range == (off_t)-1) |
222 | bb_perror_msg_and_die("lseek"); | 222 | bb_perror_msg_and_die("lseek"); |
223 | } | 223 | } |
224 | /* File doesn't exist. We do not create file here yet. | 224 | /* File doesn't exist. We do not create file here yet. |
@@ -282,7 +282,7 @@ int wget_main(int argc, char **argv) | |||
282 | #endif | 282 | #endif |
283 | 283 | ||
284 | if (beg_range) | 284 | if (beg_range) |
285 | fprintf(sfp, "Range: bytes="FILEOFF_FMT"-\r\n", beg_range); | 285 | fprintf(sfp, "Range: bytes="OFF_FMT"-\r\n", beg_range); |
286 | if(extra_headers_left < sizeof(extra_headers)) | 286 | if(extra_headers_left < sizeof(extra_headers)) |
287 | fputs(extra_headers,sfp); | 287 | fputs(extra_headers,sfp); |
288 | fprintf(sfp,"Connection: close\r\n\r\n"); | 288 | fprintf(sfp,"Connection: close\r\n\r\n"); |
@@ -413,7 +413,7 @@ read_response: | |||
413 | dfp = open_socket(&s_in); | 413 | dfp = open_socket(&s_in); |
414 | 414 | ||
415 | if (beg_range) { | 415 | if (beg_range) { |
416 | sprintf(buf, "REST "FILEOFF_FMT, beg_range); | 416 | sprintf(buf, "REST "OFF_FMT, beg_range); |
417 | if (ftpcmd(buf, NULL, sfp, buf) == 350) | 417 | if (ftpcmd(buf, NULL, sfp, buf) == 350) |
418 | content_len -= beg_range; | 418 | content_len -= beg_range; |
419 | } | 419 | } |
@@ -435,7 +435,7 @@ read_response: | |||
435 | /* Do it before progressmeter (want to have nice error message) */ | 435 | /* Do it before progressmeter (want to have nice error message) */ |
436 | if (output_fd < 0) | 436 | if (output_fd < 0) |
437 | output_fd = xopen3(fname_out, | 437 | output_fd = xopen3(fname_out, |
438 | O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_LARGEFILE, 0666); | 438 | O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0666); |
439 | 439 | ||
440 | if (!(opt & WGET_OPT_QUIET)) | 440 | if (!(opt & WGET_OPT_QUIET)) |
441 | progressmeter(-1); | 441 | progressmeter(-1); |
@@ -685,10 +685,10 @@ static void | |||
685 | progressmeter(int flag) | 685 | progressmeter(int flag) |
686 | { | 686 | { |
687 | static struct timeval lastupdate; | 687 | static struct timeval lastupdate; |
688 | static FILEOFF_TYPE lastsize, totalsize; | 688 | static off_t lastsize, totalsize; |
689 | 689 | ||
690 | struct timeval now, td, tvwait; | 690 | struct timeval now, td, tvwait; |
691 | FILEOFF_TYPE abbrevsize; | 691 | off_t abbrevsize; |
692 | int elapsed, ratio, barlength, i; | 692 | int elapsed, ratio, barlength, i; |
693 | char buf[256]; | 693 | char buf[256]; |
694 | 694 | ||
@@ -739,7 +739,7 @@ progressmeter(int flag) | |||
739 | if (tvwait.tv_sec >= STALLTIME) { | 739 | if (tvwait.tv_sec >= STALLTIME) { |
740 | fprintf(stderr, " - stalled -"); | 740 | fprintf(stderr, " - stalled -"); |
741 | } else { | 741 | } else { |
742 | FILEOFF_TYPE to_download = totalsize - beg_range; | 742 | off_t to_download = totalsize - beg_range; |
743 | if (transferred <= 0 || elapsed <= 0 || transferred > to_download || chunked) { | 743 | if (transferred <= 0 || elapsed <= 0 || transferred > to_download || chunked) { |
744 | fprintf(stderr, "--:--:-- ETA"); | 744 | fprintf(stderr, "--:--:-- ETA"); |
745 | } else { | 745 | } else { |