* cp -fa now works as expected for symlinks (it didn't before)
authorErik Andersen <andersen@codepoet.org>
Wed, 10 May 2000 05:05:45 +0000 (05:05 -0000)
committerErik Andersen <andersen@codepoet.org>
Wed, 10 May 2000 05:05:45 +0000 (05:05 -0000)
* zcat works again (wasn't working since option parsing was broken)
* more doc updates/more support for BB_FEATURE_SIMPLE_HELP
 -Erik

24 files changed:
Changelog
Makefile
TODO
archival/gunzip.c
console-tools/deallocvt.c
coreutils/dd.c
coreutils/df.c
coreutils/dirname.c
coreutils/du.c
coreutils/echo.c
cp_mv.c
dd.c
deallocvt.c
df.c
dirname.c
dmesg.c
du.c
dutmp.c
echo.c
gunzip.c
internal.h
miscutils/dutmp.c
util-linux/dmesg.c
utility.c

index 8b683ba90cc22bcbceac6e9ae821194e01a85e16..0cd58ef31cda923a8aef8a69c072ae44be1689de 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,9 @@
        * Fixed basename to support stripping of suffixes.  Patch thanks
            to xiong jianxin <jxiong@uiuc.edu>
        * More doc updates
+       * cp -fa now works as expected for symlinks (it didn't before)
+       * zcat now works (wasn't working since option parsing was broken)
+
 
         -Erik
 
index 475d039fa2bc54653b3dfa2cb1a2a23127809dd1..d7b1a9bdb4acc993b1fed78981d8b955831c486d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ export VERSION
 # Set the following to `true' to make a debuggable build.
 # Leave this set to `false' for production use.
 # eg: `make DODEBUG=true tests'
-DODEBUG = false
+DODEBUG = true
 
 # If you want a static binary, turn this on.
 DOSTATIC = false
diff --git a/TODO b/TODO
index 8d7ef0e6f515d131168dd4677501a2932b8beab7..5fe780f3914c45b100bb9b188fdf0992b9124b76 100644 (file)
--- a/TODO
+++ b/TODO
@@ -17,8 +17,6 @@ around to it some time. If you have any good ideas, please let me know.
 
 Bugs that need fixing as of Mon May  8 17:22:06 MDT 2000
 
- - zcat option parsing broke (maybe replace zcat binary with a shell script?)
- - cp -fa doesn't work (-a option parsing probably overrides everything)
  - 'grep foo$ file' doesn't work
  - 'grep *foo file' segfaults
  - ps dirent race bug (need to stat the file before attempting chdir)
index 97ab84e2d912c0411ed84665baf23e5d13d07dd8..bdf8dc293b620d9aabaf5f44a8ee231857f1f212 100644 (file)
@@ -715,11 +715,12 @@ int gunzip_main(int argc, char **argv)
        char ifname[MAX_PATH_LEN + 1];  /* input file name */
        char ofname[MAX_PATH_LEN + 1];  /* output file name */
 
-       if (argc == 1)
-               usage(gunzip_usage);
-
-       if (strcmp(*argv, "zcat") == 0)
+       if (strcmp(*argv, "zcat") == 0) {
                to_stdout = 1;
+               if (argc == 1) {
+                       fromstdin = 1;
+               }
+       }
 
        /* Parse any options */
        while (--argc > 0 && **(++argv) == '-') {
index ee858797ccc7ef779da698f756bd546a34f617ad..a1b8e4eeab85aec712ed0fef134ccc68c0dd81ef 100644 (file)
@@ -19,7 +19,11 @@ int deallocvt_main(int argc, char *argv[])
 
        if ((argc != 2) || (**(argv + 1) == '-')) {
                usage
-                       ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
+                       ("deallocvt N\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+                        "\nDeallocate unused virtual terminal /dev/ttyN\n"
+#endif
+                        );
        }
 
        progname = argv[0];
index 303500008738d93306988f46c3f03ac81059e3d9..5d9993d8b1ef644a51ff6f95d0b444ee1859303f 100644 (file)
@@ -41,17 +41,19 @@ typedef unsigned long long int uintmax_t;
 #endif
 
 static const char dd_usage[] =
-       "dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
-       "Copy a file, converting and formatting according to options\n\n"
+       "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nCopy a file, converting and formatting according to options\n\n"
        "\tif=FILE\tread from FILE instead of stdin\n"
        "\tof=FILE\twrite to FILE instead of stdout\n"
-       "\tbs=n\tread and write n bytes at a time\n"
-       "\tcount=n\tcopy only n input blocks\n"
-       "\tskip=n\tskip n input blocks\n"
-       "\tseek=n\tskip n output blocks\n"
-
+       "\tbs=N\tread and write N bytes at a time\n"
+       "\tcount=N\tcopy only N input blocks\n"
+       "\tskip=N\tskip N input blocks\n"
+       "\tseek=N\tskip N output blocks\n"
        "\n"
-       "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
+       "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
+#endif
+       ;
 
 
 
index c387204547aef77204a2cadb0e5a26bfcf35a782..4170659436caf772164fd62e7e57f77dffdfe5f6 100644 (file)
 #include <sys/stat.h>
 #include <sys/vfs.h>
 
-static const char df_usage[] = "df [filesystem ...]\n\n"
-       "Print the filesystem space used and space available.\n";
+static const char df_usage[] = "df [filesystem ...]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nPrint the filesystem space used and space available.\n"
+#endif
+       ;
 
 extern const char mtab_file[]; /* Defined in utility.c */
 
index 528b89a56dc6fe7a73585c049dda90b9ddf428d4..ce3cd6f03d24e7cd4aeb871ec7fddcf03d5b03cf 100644 (file)
@@ -28,7 +28,11 @@ extern int dirname_main(int argc, char **argv)
        char* s;
 
        if ((argc < 2) || (**(argv + 1) == '-')) {
-               usage("dirname [file ...]\n");
+               usage("dirname [FILENAME ...]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+                               "\nStrips non-directory suffix from FILENAME\n"
+#endif
+                               );
        }
        argv++;
 
index c4fb3a38d5d9d24d42d2254e57d16fda5622675e..9c699978e7c33c8416042129d12e4d789a06f181 100644 (file)
 typedef void (Display) (long, char *);
 
 static const char du_usage[] =
-       "du [OPTION]... [FILE]...\n\n"
-       "Summarize disk space used for each FILE and/or directory.\n"
+       "du [OPTION]... [FILE]...\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nSummarizes disk space used for each FILE and/or directory.\n"
        "Disk space is printed in units of 1024 bytes.\n\n"
        "Options:\n"
        "\t-l\tcount sizes many times if hard linked\n"
-       "\t-s\tdisplay only a total for each argument\n";
+       "\t-s\tdisplay only a total for each argument\n"
+#endif
+       ;
 
 static int du_depth = 0;
 static int count_hardlinks = 0;
@@ -181,7 +184,7 @@ int du_main(int argc, char **argv)
        exit(0);
 }
 
-/* $Id: du.c,v 1.18 2000/04/28 00:18:56 erik Exp $ */
+/* $Id: du.c,v 1.19 2000/05/10 05:05:45 erik Exp $ */
 /*
 Local Variables:
 c-file-style: "linux"
index 2405d0ae1dd0c2b9f559a9c19a2de4934e73165e..b31f2229bb784e9b3ff39ade751f51ff137c44b7 100644 (file)
 #include <stdio.h>
 
 static const char uname_usage[] =
-       "echo [-neE] [ARG ...]\n\n"
-       "Prints the specified ARGs to stdout\n\n"
+       "echo [-neE] [ARG ...]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nPrints the specified ARGs to stdout\n\n"
        "Options:\n"
        "\t-n\tsuppress trailing newline\n"
        "\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
-       "\t-E\tdisable interpretation of backslash-escaped characters\n";
+       "\t-E\tdisable interpretation of backslash-escaped characters\n"
+#endif
+       ;
 
 extern int 
 echo_main(int argc, char** argv)
diff --git a/cp_mv.c b/cp_mv.c
index ae35bca19ef5bc54f29b04b29350d6943a1a5a04..ac1e71b823cac1beffa3440eee18a3e19cf4db4b 100644 (file)
--- a/cp_mv.c
+++ b/cp_mv.c
@@ -70,6 +70,7 @@ static const char *cp_mv_usage[] =    /* .rodata */
 static int recursiveFlag;
 static int followLinks;
 static int preserveFlag;
+static int forceFlag;
 
 static const char *baseSrcName;
 static int                srcDirFlag;
@@ -167,7 +168,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
                        add_to_ino_dev_hashtable(statbuf, destName);
                }
        }
-       return copyFile(fileName, destName, preserveFlag, followLinks);
+       return copyFile(fileName, destName, preserveFlag, followLinks, forceFlag);
 }
 
 static int
@@ -200,7 +201,7 @@ extern int cp_mv_main(int argc, char **argv)
        argv++;
 
        if (dz_i == is_cp) {
-               recursiveFlag = preserveFlag = FALSE;
+               recursiveFlag = preserveFlag = forceFlag = FALSE;
                followLinks = TRUE;
                while (**argv == '-') {
                        while (*++(*argv)) {
@@ -220,7 +221,7 @@ extern int cp_mv_main(int argc, char **argv)
                                        recursiveFlag = TRUE;
                                        break;
                                case 'f':
-                                  /* for compatibility; busybox cp/mv always does force */
+                                       forceFlag = TRUE;
                                        break;
                                default:
                                        usage(cp_mv_usage[is_cp]);
diff --git a/dd.c b/dd.c
index 303500008738d93306988f46c3f03ac81059e3d9..5d9993d8b1ef644a51ff6f95d0b444ee1859303f 100644 (file)
--- a/dd.c
+++ b/dd.c
@@ -41,17 +41,19 @@ typedef unsigned long long int uintmax_t;
 #endif
 
 static const char dd_usage[] =
-       "dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
-       "Copy a file, converting and formatting according to options\n\n"
+       "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nCopy a file, converting and formatting according to options\n\n"
        "\tif=FILE\tread from FILE instead of stdin\n"
        "\tof=FILE\twrite to FILE instead of stdout\n"
-       "\tbs=n\tread and write n bytes at a time\n"
-       "\tcount=n\tcopy only n input blocks\n"
-       "\tskip=n\tskip n input blocks\n"
-       "\tseek=n\tskip n output blocks\n"
-
+       "\tbs=N\tread and write N bytes at a time\n"
+       "\tcount=N\tcopy only N input blocks\n"
+       "\tskip=N\tskip N input blocks\n"
+       "\tseek=N\tskip N output blocks\n"
        "\n"
-       "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
+       "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
+#endif
+       ;
 
 
 
index ee858797ccc7ef779da698f756bd546a34f617ad..a1b8e4eeab85aec712ed0fef134ccc68c0dd81ef 100644 (file)
@@ -19,7 +19,11 @@ int deallocvt_main(int argc, char *argv[])
 
        if ((argc != 2) || (**(argv + 1) == '-')) {
                usage
-                       ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
+                       ("deallocvt N\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+                        "\nDeallocate unused virtual terminal /dev/ttyN\n"
+#endif
+                        );
        }
 
        progname = argv[0];
diff --git a/df.c b/df.c
index c387204547aef77204a2cadb0e5a26bfcf35a782..4170659436caf772164fd62e7e57f77dffdfe5f6 100644 (file)
--- a/df.c
+++ b/df.c
 #include <sys/stat.h>
 #include <sys/vfs.h>
 
-static const char df_usage[] = "df [filesystem ...]\n\n"
-       "Print the filesystem space used and space available.\n";
+static const char df_usage[] = "df [filesystem ...]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nPrint the filesystem space used and space available.\n"
+#endif
+       ;
 
 extern const char mtab_file[]; /* Defined in utility.c */
 
index 528b89a56dc6fe7a73585c049dda90b9ddf428d4..ce3cd6f03d24e7cd4aeb871ec7fddcf03d5b03cf 100644 (file)
--- a/dirname.c
+++ b/dirname.c
@@ -28,7 +28,11 @@ extern int dirname_main(int argc, char **argv)
        char* s;
 
        if ((argc < 2) || (**(argv + 1) == '-')) {
-               usage("dirname [file ...]\n");
+               usage("dirname [FILENAME ...]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+                               "\nStrips non-directory suffix from FILENAME\n"
+#endif
+                               );
        }
        argv++;
 
diff --git a/dmesg.c b/dmesg.c
index 2bbf43a12b86dd98e4164c337a49a274808472d6..6fa17b5fb8bd5c6035b2df0399b345f68b1defd6 100644 (file)
--- a/dmesg.c
+++ b/dmesg.c
@@ -34,7 +34,15 @@ static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
 # include <sys/klog.h>
 #endif
 
-static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
+static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nPrints or controls the kernel ring buffer\n\n"
+       "Options:\n"
+       "\t-c\t\tClears the ring buffer's contents after printing\n"
+       "\t-n LEVEL\tSets console logging level\n"
+       "\t-s SIZE\t\tUse a buffer of size SIZE\n"
+#endif
+       ;
 
 int dmesg_main(int argc, char **argv)
 {
diff --git a/du.c b/du.c
index c4fb3a38d5d9d24d42d2254e57d16fda5622675e..9c699978e7c33c8416042129d12e4d789a06f181 100644 (file)
--- a/du.c
+++ b/du.c
 typedef void (Display) (long, char *);
 
 static const char du_usage[] =
-       "du [OPTION]... [FILE]...\n\n"
-       "Summarize disk space used for each FILE and/or directory.\n"
+       "du [OPTION]... [FILE]...\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nSummarizes disk space used for each FILE and/or directory.\n"
        "Disk space is printed in units of 1024 bytes.\n\n"
        "Options:\n"
        "\t-l\tcount sizes many times if hard linked\n"
-       "\t-s\tdisplay only a total for each argument\n";
+       "\t-s\tdisplay only a total for each argument\n"
+#endif
+       ;
 
 static int du_depth = 0;
 static int count_hardlinks = 0;
@@ -181,7 +184,7 @@ int du_main(int argc, char **argv)
        exit(0);
 }
 
-/* $Id: du.c,v 1.18 2000/04/28 00:18:56 erik Exp $ */
+/* $Id: du.c,v 1.19 2000/05/10 05:05:45 erik Exp $ */
 /*
 Local Variables:
 c-file-style: "linux"
diff --git a/dutmp.c b/dutmp.c
index 192871f1e051291f14f0627cf06aa26c0c91df18..fab1a7b994b57c36c17af215682805834b8521e4 100644 (file)
--- a/dutmp.c
+++ b/dutmp.c
 #endif
 
 
-static const char dutmp_usage[] = "dutmp [FILE]\n\n"
-       "Dump utmp file format (pipe delimited) from FILE\n"
-       "or stdin to stdout.  (i.e. 'dutmp /var/run/utmp')\n";
+static const char dutmp_usage[] = "dutmp [FILE]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nDump utmp file format (pipe delimited) from FILE\n"
+       "or stdin to stdout.  (i.e. 'dutmp /var/run/utmp')\n"
+#endif
+       ;
 
 extern int dutmp_main(int argc, char **argv)
 {
diff --git a/echo.c b/echo.c
index 2405d0ae1dd0c2b9f559a9c19a2de4934e73165e..b31f2229bb784e9b3ff39ade751f51ff137c44b7 100644 (file)
--- a/echo.c
+++ b/echo.c
 #include <stdio.h>
 
 static const char uname_usage[] =
-       "echo [-neE] [ARG ...]\n\n"
-       "Prints the specified ARGs to stdout\n\n"
+       "echo [-neE] [ARG ...]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nPrints the specified ARGs to stdout\n\n"
        "Options:\n"
        "\t-n\tsuppress trailing newline\n"
        "\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
-       "\t-E\tdisable interpretation of backslash-escaped characters\n";
+       "\t-E\tdisable interpretation of backslash-escaped characters\n"
+#endif
+       ;
 
 extern int 
 echo_main(int argc, char** argv)
index 97ab84e2d912c0411ed84665baf23e5d13d07dd8..bdf8dc293b620d9aabaf5f44a8ee231857f1f212 100644 (file)
--- a/gunzip.c
+++ b/gunzip.c
@@ -715,11 +715,12 @@ int gunzip_main(int argc, char **argv)
        char ifname[MAX_PATH_LEN + 1];  /* input file name */
        char ofname[MAX_PATH_LEN + 1];  /* output file name */
 
-       if (argc == 1)
-               usage(gunzip_usage);
-
-       if (strcmp(*argv, "zcat") == 0)
+       if (strcmp(*argv, "zcat") == 0) {
                to_stdout = 1;
+               if (argc == 1) {
+                       fromstdin = 1;
+               }
+       }
 
        /* Parse any options */
        while (--argc > 0 && **(++argv) == '-') {
index 859bee1c398d646fb6649448795d8996db382abb..a4014778ce8127cbc313aa8f96efeeefde0ed57d 100644 (file)
@@ -215,8 +215,8 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
 void reset_ino_dev_hashtable(void);
 
-int copyFile(const char *srcName, const char *destName, int setModes,
-               int followLinks);
+int copyFile(const char *srcName, const char *destName,
+                int setModes, int followLinks, int forceFlag);
 char *buildName(const char *dirName, const char *fileName);
 int makeString(int argc, const char **argv, char *buf, int bufLen);
 char *getChunk(int size);
index 192871f1e051291f14f0627cf06aa26c0c91df18..fab1a7b994b57c36c17af215682805834b8521e4 100644 (file)
 #endif
 
 
-static const char dutmp_usage[] = "dutmp [FILE]\n\n"
-       "Dump utmp file format (pipe delimited) from FILE\n"
-       "or stdin to stdout.  (i.e. 'dutmp /var/run/utmp')\n";
+static const char dutmp_usage[] = "dutmp [FILE]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nDump utmp file format (pipe delimited) from FILE\n"
+       "or stdin to stdout.  (i.e. 'dutmp /var/run/utmp')\n"
+#endif
+       ;
 
 extern int dutmp_main(int argc, char **argv)
 {
index 2bbf43a12b86dd98e4164c337a49a274808472d6..6fa17b5fb8bd5c6035b2df0399b345f68b1defd6 100644 (file)
@@ -34,7 +34,15 @@ static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
 # include <sys/klog.h>
 #endif
 
-static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
+static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nPrints or controls the kernel ring buffer\n\n"
+       "Options:\n"
+       "\t-c\t\tClears the ring buffer's contents after printing\n"
+       "\t-n LEVEL\tSets console logging level\n"
+       "\t-s SIZE\t\tUse a buffer of size SIZE\n"
+#endif
+       ;
 
 int dmesg_main(int argc, char **argv)
 {
index c8442f1bae01a40896293cde4efa6cc67e4b906f..5899fe954370aa8d4fbf747e81991164593ba9bd 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -234,15 +234,14 @@ int isDirectory(const char *fileName, const int followLinks, struct stat *statBu
 
 #if defined (BB_CP_MV)
 /*
- * Copy one file to another, while possibly preserving its modes, times,
- * and modes.  Returns TRUE if successful, or FALSE on a failure with an
- * error message output.  (Failure is not indicated if the attributes cannot
- * be set.)
- *  -Erik Andersen
+ * Copy one file to another, while possibly preserving its modes, times, and
+ * modes.  Returns TRUE if successful, or FALSE on a failure with an error
+ * message output.  (Failure is not indicated if attributes cannot be set.)
+ * -Erik Andersen
  */
 int
 copyFile(const char *srcName, const char *destName,
-                int setModes, int followLinks)
+                int setModes, int followLinks, int forceFlag)
 {
        int rfd;
        int wfd;
@@ -268,7 +267,8 @@ copyFile(const char *srcName, const char *destName,
        else
                status = lstat(destName, &dstStatBuf);
 
-       if (status < 0) {
+       if (status < 0 || forceFlag==TRUE) {
+               unlink(destName);
                dstStatBuf.st_ino = -1;
                dstStatBuf.st_dev = -1;
        }
@@ -306,10 +306,8 @@ copyFile(const char *srcName, const char *destName,
                }
 #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
                if (setModes == TRUE) {
-                       if (lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) {
-                               perror(destName);
-                               return FALSE;
-                       }
+                       /* Try to set owner, but fail silently like GNU cp */
+                       lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
                }
 #endif
                return TRUE;