diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-04 21:16:46 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-04 21:16:46 +0000 |
| commit | 855ff6f503ee50fad3eb6fa30e2b02f53f32d63d (patch) | |
| tree | 7cc63f646f0c9c5bcacefe2a8e453a3796902af0 /modutils | |
| parent | 5db861a9eb93c4562798654f53022088784f35eb (diff) | |
| download | busybox-w32-855ff6f503ee50fad3eb6fa30e2b02f53f32d63d.tar.gz busybox-w32-855ff6f503ee50fad3eb6fa30e2b02f53f32d63d.tar.bz2 busybox-w32-855ff6f503ee50fad3eb6fa30e2b02f53f32d63d.zip | |
modprobe: use buffering line reads (fgets) instead of reads().
libbb: remove reads()
function old new delta
include_conf_file_act 961 980 +19
localcmd 282 284 +2
already_loaded 155 151 -4
in_cksum 58 53 -5
modprobe_main 1630 1624 -6
reads 129 - -129
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/3 up/down: 21/-144) Total: -123 bytes
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/modprobe.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 3a2d893ee..01f8bb89b 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
| @@ -280,18 +280,18 @@ static int FAST_FUNC include_conf_file_act(const char *filename, | |||
| 280 | struct dep_t **first = &conf->first; | 280 | struct dep_t **first = &conf->first; |
| 281 | struct dep_t **current = &conf->current; | 281 | struct dep_t **current = &conf->current; |
| 282 | int continuation_line = 0; | 282 | int continuation_line = 0; |
| 283 | int fd; | 283 | FILE *f; |
| 284 | 284 | ||
| 285 | if (bb_basename(filename)[0] == '.') | 285 | if (bb_basename(filename)[0] == '.') |
| 286 | return TRUE; | 286 | return TRUE; |
| 287 | 287 | ||
| 288 | fd = open(filename, O_RDONLY); | 288 | f = fopen_for_read(filename); |
| 289 | if (fd < 0) | 289 | if (f == NULL) |
| 290 | return FALSE; | 290 | return FALSE; |
| 291 | 291 | ||
| 292 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias)! | 292 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias)! |
| 293 | 293 | ||
| 294 | while (reads(fd, line_buffer, sizeof(line_buffer))) { | 294 | while (fgets(line_buffer, sizeof(line_buffer), f)) { |
| 295 | int l; | 295 | int l; |
| 296 | 296 | ||
| 297 | *strchrnul(line_buffer, '#') = '\0'; | 297 | *strchrnul(line_buffer, '#') = '\0'; |
| @@ -376,9 +376,9 @@ static int FAST_FUNC include_conf_file_act(const char *filename, | |||
| 376 | if (dt) | 376 | if (dt) |
| 377 | dt->m_isblacklisted = 1; | 377 | dt->m_isblacklisted = 1; |
| 378 | } | 378 | } |
| 379 | } /* while (reads(...)) */ | 379 | } /* while (fgets(...)) */ |
| 380 | 380 | ||
| 381 | close(fd); | 381 | fclose(f); |
| 382 | return TRUE; | 382 | return TRUE; |
| 383 | } | 383 | } |
| 384 | 384 | ||
| @@ -403,7 +403,7 @@ static int include_conf_file2(struct include_conf_t *conf, | |||
| 403 | */ | 403 | */ |
| 404 | static struct dep_t *build_dep(void) | 404 | static struct dep_t *build_dep(void) |
| 405 | { | 405 | { |
| 406 | int fd; | 406 | FILE *f; |
| 407 | struct utsname un; | 407 | struct utsname un; |
| 408 | struct include_conf_t conf = { NULL, NULL }; | 408 | struct include_conf_t conf = { NULL, NULL }; |
| 409 | char *filename; | 409 | char *filename; |
| @@ -419,18 +419,18 @@ static struct dep_t *build_dep(void) | |||
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/"CONFIG_DEFAULT_DEPMOD_FILE, un.release); | 421 | filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/"CONFIG_DEFAULT_DEPMOD_FILE, un.release); |
| 422 | fd = open(filename, O_RDONLY); | 422 | f = fopen_for_read(filename); |
| 423 | if (ENABLE_FEATURE_CLEAN_UP) | 423 | if (ENABLE_FEATURE_CLEAN_UP) |
| 424 | free(filename); | 424 | free(filename); |
| 425 | if (fd < 0) { | 425 | if (f == NULL) { |
| 426 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ | 426 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ |
| 427 | fd = open(CONFIG_DEFAULT_MODULES_DIR"/"CONFIG_DEFAULT_DEPMOD_FILE, O_RDONLY); | 427 | f = fopen_for_read(CONFIG_DEFAULT_MODULES_DIR"/"CONFIG_DEFAULT_DEPMOD_FILE); |
| 428 | if (fd < 0) { | 428 | if (f == NULL) { |
| 429 | bb_error_msg_and_die("cannot parse " CONFIG_DEFAULT_DEPMOD_FILE); | 429 | bb_error_msg_and_die("cannot parse " CONFIG_DEFAULT_DEPMOD_FILE); |
| 430 | } | 430 | } |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | while (reads(fd, line_buffer, sizeof(line_buffer))) { | 433 | while (fgets(line_buffer, sizeof(line_buffer), f)) { |
| 434 | int l = strlen(line_buffer); | 434 | int l = strlen(line_buffer); |
| 435 | char *p = 0; | 435 | char *p = 0; |
| 436 | 436 | ||
| @@ -545,8 +545,8 @@ static struct dep_t *build_dep(void) | |||
| 545 | 545 | ||
| 546 | /* is there other dependable module(s) ? */ | 546 | /* is there other dependable module(s) ? */ |
| 547 | continuation_line = (line_buffer[l-1] == '\\'); | 547 | continuation_line = (line_buffer[l-1] == '\\'); |
| 548 | } /* while (reads(...)) */ | 548 | } /* while (fgets(...)) */ |
| 549 | close(fd); | 549 | fclose(f); |
| 550 | 550 | ||
| 551 | /* | 551 | /* |
| 552 | * First parse system-specific options and aliases | 552 | * First parse system-specific options and aliases |
| @@ -594,13 +594,14 @@ static struct dep_t *build_dep(void) | |||
| 594 | /* return 1 = loaded, 0 = not loaded, -1 = can't tell */ | 594 | /* return 1 = loaded, 0 = not loaded, -1 = can't tell */ |
| 595 | static int already_loaded(const char *name) | 595 | static int already_loaded(const char *name) |
| 596 | { | 596 | { |
| 597 | int fd, ret = 0; | 597 | FILE *f; |
| 598 | int ret = 0; | ||
| 598 | 599 | ||
| 599 | fd = open("/proc/modules", O_RDONLY); | 600 | f = fopen_for_read("/proc/modules"); |
| 600 | if (fd < 0) | 601 | if (f == NULL) |
| 601 | return -1; | 602 | return -1; |
| 602 | 603 | ||
| 603 | while (reads(fd, line_buffer, sizeof(line_buffer))) { | 604 | while (fgets(line_buffer, sizeof(line_buffer), f)) { |
| 604 | char *p; | 605 | char *p; |
| 605 | 606 | ||
| 606 | p = strchr(line_buffer, ' '); | 607 | p = strchr(line_buffer, ' '); |
| @@ -627,7 +628,7 @@ static int already_loaded(const char *name) | |||
| 627 | } | 628 | } |
| 628 | } | 629 | } |
| 629 | done: | 630 | done: |
| 630 | close(fd); | 631 | fclose(f); |
| 631 | return ret; | 632 | return ret; |
| 632 | } | 633 | } |
| 633 | 634 | ||
