diff options
author | Pavel Roskin <proski@gnu.org> | 2000-07-17 20:18:42 +0000 |
---|---|---|
committer | Pavel Roskin <proski@gnu.org> | 2000-07-17 20:18:42 +0000 |
commit | cc8a66b113dbdf04082b6f7c9b0b58984d433028 (patch) | |
tree | 98490b8eadc4e44b46c073fa2d21de403a2b61d4 | |
parent | 97562bd9d7fe18bdc4f63e6e80bdce980416a915 (diff) | |
download | busybox-w32-cc8a66b113dbdf04082b6f7c9b0b58984d433028.tar.gz busybox-w32-cc8a66b113dbdf04082b6f7c9b0b58984d433028.tar.bz2 busybox-w32-cc8a66b113dbdf04082b6f7c9b0b58984d433028.zip |
Moved functions used by "lsmod" from cat.c to utility.c
Adjusted to make lsmod and sh compilable as standalone apps.
Comment fixes
-rw-r--r-- | cat.c | 16 | ||||
-rw-r--r-- | coreutils/cat.c | 16 | ||||
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | lsmod.c | 6 | ||||
-rw-r--r-- | modutils/lsmod.c | 6 | ||||
-rw-r--r-- | utility.c | 31 |
6 files changed, 37 insertions, 40 deletions
@@ -24,20 +24,8 @@ | |||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | 26 | ||
27 | static void print_file(FILE * file) | ||
28 | { | ||
29 | int c; | ||
30 | |||
31 | while ((c = getc(file)) != EOF) | ||
32 | putc(c, stdout); | ||
33 | fclose(file); | ||
34 | fflush(stdout); | ||
35 | } | ||
36 | |||
37 | extern int cat_main(int argc, char **argv) | 27 | extern int cat_main(int argc, char **argv) |
38 | { | 28 | { |
39 | FILE *file; | ||
40 | |||
41 | if (argc == 1) { | 29 | if (argc == 1) { |
42 | print_file(stdin); | 30 | print_file(stdin); |
43 | exit(TRUE); | 31 | exit(TRUE); |
@@ -47,12 +35,10 @@ extern int cat_main(int argc, char **argv) | |||
47 | usage(cat_usage); | 35 | usage(cat_usage); |
48 | 36 | ||
49 | while (--argc > 0) { | 37 | while (--argc > 0) { |
50 | file = fopen(*++argv, "r"); | 38 | if (print_file_by_name(*++argv) == FALSE) { |
51 | if (file == NULL) { | ||
52 | perror(*argv); | 39 | perror(*argv); |
53 | exit(FALSE); | 40 | exit(FALSE); |
54 | } | 41 | } |
55 | print_file(file); | ||
56 | } | 42 | } |
57 | return(TRUE); | 43 | return(TRUE); |
58 | } | 44 | } |
diff --git a/coreutils/cat.c b/coreutils/cat.c index c27f07e82..6a9204fe7 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -24,20 +24,8 @@ | |||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | 26 | ||
27 | static void print_file(FILE * file) | ||
28 | { | ||
29 | int c; | ||
30 | |||
31 | while ((c = getc(file)) != EOF) | ||
32 | putc(c, stdout); | ||
33 | fclose(file); | ||
34 | fflush(stdout); | ||
35 | } | ||
36 | |||
37 | extern int cat_main(int argc, char **argv) | 27 | extern int cat_main(int argc, char **argv) |
38 | { | 28 | { |
39 | FILE *file; | ||
40 | |||
41 | if (argc == 1) { | 29 | if (argc == 1) { |
42 | print_file(stdin); | 30 | print_file(stdin); |
43 | exit(TRUE); | 31 | exit(TRUE); |
@@ -47,12 +35,10 @@ extern int cat_main(int argc, char **argv) | |||
47 | usage(cat_usage); | 35 | usage(cat_usage); |
48 | 36 | ||
49 | while (--argc > 0) { | 37 | while (--argc > 0) { |
50 | file = fopen(*++argv, "r"); | 38 | if (print_file_by_name(*++argv) == FALSE) { |
51 | if (file == NULL) { | ||
52 | perror(*argv); | 39 | perror(*argv); |
53 | exit(FALSE); | 40 | exit(FALSE); |
54 | } | 41 | } |
55 | print_file(file); | ||
56 | } | 42 | } |
57 | return(TRUE); | 43 | return(TRUE); |
58 | } | 44 | } |
diff --git a/internal.h b/internal.h index e36c7f396..5cf72d6d3 100644 --- a/internal.h +++ b/internal.h | |||
@@ -354,6 +354,8 @@ extern long getNum (const char *cp); | |||
354 | extern pid_t* findPidByName( char* pidName); | 354 | extern pid_t* findPidByName( char* pidName); |
355 | extern int find_real_root_device_name(char* name); | 355 | extern int find_real_root_device_name(char* name); |
356 | extern char *get_line_from_file(FILE *file); | 356 | extern char *get_line_from_file(FILE *file); |
357 | extern void print_file(FILE *file); | ||
358 | extern int print_file_by_name(char *filename); | ||
357 | extern char process_escape_sequence(char **ptr); | 359 | extern char process_escape_sequence(char **ptr); |
358 | extern char *get_last_path_component(char *path); | 360 | extern char *get_last_path_component(char *path); |
359 | extern void xregcomp(regex_t *preg, const char *regex, int cflags); | 361 | extern void xregcomp(regex_t *preg, const char *regex, int cflags); |
@@ -28,13 +28,13 @@ | |||
28 | extern int lsmod_main(int argc, char **argv) | 28 | extern int lsmod_main(int argc, char **argv) |
29 | { | 29 | { |
30 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 30 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
31 | char *cmd[] = { "cat", "/dev/modules", "\0" }; | 31 | char *filename = "/dev/modules"; |
32 | #else | 32 | #else |
33 | #if ! defined BB_FEATURE_USE_PROCFS | 33 | #if ! defined BB_FEATURE_USE_PROCFS |
34 | #error Sorry, I depend on the /proc filesystem right now. | 34 | #error Sorry, I depend on the /proc filesystem right now. |
35 | #endif | 35 | #endif |
36 | char *cmd[] = { "cat", "/proc/modules", "\0" }; | 36 | char *filename = "/proc/modules"; |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | return(cat_main(3, cmd)); | 39 | return(print_file_by_name(filename)); |
40 | } | 40 | } |
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index d3b1bb79e..6eb9c56b8 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
@@ -28,13 +28,13 @@ | |||
28 | extern int lsmod_main(int argc, char **argv) | 28 | extern int lsmod_main(int argc, char **argv) |
29 | { | 29 | { |
30 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 30 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
31 | char *cmd[] = { "cat", "/dev/modules", "\0" }; | 31 | char *filename = "/dev/modules"; |
32 | #else | 32 | #else |
33 | #if ! defined BB_FEATURE_USE_PROCFS | 33 | #if ! defined BB_FEATURE_USE_PROCFS |
34 | #error Sorry, I depend on the /proc filesystem right now. | 34 | #error Sorry, I depend on the /proc filesystem right now. |
35 | #endif | 35 | #endif |
36 | char *cmd[] = { "cat", "/proc/modules", "\0" }; | 36 | char *filename = "/proc/modules"; |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | return(cat_main(3, cmd)); | 39 | return(print_file_by_name(filename)); |
40 | } | 40 | } |
@@ -483,7 +483,7 @@ const char *timeString(time_t timeVal) | |||
483 | 483 | ||
484 | return buf; | 484 | return buf; |
485 | } | 485 | } |
486 | #endif /* BB_TAR */ | 486 | #endif /* BB_TAR || BB_AR */ |
487 | 487 | ||
488 | #if defined BB_TAR || defined BB_CP_MV || defined BB_AR | 488 | #if defined BB_TAR || defined BB_CP_MV || defined BB_AR |
489 | /* | 489 | /* |
@@ -511,10 +511,10 @@ int fullWrite(int fd, const char *buf, int len) | |||
511 | 511 | ||
512 | return total; | 512 | return total; |
513 | } | 513 | } |
514 | #endif /* BB_TAR || BB_CP_MV */ | 514 | #endif /* BB_TAR || BB_CP_MV || BB_AR */ |
515 | 515 | ||
516 | 516 | ||
517 | #if defined BB_TAR || defined BB_TAIL || defined BB_AR | 517 | #if defined BB_TAR || defined BB_TAIL || defined BB_AR || defined BB_SH |
518 | /* | 518 | /* |
519 | * Read all of the supplied buffer from a file. | 519 | * Read all of the supplied buffer from a file. |
520 | * This does multiple reads as necessary. | 520 | * This does multiple reads as necessary. |
@@ -544,7 +544,7 @@ int fullRead(int fd, char *buf, int len) | |||
544 | 544 | ||
545 | return total; | 545 | return total; |
546 | } | 546 | } |
547 | #endif /* BB_TAR || BB_TAIL */ | 547 | #endif /* BB_TAR || BB_TAIL || BB_AR || BB_SH */ |
548 | 548 | ||
549 | 549 | ||
550 | #if defined (BB_CHMOD_CHOWN_CHGRP) \ | 550 | #if defined (BB_CHMOD_CHOWN_CHGRP) \ |
@@ -1667,6 +1667,29 @@ extern char *get_line_from_file(FILE *file) | |||
1667 | return linebuf; | 1667 | return linebuf; |
1668 | } | 1668 | } |
1669 | 1669 | ||
1670 | #if defined BB_CAT || defined BB_LSMOD | ||
1671 | extern void print_file(FILE *file) | ||
1672 | { | ||
1673 | int c; | ||
1674 | |||
1675 | while ((c = getc(file)) != EOF) | ||
1676 | putc(c, stdout); | ||
1677 | fclose(file); | ||
1678 | fflush(stdout); | ||
1679 | } | ||
1680 | |||
1681 | extern int print_file_by_name(char *filename) | ||
1682 | { | ||
1683 | FILE *file; | ||
1684 | file = fopen(filename, "r"); | ||
1685 | if (file == NULL) { | ||
1686 | return FALSE; | ||
1687 | } | ||
1688 | print_file(file); | ||
1689 | return TRUE; | ||
1690 | } | ||
1691 | #endif /* BB_CAT || BB_LSMOD */ | ||
1692 | |||
1670 | #if defined BB_ECHO || defined BB_TR | 1693 | #if defined BB_ECHO || defined BB_TR |
1671 | char process_escape_sequence(char **ptr) | 1694 | char process_escape_sequence(char **ptr) |
1672 | { | 1695 | { |