cvs-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cvs-cvs] ccvs/emx ChangeLog filesubr.c


From: Mark D. Baushke
Subject: [Cvs-cvs] ccvs/emx ChangeLog filesubr.c
Date: Tue, 23 May 2006 17:02:49 +0000

CVSROOT:        /cvsroot/cvs
Module name:    ccvs
Branch:         
Changes by:     Mark D. Baushke <address@hidden>        06/05/23 17:02:49

Modified files:
        emx            : ChangeLog filesubr.c 

Log message:
        * filesubr.c: Reformat according to HACKING standards.
        (isdir, isfile, isreadable, iswritable, isaccessible): Return bool
        instead of int to match prototypes.
        (xresolvepath): Remove obsolete funciton.
        (islink): Use ssize_t instead of int to match prototype and return
        the sb.st_size if it is a link and zero otherwise.
        (xchmod): Change writable argument to bool to match prototype.
        (copy_file, rename_file, unlink_file): Use TRACE macro instead
        of open code.
        (copy_file, isdir, islink, isfile, isreadable, iswritable,
        isaccessible, make_directory, make_directories, mkdir_if_needed,
        xchmod, rename_file, unlink_file, unlink_file_dir,
        deep_remove_dir, block_read, xcmp, cvs_temp_name, last_component,
        get_homedir, expand_wild): Use C89 function declaration.
        (unlink_file_dir): Fix problem with trace on the server.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/emx/ChangeLog.diff?tr1=1.45&tr2=1.46&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/emx/filesubr.c.diff?tr1=1.9&tr2=1.10&r1=text&r2=text

Patches:
Index: ccvs/emx/ChangeLog
diff -u ccvs/emx/ChangeLog:1.45 ccvs/emx/ChangeLog:1.46
--- ccvs/emx/ChangeLog:1.45     Thu Sep  1 13:49:00 2005
+++ ccvs/emx/ChangeLog  Tue May 23 17:02:49 2006
@@ -1,3 +1,21 @@
+2006-05-23  Mark D. Baushke  <address@hidden>
+
+       * filesubr.c: Reformat according to HACKING standards.
+       (isdir, isfile, isreadable, iswritable, isaccessible): Return bool
+       instead of int to match prototypes.
+       (xresolvepath): Remove obsolete funciton.
+       (islink): Use ssize_t instead of int to match prototype and return
+       the sb.st_size if it is a link and zero otherwise.
+       (xchmod): Change writable argument to bool to match prototype.
+       (copy_file, rename_file, unlink_file): Use TRACE macro instead
+       of open code.
+       (copy_file, isdir, islink, isfile, isreadable, iswritable,
+       isaccessible, make_directory, make_directories, mkdir_if_needed,
+       xchmod, rename_file, unlink_file, unlink_file_dir,
+       deep_remove_dir, block_read, xcmp, cvs_temp_name, last_component,
+       get_homedir, expand_wild): Use C89 function declaration.
+       (unlink_file_dir): Fix problem with trace on the server.
+
 2005-09-01  Derek Price  <address@hidden>
 
        * README: Update bug-cvs email.
Index: ccvs/emx/filesubr.c
diff -u ccvs/emx/filesubr.c:1.9 ccvs/emx/filesubr.c:1.10
--- ccvs/emx/filesubr.c:1.9     Wed Mar 16 15:53:57 2005
+++ ccvs/emx/filesubr.c Tue May 23 17:02:49 2006
@@ -28,27 +28,20 @@
 #define LOSING_TMPNAM_FUNCTION
 #endif
 
-static int deep_remove_dir( const char *path );
+static int deep_remove_dir (const char *path);
 
 /*
  * Copies "from" to "to".
  */
 void
