Source-Changes-HG archive

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

[src/trunk]: src/external/gpl2/xcvs/dist/src 1/2 the number of {l, s}stat(2) c...



details:   https://anonhg.NetBSD.org/src/rev/9d8598045d8b
branches:  trunk
changeset: 826595:9d8598045d8b
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 15 21:03:26 2017 +0000

description:
1/2 the number of {l,s}stat(2) calls by exposing the stat data found
when calling islink()!

diffstat:

 external/gpl2/xcvs/dist/src/cvs.h        |   2 +-
 external/gpl2/xcvs/dist/src/filesubr.c   |  39 ++++++++++++++++++-------------
 external/gpl2/xcvs/dist/src/find_names.c |   4 +-
 external/gpl2/xcvs/dist/src/import.c     |   8 +++---
 external/gpl2/xcvs/dist/src/rcs.c        |   6 ++--
 external/gpl2/xcvs/dist/src/subr.c       |   4 +-
 external/gpl2/xcvs/dist/src/update.c     |  10 ++++----
 external/gpl2/xcvs/dist/src/vers_ts.c    |  16 ++++++------
 8 files changed, 47 insertions(+), 42 deletions(-)

diffs (289 lines):

diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/cvs.h
--- a/external/gpl2/xcvs/dist/src/cvs.h Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/cvs.h Fri Sep 15 21:03:26 2017 +0000
@@ -516,7 +516,7 @@
 int SIG_register (int sig, SIGCLEANUPPROC sigcleanup);
 bool isdir (const char *file);
 bool isfile (const char *file);
-ssize_t islink (const char *file);
+ssize_t islink (const char *file, struct stat *stp);
 bool isdevice (const char *file);
 bool isreadable (const char *file);
 bool iswritable (const char *file);
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/filesubr.c
--- a/external/gpl2/xcvs/dist/src/filesubr.c    Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/filesubr.c    Fri Sep 15 21:03:26 2017 +0000
@@ -13,7 +13,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: filesubr.c,v 1.5 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: filesubr.c,v 1.6 2017/09/15 21:03:26 christos Exp $");
 
 /* These functions were moved out of subr.c because they need different
    definitions under operating systems (like, say, Windows NT) with different
@@ -25,6 +25,13 @@
 #include "xsize.h"
 
 static int deep_remove_dir (const char *path);
+#ifndef S_ISBLK
+#define S_ISBLK(a) 0
+#endif
+#ifndef S_ISCHR
+#define S_ISCHR(a) 0
+#endif
+#define IS_DEVICE(sbp) (S_ISBLK((sbp)->st_mode) || S_ISCHR((sbp)->st_mode))
 
 /*
  * Copies "from" to "to".
@@ -44,7 +51,7 @@
 
     /* If the file to be copied is a link or a device, then just create
        the new link or device appropriately. */
-    if ((rsize = islink (from)) > 0)
+    if ((rsize = islink (from, &sb)) > 0)
     {
        char *source = Xreadlink (from, rsize);
        if (symlink (source, to) == -1)
@@ -53,11 +60,9 @@
        return;
     }
 
-    if (isdevice (from))
+    if (sb.st_ino != -1 && IS_DEVICE (&sb))
     {
 #if defined(HAVE_MKNOD) && defined(HAVE_STRUCT_STAT_ST_RDEV)
-       if (stat (from, &sb) < 0)
-           error (1, errno, "cannot stat %s", from);
        mknod (to, sb.st_mode, sb.st_rdev);
 #else
        error (1, 0, "cannot copy device files on this system (%s)", from);
@@ -136,14 +141,22 @@
  * Returns size of the link if it is a symbolic link.
  */
 ssize_t
-islink (const char *file)
+islink (const char *file, struct stat *sbp)
 {
     ssize_t retsize = 0;
 #ifdef S_ISLNK
     struct stat sb;
+    if (sbp == NULL)
+       sbp = &sb;
 
-    if ((lstat (file, &sb) >= 0) && S_ISLNK (sb.st_mode))
-       retsize = sb.st_size;
+    if (lstat (file, sbp) < 0) {
+       sbp->st_ino = -1;
+       return 0;
+    }
+    if (S_ISLNK (sbp->st_mode))
+       retsize = sbp->st_size;
+#else
+    sbp->st_ino = -1;
 #endif
     return retsize;
 }
@@ -161,15 +174,7 @@
 
     if (lstat (file, &sb) < 0)
        return false;
-#ifdef S_ISBLK
-    if (S_ISBLK (sb.st_mode))
-       return true;
-#endif
-#ifdef S_ISCHR
-    if (S_ISCHR (sb.st_mode))
-       return true;
-#endif
-    return false;
+    return IS_DEVICE(&sb);
 }
 
 
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/find_names.c
--- a/external/gpl2/xcvs/dist/src/find_names.c  Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/find_names.c  Fri Sep 15 21:03:26 2017 +0000
@@ -21,7 +21,7 @@
  * repository (and optionally the attic)
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: find_names.c,v 1.3 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: find_names.c,v 1.4 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include <glob.h>
@@ -494,7 +494,7 @@
 #endif
                /* Note that we only get here if we already set tmp
                   above.  */
-               if (islink (tmp))
+               if (islink (tmp, NULL))
                    goto do_it_again;
 #ifdef DT_DIR
            }
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/import.c
--- a/external/gpl2/xcvs/dist/src/import.c      Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/import.c      Fri Sep 15 21:03:26 2017 +0000
@@ -21,7 +21,7 @@
  * Additional arguments specify more Vendor Release Tags.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: import.c,v 1.7 2016/05/30 17:49:51 christos Exp $");
