the beginnings of a proper man page for busybox.
[oweals/busybox.git] / utility.c
index 74df632b9a7cf1ce9c71ad1b00ab55e9c60adf9a..ade47bde0906d30edff5880cb9ef8e52d207b1c1 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -151,7 +151,8 @@ copyFile( const char *srcName, const char *destName,
     if (S_ISDIR(srcStatBuf.st_mode)) {
        //fprintf(stderr, "copying directory %s to %s\n", srcName, destName);
        /* Make sure the directory is writable */
-       if (mkdir(destName, 0777777 ^ umask(0))) {
+       result = mkdir(destName, 0777777 ^ umask(0));
+       if (result < 0 && errno != EEXIST) {
            perror(destName);
            return (FALSE);
        }
@@ -217,10 +218,12 @@ copyFile( const char *srcName, const char *destName,
     if (setModes == TRUE) {
        //fprintf(stderr, "Setting permissions for %s\n", destName);
        chmod(destName, srcStatBuf.st_mode);
-       if (followLinks == TRUE)
-           chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
-       else
+#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+       if (followLinks == FALSE)
            lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
+       else
+#endif
+           chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
 
        times.actime = srcStatBuf.st_atime;
        times.modtime = srcStatBuf.st_mtime;
@@ -314,7 +317,9 @@ const char *timeString(time_t timeVal)
 
     return buf;
 }
+#endif
 
+#if defined BB_TAR || defined BB_CP || defined BB_MV
 /*
  * Write all of the supplied buffer out to a file.
  * This does multiple writes as necessary.
@@ -376,7 +381,7 @@ int fullRead(int fd, char *buf, int len)
 #endif
 
 
-#if defined (BB_CHOWN) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS)
+#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS) || defined (BB_INSMOD)
 /*
  * Walk down all the directories under the specified 
  * location, and do something (something specified
@@ -393,7 +398,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
                int (*dirAction) (const char *fileName, struct stat* statbuf))
 {
     int status;
-    struct stat statbuf;
+    struct stat statbuf, statbuf1;
     struct dirent *next;
 
     if (followLinks == TRUE)
@@ -401,6 +406,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
     else
        status = lstat(fileName, &statbuf);
 
+    status = lstat(fileName, &statbuf);
     if (status < 0) {
        perror(fileName);
        return (FALSE);
@@ -421,8 +427,14 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
                return (TRUE);
        } 
     }
+    
+    status = lstat(fileName, &statbuf1);
+    if (status < 0) {
+       perror(fileName);
+       return (FALSE);
+    }
 
-    if (S_ISDIR(statbuf.st_mode)) {
+    if (S_ISDIR(statbuf.st_mode) && S_ISDIR(statbuf1.st_mode)) {
        DIR *dir;
        dir = opendir(fileName);
        if (!dir) {
@@ -966,7 +978,7 @@ check_wildcard_match(const char* text, const char* pattern)
 
 
 
-#if defined BB_DF | defined BB_MTAB
+#if defined BB_DF || defined BB_MTAB
 /*
  * Given a block device, find the mount table entry if that block device
  * is mounted.
@@ -1005,21 +1017,10 @@ extern struct mntent *findMountPoint(const char *name, const char *table)
     endmntent(mountTable);
     return mountEntry;
 }
-
 #endif
 
 
 
-#if !defined BB_MTAB && (defined BB_MOUNT || defined BB_DF )
-extern void whine_if_fstab_is_missing()
-{
-    struct stat statBuf;
-    if (stat("/etc/fstab", &statBuf) < 0) 
-       fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n");
-}
-#endif
-
-
 #if defined BB_DD || defined BB_TAIL
 /*
  * Read a number with a possible multiplier.
@@ -1108,4 +1109,15 @@ findInitPid()
 }
 #endif
 
+#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
+extern int vdprintf(int d, const char *format, va_list ap)
+{
+    char buf[BUF_SIZE];
+    int len;
+
+    len = vsprintf(buf, format, ap);
+    return write(d, buf, len);
+}
+#endif
+
 /* END CODE */