Moved functions used by "lsmod" from cat.c to utility.c
authorPavel Roskin <proski@gnu.org>
Mon, 17 Jul 2000 20:18:42 +0000 (20:18 -0000)
committerPavel Roskin <proski@gnu.org>
Mon, 17 Jul 2000 20:18:42 +0000 (20:18 -0000)
Adjusted to make lsmod and sh compilable as standalone apps.
Comment fixes

cat.c
coreutils/cat.c
internal.h
lsmod.c
modutils/lsmod.c
utility.c

diff --git a/cat.c b/cat.c
index c27f07e825c4ae4aacb743ec02c1a687a4dafc8b..6a9204fe7bfe93bbfa7c898eaba3453a616a182f 100644 (file)
--- a/cat.c
+++ b/cat.c
 #include "internal.h"
 #include <stdio.h>
 
-static void print_file(FILE * file)
-{
-       int c;
-
-       while ((c = getc(file)) != EOF)
-               putc(c, stdout);
-       fclose(file);
-       fflush(stdout);
-}
-
 extern int cat_main(int argc, char **argv)
 {
-       FILE *file;
-
        if (argc == 1) {
                print_file(stdin);
                exit(TRUE);
@@ -47,12 +35,10 @@ extern int cat_main(int argc, char **argv)
                usage(cat_usage);
 
        while (--argc > 0) {
-               file = fopen(*++argv, "r");
-               if (file == NULL) {
+               if (print_file_by_name(*++argv) == FALSE) {
                        perror(*argv);
                        exit(FALSE);
                }
-               print_file(file);
        }
        return(TRUE);
 }
index c27f07e825c4ae4aacb743ec02c1a687a4dafc8b..6a9204fe7bfe93bbfa7c898eaba3453a616a182f 100644 (file)
 #include "internal.h"
 #include <stdio.h>
 
-static void print_file(FILE * file)
-{
-       int c;
-
-       while ((c = getc(file)) != EOF)
-               putc(c, stdout);
-       fclose(file);
-       fflush(stdout);
-}
-
 extern int cat_main(int argc, char **argv)
 {
-       FILE *file;
-
        if (argc == 1) {
                print_file(stdin);
                exit(TRUE);
@@ -47,12 +35,10 @@ extern int cat_main(int argc, char **argv)
                usage(cat_usage);
 
        while (--argc > 0) {
-               file = fopen(*++argv, "r");
-               if (file == NULL) {
+               if (print_file_by_name(*++argv) == FALSE) {
                        perror(*argv);
                        exit(FALSE);
                }
-               print_file(file);
        }
        return(TRUE);
 }
index e36c7f396d00f9a9698412cc1ee9a69044ff64a2..5cf72d6d32a4e225622a7b64efd3471f84adc20f 100644 (file)
@@ -354,6 +354,8 @@ extern long getNum (const char *cp);
 extern pid_t* findPidByName( char* pidName);
 extern int find_real_root_device_name(char* name);
 extern char *get_line_from_file(FILE *file);
+extern void print_file(FILE *file);
+extern int print_file_by_name(char *filename);
 extern char process_escape_sequence(char **ptr);
 extern char *get_last_path_component(char *path);
 extern void xregcomp(regex_t *preg, const char *regex, int cflags);
diff --git a/lsmod.c b/lsmod.c
index d3b1bb79eb08707895340d15d14c8898c98ce62e..6eb9c56b8d09f1b58304c54c12559b59981d92e1 100644 (file)
--- a/lsmod.c
+++ b/lsmod.c
 extern int lsmod_main(int argc, char **argv)
 {
 #if defined BB_FEATURE_USE_DEVPS_PATCH
-       char *cmd[] = { "cat", "/dev/modules", "\0" };
+       char *filename = "/dev/modules";
 #else
 #if ! defined BB_FEATURE_USE_PROCFS
 #error Sorry, I depend on the /proc filesystem right now.
 #endif
-       char *cmd[] = { "cat", "/proc/modules", "\0" };
+       char *filename = "/proc/modules";
 #endif
 
-       return(cat_main(3, cmd));
+       return(print_file_by_name(filename));
 }
index d3b1bb79eb08707895340d15d14c8898c98ce62e..6eb9c56b8d09f1b58304c54c12559b59981d92e1 100644 (file)
 extern int lsmod_main(int argc, char **argv)
 {
 #if defined BB_FEATURE_USE_DEVPS_PATCH
-       char *cmd[] = { "cat", "/dev/modules", "\0" };
+       char *filename = "/dev/modules";
 #else
 #if ! defined BB_FEATURE_USE_PROCFS
 #error Sorry, I depend on the /proc filesystem right now.
 #endif
-       char *cmd[] = { "cat", "/proc/modules", "\0" };
+       char *filename = "/proc/modules";
 #endif
 
-       return(cat_main(3, cmd));
+       return(print_file_by_name(filename));
 }
index c682bf05d14ebf63af683e7cf81493e08e02c260..5f890c0ea9c06ff51a4cb02aae7da2c00484c190 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -483,7 +483,7 @@ const char *timeString(time_t timeVal)
 
        return buf;
 }
-#endif                                                 /* BB_TAR */
+#endif /* BB_TAR || BB_AR */
 
 #if defined BB_TAR || defined BB_CP_MV || defined BB_AR
 /*
@@ -511,10 +511,10 @@ int fullWrite(int fd, const char *buf, int len)
 
        return total;
 }
-#endif                                                 /* BB_TAR || BB_CP_MV */
+#endif /* BB_TAR || BB_CP_MV || BB_AR */
 
 
-#if defined BB_TAR || defined BB_TAIL || defined BB_AR
+#if defined BB_TAR || defined BB_TAIL || defined BB_AR || defined BB_SH
 /*
  * Read all of the supplied buffer from a file.
  * This does multiple reads as necessary.
@@ -544,7 +544,7 @@ int fullRead(int fd, char *buf, int len)
 
        return total;
 }
-#endif                                                 /* BB_TAR || BB_TAIL */
+#endif /* BB_TAR || BB_TAIL || BB_AR || BB_SH */
 
 
 #if defined (BB_CHMOD_CHOWN_CHGRP) \
@@ -1667,6 +1667,29 @@ extern char *get_line_from_file(FILE *file)
        return linebuf;
 }
 
+#if defined BB_CAT || defined BB_LSMOD
+extern void print_file(FILE *file)
+{
+       int c;
+
+       while ((c = getc(file)) != EOF)
+               putc(c, stdout);
+       fclose(file);
+       fflush(stdout);
+}
+
+extern int print_file_by_name(char *filename)
+{
+       FILE *file;
+       file = fopen(filename, "r");
+       if (file == NULL) {
+               return FALSE;
+       }
+       print_file(file);
+       return TRUE;
+}
+#endif /* BB_CAT || BB_LSMOD */
+
 #if defined BB_ECHO || defined BB_TR
 char process_escape_sequence(char **ptr)
 {