-copy_file (from, to)
-    const char *from;
-    const char *to;
+copy_file (const char *from, const char *to)
 {
     struct stat sb;
     struct utimbuf t;
     int fdin, fdout;
 
-    if (trace)
-#ifdef SERVER_SUPPORT
-       (void) fprintf (stderr, "%c-> copy(%s,%s)\n",
-                       (server_active) ? 'S' : ' ', from, to);
-#else
-       (void) fprintf (stderr, "-> copy(%s,%s)\n", from, to);
-#endif
+    TRACE (TRACE_FUNCTION, "copy (%s, %s)", from, to);
+
     if (noexec)
        return;
 
@@ -57,7 +50,7 @@
     if (fstat (fdin, &sb) < 0)
        error (1, errno, "cannot fstat %s", from);
     if ((fdout = open (to, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY,
-                                          (int) sb.st_mode & 07777)) < 0)
+                      (int) sb.st_mode & 07777)) < 0)
        error (1, errno, "cannot create %s for copying", to);
     if (sb.st_size > 0)
     {
@@ -66,7 +59,7 @@
 
        for (;;)
        {
-           n = read (fdin, buf, sizeof(buf));
+           n = read (fdin, buf, sizeof (buf));
            if (n == -1)
            {
 #ifdef EINTR
@@ -78,9 +71,8 @@
             else if (n == 0)
                break;
 
-           if (write(fdout, buf, n) != n) {
+           if (write (fdout, buf, n) != n)
                error (1, errno, "cannot write file %s for copying", to);
-           }
        }
 
 #ifdef HAVE_FSYNC
@@ -101,81 +93,91 @@
     (void) utime (to, &t);
 }
 
+
+
 /* FIXME-krp: these functions would benefit from caching the char * &
    stat buf.  */
 
 /*
- * Returns non-zero if the argument file is a directory, or is a symbolic
+ * Returns true if the argument file is a directory, or is a symbolic
  * link which points to a directory.
  */
-int
-isdir (file)
-    const char *file;
+bool
+isdir (const char *file)
 {
     struct stat sb;
 
     if (stat (file, &sb) < 0)
-       return (0);
-    return (S_ISDIR (sb.st_mode));
+       return false;
+    return S_ISDIR (sb.st_mode);
 }
 
+
+
 /*
- * Returns non-zero if the argument file is a symbolic link.
+ * Returns 0 if the argument file is not a symbolic link.
+ * Returns size of the link if it is a symbolic link.
+ *
+ * FIXME: Is there a good reason that the off_t specified by POSIX for st_size
+ *        (http://www.opengroup.org/susv3xbd/sys/stat.h.html) is converted to
+ *        ssize_t here?  rcs.h uses off_t, so it's not because off_t isn't
+ *        portable.
  */
-int
-islink (file)
-    const char *file;
+ssize_t
+islink (const char *file)
 {
+    ssize_t retsize = 0;
 #ifdef S_ISLNK
     struct stat sb;
 
-    if (lstat (file, &sb) < 0)
-       return (0);
-    return (S_ISLNK (sb.st_mode));
-#else
-    return (0);
+    if ((lstat (file, &sb) >= 0) && S_ISLNK (sb.st_mode))
+       retsize = sb.st_size;
 #endif
+    return retsize;
 }
 
+
+
 /*
- * Returns non-zero if the argument file exists.
+ * Returns true if the argument file exists.
  */
-int
-isfile (file)
-    const char *file;
+bool
+isfile (const char *file)
 {
-    return isaccessible(file, F_OK);
+    return isaccessible (file, F_OK);
 }
 
+
+
 /*
- * Returns non-zero if the argument file is readable.
+ * Returns true if the argument file is readable.
  */
-int
-isreadable (file)
-    const char *file;
+bool
+isreadable (const char *file)
 {
-    return isaccessible(file, R_OK);
+    return isaccessible (file, R_OK);
 }
 
+
+
 /*
- * Returns non-zero if the argument file is writable.
+ * Returns true if the argument file is writable.
  */
-int
-iswritable (file)
-    const char *file;
+bool
+iswritable (const char *file)
 {
-    return isaccessible(file, W_OK);
+    return isaccessible (file, W_OK);
 }
 
+
+
 /*
- * Returns non-zero if the argument file is accessable according to
+ * Returns true if the argument file is accessable according to
  * mode.  If compiled with SETXID_SUPPORT also works if cvs has setxid
  * bits set.
  */
-int
-isaccessible (file, mode)
-    const char *file;
-    const int mode;
+bool
+isaccessible (const char *file, const int mode)
 {
 #ifdef SETXID_SUPPORT
     struct stat sb;
@@ -184,20 +186,23 @@
     int omask = 0;
     int uid;
 
-    if (stat(file, &sb) == -1)
-       return 0;
+    if (stat (file, &sb) == -1)
+       return false;
     if (mode == F_OK)
-       return 1;
+       return true;
 
-    uid = geteuid();
+    uid = geteuid ();
     if (uid == 0)              /* superuser */
     {
-       if (mode & X_OK)
-           return sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH);
-       else
-           return 1;
+       if (!(mode & X_OK) || (sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
+           return true;
+
+#ifdef EACCES
+       errno = EACCES;
+#endif
+       return false;
     }
-       
+
     if (mode & R_OK)
     {
        umask |= S_IRUSR;
@@ -219,13 +224,13 @@
 
     if (sb.st_uid == uid)
        return (sb.st_mode & umask) == umask;
-    else if (sb.st_gid == getegid())
+    else if (sb.st_gid == getegid ())
        return (sb.st_mode & gmask) == gmask;
     else
        return (sb.st_mode & omask) == omask;
-#else
-    return access(file, mode) == 0;
-#endif
+#else /* !SETXID_SUPPORT */
+    return access (file, mode) == 0;
+#endif /* SETXID_SUPPORT */
 }
 
 
@@ -234,8 +239,7 @@
  * Make a directory and die if it fails
  */
 void
-make_directory (name)
-    const char *name;
+make_directory (const char *name)
 {
     struct stat sb;
 
@@ -250,8 +254,7 @@
  * goes wrong.
  */
 void
-make_directories (name)
-    const char *name;
+make_directories (const char *name)
 {
     char *cp;
 
@@ -275,12 +278,13 @@
     (void) mkdir (name, 0777);
 }
 
+
+
 /* Create directory NAME if it does not already exist; fatal error for
    other errors.  Returns 0 if directory was created; 1 if it already
    existed.  */
 int
-mkdir_if_needed (name)
-    char *name;
+mkdir_if_needed (char *name)
 {
     if (mkdir (name, 0777) < 0)
     {
@@ -291,6 +295,8 @@
     return 0;
 }
 
+
+
 /*
  * Change the mode of a file, either adding write permissions, or removing
  * all write permissions.  Either change honors the current umask setting.
@@ -299,9 +305,7 @@
  * I've copied over the "attrib" code from os2/filesubr.c.
  */
 void
-xchmod (fname, writable)
-    char *fname;
-    int writable;
+xchmod (char *fname, bool writable)
 {
     char *attrib_cmd;
     char *attrib_option;
@@ -322,7 +326,7 @@
         attrib_option = "-r ";  /* make writeable */
     else
         attrib_option = "+r ";  /* make read-only */
-        
+
     whole_cmd = xmalloc (strlen (attrib_cmd)
                          + strlen (attrib_option)
                          + strlen (fname)
@@ -350,21 +354,16 @@
     free (whole_cmd);
 }
 
+
+
 /*
  * Rename a file and die if it fails
  */
 void
-rename_file (from, to)
-    const char *from;
-    const char *to;
-{
-    if (trace)
-#ifdef SERVER_SUPPORT
-       (void) fprintf (stderr, "%c-> rename(%s,%s)\n",
-                       (server_active) ? 'S' : ' ', from, to);
-#else
-       (void) fprintf (stderr, "-> rename(%s,%s)\n", from, to);
-#endif
+rename_file (const char *from, const char *to)
+{
+    TRACE (TRACE_FUNCTION, "rename(%s,%s)", from, to);
+
     if (noexec)
        return;
 
@@ -373,46 +372,42 @@
        error (1, errno, "cannot rename file %s to %s", from, to);
 }
 
+
+
 /*
  * unlink a file, if possible.
  */
 int
-unlink_file (f)
-    const char *f;
+unlink_file (const char *f)
 {
-    if (trace)
-#ifdef SERVER_SUPPORT
-       (void) fprintf (stderr, "%c-> unlink(%s)\n",
-                       (server_active) ? 'S' : ' ', f);
-#else
-       (void) fprintf (stderr, "-> unlink(%s)\n", f);
-#endif
+    TRACE (TRACE_FUNCTION, "unlink_file(%s)", f);
+
     if (noexec)
-       return (0);
+       return 0;
 
     if (isfile (f))
        xchmod ((char *)f, 1);
-    return (unlink (f));
+    return unlink (f);
 }
 
+
+
 /*
  * Unlink a file or dir, if possible.  If it is a directory do a deep
  * removal of all of the files in the directory.  Return -1 on error
  * (in which case errno is set).
  */
 int
-unlink_file_dir (f)
-    const char *f;
+unlink_file_dir (const char *f)
 {
-    if (trace)
-#ifdef SERVER_SUPPORT
-       (void) fprintf (stderr, "%c-> unlink_file_dir(%s)\n",
-                       (server_active) ? 'S' : ' ', f);
-#else
-       (void) fprintf (stderr, "-> unlink_file_dir(%s)\n", f);
-#endif
+    /* This is called by the server parent process in contexts where
+       it is not OK to send output (e.g. after we sent "ok" to the
+       client).  */
+    if (!server_active)
+       TRACE (TRACE_FUNCTION, "unlink_file_dir(%s)", f);
+
     if (noexec)
-       return (0);
+       return 0;
 
     /* For at least some unices, if root tries to unlink() a directory,
        instead of doing something rational like returning EISDIR,
@@ -422,8 +417,8 @@
        call to isdir() and the call to unlink(), we'll still corrupt
        the filesystem.  Where is the Unix Haters Handbook when you need
        it?  */
-    if (isdir(f))
-       return deep_remove_dir(f);
+    if (isdir (f))
+       return deep_remove_dir (f);
     else
     {
        if (unlink (f) != 0)
@@ -433,13 +428,14 @@
     return 0;
 }
 
+
+
 /* Remove a directory and everything it contains.  Returns 0 for
  * success, -1 for failure (in which case errno is set).
  */
 
 static int
-deep_remove_dir (path)
-    const char *path;
+deep_remove_dir (const char *path)
 {
     DIR                  *dirp;
     struct dirent *dp;
@@ -471,11 +467,11 @@
                /* See comment in unlink_file_dir explanation of why we use
                   isdir instead of just calling unlink and checking the
                   status.  */
-               if (isdir(buf))
+               if (isdir (buf))
                {
-                   if (deep_remove_dir(buf))
+                   if (deep_remove_dir (buf))
                    {
-                       closedir(dirp);
+                       closedir (dirp);
                        return -1;
                    }
                }
@@ -483,7 +479,7 @@
                {
                    if (unlink (buf) != 0)
                    {
-                       closedir(dirp);
+                       closedir (dirp);
                        return -1;
                    }
                }
@@ -499,14 +495,13 @@
     return 0;
 }
 
+
+
 /* Read NCHARS bytes from descriptor FD into BUF.
    Return the number of characters successfully read.
    The number returned is always NCHARS unless end-of-file or error.  */
 static size_t
-block_read (fd, buf, nchars)
-    int fd;
-    char *buf;
-    size_t nchars;
+block_read (int fd, char *buf, size_t nchars)
 {
     char *bp = buf;
     size_t nread;
@@ -534,13 +529,12 @@
 }
 
 
+
 /*
  * Compare "file1" to "file2". Return non-zero if they don't compare exactly.
  */
 int
-xcmp (file1, file2)
-    const char *file1;
-    const char *file2;
+xcmp (const char *file1, const char *file2)
 {
     char *buf1, *buf2;
     struct stat sb1, sb2;
@@ -587,16 +581,16 @@
 
            /* assert (read1 == read2); */
 
-           ret = memcmp(buf1, buf2, read1);
+           ret = memcmp (buf1, buf2, read1);
        } while (ret == 0 && read1 == buf_size);
 
        free (buf1);
        free (buf2);
     }
-       
+
     (void) close (fd1);
     (void) close (fd2);
-    return (ret);
+    return ret;
 }
 
 
@@ -608,7 +602,7 @@
 
 #ifdef LOSING_TMPNAM_FUNCTION
 char *
-cvs_temp_name ()
+cvs_temp_name (void)
 {
     char value[L_tmpnam + 1];
 
@@ -622,7 +616,7 @@
    malloc'd string containing the name.  Returns successfully or not at
    all.  */
 char *
-cvs_temp_name ()
+cvs_temp_name (void)
 {
     char value[L_tmpnam + 1];
     char *retval;
@@ -638,49 +632,9 @@
 
 
 
-/* char *
- * xresolvepath ( const char *path )
- *
- * Like xreadlink(), but resolve all links in a path.
- *
- * INPUTS
- *  path       The original path.
- *
- * RETURNS
- *  The path with any symbolic links expanded.
- *
- * ERRORS
- *  This function exits with a fatal error if it fails to read the link for
- *  any reason.
- */
-char *
-xresolvepath ( path )
-    const char *path;
-{
-    char *hardpath;
-    char *owd;
-
-    /* assert ( isdir ( path ) ); */
-
-    /* FIXME - If HAVE_READLINK is defined, we should probably walk the path
-     * bit by bit calling xreadlink().
-     */
-
-    owd = xgetwd();
-    if ( CVS_CHDIR ( path ) < 0)
-       error ( 1, errno, "cannot chdir to %s", path );
-    if ( ( hardpath = xgetwd() ) == NULL )
-       error (1, errno, "cannot readlink %s", hardpath);
-    if ( CVS_CHDIR ( owd ) < 0)
-       error ( 1, errno, "cannot chdir to %s", owd );
-    free (owd);
-    return hardpath;
-}
-
 /* Return a pointer into PATH's last component.  */
 char *
-last_component (path)
-    char *path;
+last_component (char *path)
 {
     char *last;
 
@@ -700,7 +654,7 @@
    This function will return the same thing every time it is
    called.  */
 char *
-get_homedir ()
+get_homedir (void)
 {
     static char *home = NULL;
     char *env = getenv ("HOME");
@@ -724,11 +678,7 @@
    shell expands the wildcards.  Under EMX, use _fnexplode to get the
    expanded filenames */
 void
-expand_wild (argc, argv, pargc, pargv)
-    int argc;
-    char **argv;
-    int *pargc;
-    char ***pargv;
+expand_wild (int argc, char **argv, int *pargc, char ***pargv)
 {
     int i;
     *pargc = argc;
@@ -783,8 +733,8 @@
 {
     char fn1[MAXNAMLEN], fn2[MAXNAMLEN];
 
-    strcpy (fn1, n1); _fnslashify(fn1);
-    strcpy (fn2, n2); _fnslashify(fn2);
+    strcpy (fn1, n1); _fnslashify (fn1);
+    strcpy (fn2, n2); _fnslashify (fn2);
 
     return _fncmp ((unsigned char *) fn1, (unsigned char *) fn2);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]