diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-21 11:58:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-21 11:58:14 +0000 |
commit | 9229794ab33fa510a5896784958b90f87bef6876 (patch) | |
tree | cbf063d72178aac42b71fe233dc20e5bc226463e | |
parent | a8381948da79b06071c17853a9a2a59947742c8d (diff) | |
download | busybox-w32-9229794ab33fa510a5896784958b90f87bef6876.tar.gz busybox-w32-9229794ab33fa510a5896784958b90f87bef6876.tar.bz2 busybox-w32-9229794ab33fa510a5896784958b90f87bef6876.zip |
insmod_ng_main: -80 bytes. Stopp mmapping, use xmalloc_open_read_close().
-rw-r--r-- | archival/libunarchive/archive_xread_all_eof.c | 13 | ||||
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | modutils/insmod.c | 48 |
3 files changed, 33 insertions, 31 deletions
diff --git a/archival/libunarchive/archive_xread_all_eof.c b/archival/libunarchive/archive_xread_all_eof.c index 8513ffecb..007f68c6d 100644 --- a/archival/libunarchive/archive_xread_all_eof.c +++ b/archival/libunarchive/archive_xread_all_eof.c | |||
@@ -3,19 +3,18 @@ | |||
3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <string.h> | ||
9 | #include "unarchive.h" | 6 | #include "unarchive.h" |
10 | #include "libbb.h" | 7 | #include "libbb.h" |
11 | 8 | ||
12 | ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count) | 9 | ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, |
10 | unsigned char *buf, size_t count) | ||
13 | { | 11 | { |
14 | ssize_t size; | 12 | ssize_t size; |
15 | 13 | ||
16 | size = full_read(archive_handle->src_fd, buf, count); | 14 | size = full_read(archive_handle->src_fd, buf, count); |
17 | if ((size != 0) && (size != count)) { | 15 | if (size != 0 && size != count) { |
18 | bb_perror_msg_and_die("short read, read %ld of %ld", (long)size, (long)count); | 16 | bb_error_msg_and_die("short read: %u of %u", |
17 | (unsigned)size, (unsigned)count); | ||
19 | } | 18 | } |
20 | return(size); | 19 | return size; |
21 | } | 20 | } |
diff --git a/include/libbb.h b/include/libbb.h index 3fb477b33..f574f9b5f 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -60,7 +60,7 @@ | |||
60 | #define PATH_MAX 256 | 60 | #define PATH_MAX 256 |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | /* Not (yet) used, but tested to work correctly | 63 | /* Tested to work correctly (IIRC :]) */ |
64 | #define MAXINT(T) (T)( \ | 64 | #define MAXINT(T) (T)( \ |
65 | ((T)-1) > 0 \ | 65 | ((T)-1) > 0 \ |
66 | ? (T)-1 \ | 66 | ? (T)-1 \ |
@@ -72,7 +72,6 @@ | |||
72 | ? (T)0 \ | 72 | ? (T)0 \ |
73 | : ((T)1 << (sizeof(T)*8-1)) \ | 73 | : ((T)1 << (sizeof(T)*8-1)) \ |
74 | ) | 74 | ) |
75 | */ | ||
76 | 75 | ||
77 | /* Large file support */ | 76 | /* Large file support */ |
78 | /* Note that CONFIG_LFS forces bbox to be built with all common ops | 77 | /* Note that CONFIG_LFS forces bbox to be built with all common ops |
diff --git a/modutils/insmod.c b/modutils/insmod.c index ff96736af..11ba26344 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -4263,38 +4263,32 @@ static const char *moderror(int err) | |||
4263 | } | 4263 | } |
4264 | } | 4264 | } |
4265 | 4265 | ||
4266 | int insmod_ng_main( int argc, char **argv) | 4266 | int insmod_ng_main(int argc, char **argv) |
4267 | { | 4267 | { |
4268 | int i; | 4268 | long ret; |
4269 | int fd; | 4269 | size_t len; |
4270 | long int ret; | ||
4271 | struct stat st; | ||
4272 | unsigned long len; | ||
4273 | void *map; | 4270 | void *map; |
4274 | char *filename, *options = xstrdup(""); | 4271 | char *filename, *options; |
4275 | 4272 | ||
4276 | filename = argv[1]; | 4273 | filename = *++argv; |
4277 | if (!filename) { | 4274 | if (!filename) |
4278 | bb_show_usage(); | 4275 | bb_show_usage(); |
4279 | return -1; | ||
4280 | } | ||
4281 | 4276 | ||
4282 | /* Rest is options */ | 4277 | /* Rest is options */ |
4283 | for (i = 2; i < argc; i++) { | 4278 | options = xstrdup(""); |
4284 | options = xrealloc(options, strlen(options) + 2 + strlen(argv[i]) + 2); | 4279 | while (*++argv) { |
4280 | int optlen = strlen(options); | ||
4281 | options = xrealloc(options, optlen + 2 + strlen(*argv) + 2); | ||
4285 | /* Spaces handled by "" pairs, but no way of escaping quotes */ | 4282 | /* Spaces handled by "" pairs, but no way of escaping quotes */ |
4286 | if (strchr(argv[i], ' ')) { | 4283 | sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv); |
4287 | strcat(options, "\""); | ||
4288 | strcat(options, argv[i]); | ||
4289 | strcat(options, "\""); | ||
4290 | } else { | ||
4291 | strcat(options, argv[i]); | ||
4292 | } | ||
4293 | strcat(options, " "); | ||
4294 | } | 4284 | } |
4295 | 4285 | ||
4286 | #if 0 | ||
4287 | /* Any special reason why mmap? It isn't performace critical... */ | ||
4288 | int fd; | ||
4289 | struct stat st; | ||
4290 | unsigned long len; | ||
4296 | fd = xopen(filename, O_RDONLY); | 4291 | fd = xopen(filename, O_RDONLY); |
4297 | |||
4298 | fstat(fd, &st); | 4292 | fstat(fd, &st); |
4299 | len = st.st_size; | 4293 | len = st.st_size; |
4300 | map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); | 4294 | map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); |
@@ -4302,6 +4296,16 @@ int insmod_ng_main( int argc, char **argv) | |||
4302 | bb_perror_msg_and_die("cannot mmap '%s'", filename); | 4296 | bb_perror_msg_and_die("cannot mmap '%s'", filename); |
4303 | } | 4297 | } |
4304 | 4298 | ||
4299 | /* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */ | ||
4300 | if (map == NULL) { | ||
4301 | map = xmalloc(len); | ||
4302 | xread(fd, map, len); | ||
4303 | } | ||
4304 | #else | ||
4305 | len = MAXINT(ssize_t); | ||
4306 | map = xmalloc_open_read_close(filename, &len); | ||
4307 | #endif | ||
4308 | |||
4305 | ret = syscall(__NR_init_module, map, len, options); | 4309 | ret = syscall(__NR_init_module, map, len, options); |
4306 | if (ret != 0) { | 4310 | if (ret != 0) { |
4307 | bb_perror_msg_and_die("cannot insert '%s': %s (%li)", | 4311 | bb_perror_msg_and_die("cannot insert '%s': %s (%li)", |