+__RCSID("$NetBSD: import.c,v 1.8 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include "lstat.h"
@@ -520,9 +520,9 @@
            else if (
 #ifdef DT_DIR
                     dp->d_type == DT_LNK
-                    || (dp->d_type == DT_UNKNOWN && islink (dp->d_name))
+                    || (dp->d_type == DT_UNKNOWN && islink (dp->d_name, NULL))
 #else
-                    islink (dp->d_name)
+                    islink (dp->d_name, NULL)
 #endif
                     )
            {
@@ -1722,7 +1722,7 @@
     int ierrno, err;
     char *rcs = NULL;
 
-    if (islink (dir))
+    if (islink (dir, NULL))
        return 0;
     if (save_cwd (&cwd))
     {
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/rcs.c
--- a/external/gpl2/xcvs/dist/src/rcs.c Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/rcs.c Fri Sep 15 21:03:26 2017 +0000
@@ -14,7 +14,7 @@
  * manipulation
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rcs.c,v 1.6 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: rcs.c,v 1.7 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include "edit.h"
@@ -4549,7 +4549,7 @@
            {
                /* Symbolic links should be removed before replacement, so that
                   `fopen' doesn't follow the link and open the wrong file. */
-               if (islink (sout))
+               if (islink (sout, NULL))
                    if (unlink_file (sout) < 0)
                        error (1, errno, "cannot remove %s", sout);
                ofp = CVS_FOPEN (sout, expand == KFLAG_B ? "wb" : "w");
@@ -4561,7 +4561,7 @@
        {
            /* Output is supposed to go to WORKFILE, so we should open that
               file.  Symbolic links should be removed first (see above). */
-           if (islink (workfile))
+           if (islink (workfile, NULL))
                if (unlink_file (workfile) < 0)
                    error (1, errno, "cannot remove %s", workfile);
 
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/subr.c
--- a/external/gpl2/xcvs/dist/src/subr.c        Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/subr.c        Fri Sep 15 21:03:26 2017 +0000
@@ -13,7 +13,7 @@
  * Various useful functions for the CVS support code.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: subr.c,v 1.4 2016/05/30 17:49:51 christos Exp $");
+__RCSID("$NetBSD: subr.c,v 1.5 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 
@@ -719,7 +719,7 @@
     if (filename == NULL || *filename == NULL)
        return;
 
-    while ((rsize = islink (*filename)) > 0)
+    while ((rsize = islink (*filename, NULL)) > 0)
     {
 #ifdef HAVE_READLINK
        /* The clean thing to do is probably to have each filesubr.c
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/update.c
--- a/external/gpl2/xcvs/dist/src/update.c      Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/update.c      Fri Sep 15 21:03:26 2017 +0000
@@ -38,7 +38,7 @@
  * as well.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: update.c,v 1.11 2017/01/04 16:11:20 christos Exp $");
+__RCSID("$NetBSD: update.c,v 1.12 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include <assert.h>
@@ -2678,12 +2678,12 @@
     {
        ssize_t rsize;
 
-       if ((rsize = islink (finfo->file)) > 0)
+       if ((rsize = islink (finfo->file, &sb)) > 0)
            rev1_symlink = Xreadlink (finfo->file, rsize);
        else
        {
 # ifdef HAVE_STRUCT_STAT_ST_RDEV
-           if (lstat (finfo->file, &sb) < 0)
+           if (sb.st_ino == -1)
                error (1, errno, "could not get file information for %s",
                       finfo->file);
            rev1_uid = sb.st_uid;
@@ -2758,12 +2758,12 @@
     {
        ssize_t rsize;
 
-       if ((rsize = islink (finfo->file)) > 0)
+       if ((rsize = islink (finfo->file, &sb)) > 0)
            rev2_symlink = Xreadlink (finfo->file, rsize);
        else
        {
 # ifdef HAVE_STRUCT_STAT_ST_RDEV
-           if (lstat (finfo->file, &sb) < 0)
+           if (sb.st_ino == -1)
                error (1, errno, "could not get file information for %s",
                       finfo->file);
            rev2_uid = sb.st_uid;
diff -r 22dfceb88938 -r 9d8598045d8b external/gpl2/xcvs/dist/src/vers_ts.c
--- a/external/gpl2/xcvs/dist/src/vers_ts.c     Fri Sep 15 19:20:11 2017 +0000
+++ b/external/gpl2/xcvs/dist/src/vers_ts.c     Fri Sep 15 21:03:26 2017 +0000
@@ -11,7 +11,7 @@
  * specified in the README file that comes with the CVS source distribution.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: vers_ts.c,v 1.2 2016/05/17 14:00:09 christos Exp $");
+__RCSID("$NetBSD: vers_ts.c,v 1.3 2017/09/15 21:03:26 christos Exp $");
 
 #include "cvs.h"
 #include "lstat.h"
@@ -401,19 +401,19 @@
 unix_time_stamp (const char *file)
 {
     struct stat sb;
-    time_t mtime = 0L;
+    time_t mtime;
+    bool lnk;
 
-    if (!lstat (file, &sb))
-    {
-       mtime = sb.st_mtime;
-    }
+    if (!(lnk = islink (file, &sb)) && sb.st_ino == -1)
+       return 0;
+    mtime = sb.st_mtime;
 
     /* If it's a symlink, return whichever is the newest mtime of
        the link and its target, for safety.
     */
-    if (!stat (file, &sb))
+    if (lnk && stat (file, &sb) != -1)
     {
-        if (mtime < sb.st_mtime)
+       if (mtime < sb.st_mtime)
            mtime = sb.st_mtime;
     }
 



Home | Main Index | Thread Index | Old Index