Revision: 45521
          http://brlcad.svn.sourceforge.net/brlcad/?rev=45521&view=rev
Author:   brlcad
Date:     2011-07-16 10:42:03 +0000 (Sat, 16 Jul 2011)

Log Message:
-----------
renamed stat.c to file.c in order to reflect the API supporting more than 
determining whether a file exists and stat-style permissions info.

Modified Paths:
--------------
    brlcad/trunk/include/bu.h
    brlcad/trunk/src/libbu/CMakeLists.txt
    brlcad/trunk/src/libbu/Makefile.am

Added Paths:
-----------
    brlcad/trunk/src/libbu/file.c

Removed Paths:
-------------
    brlcad/trunk/src/libbu/stat.c

Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h   2011-07-16 04:00:43 UTC (rev 45520)
+++ brlcad/trunk/include/bu.h   2011-07-16 10:42:03 UTC (rev 45521)
@@ -2775,7 +2775,7 @@
 /** @ingroup io */
 /** @{ */
 
-/** @file libbu/stat.c
+/** @file libbu/file.c
  *
  * Support routines for identifying properties of files and
  * directories such as whether they exist or are the same as another

Modified: brlcad/trunk/src/libbu/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/CMakeLists.txt       2011-07-16 04:00:43 UTC (rev 
45520)
+++ brlcad/trunk/src/libbu/CMakeLists.txt       2011-07-16 10:42:03 UTC (rev 
45521)
@@ -26,6 +26,7 @@
     endian.c
     fchmod.c
     fgets.c
+    file.c
     fnmatch.c
     fopen_uniq.c
     getcwd.c
@@ -68,7 +69,6 @@
     rb_walk.c
     semaphore.c
     simd.c
-    stat.c
     str.c
     tcl.c
     temp.c

Modified: brlcad/trunk/src/libbu/Makefile.am
===================================================================
--- brlcad/trunk/src/libbu/Makefile.am  2011-07-16 04:00:43 UTC (rev 45520)
+++ brlcad/trunk/src/libbu/Makefile.am  2011-07-16 10:42:03 UTC (rev 45521)
@@ -26,6 +26,7 @@
        endian.c \
        fchmod.c \
        fgets.c \
+       file.c \
        fnmatch.c \
        fopen_uniq.c \
        getcwd.c \
@@ -68,7 +69,6 @@
        rb_walk.c \
        semaphore.c \
        simd.c \
-       stat.c \
        str.c \
        tcl.c \
        temp.c \

Copied: brlcad/trunk/src/libbu/file.c (from rev 45436, 
brlcad/trunk/src/libbu/stat.c)
===================================================================
--- brlcad/trunk/src/libbu/file.c                               (rev 0)
+++ brlcad/trunk/src/libbu/file.c       2011-07-16 10:42:03 UTC (rev 45521)
@@ -0,0 +1,238 @@
+/*                         S T A T . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2011 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#include "common.h"
+
+#include <string.h>
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#  include <sys/stat.h>
+#endif
+#ifdef HAVE_PWD_H
+#  include <pwd.h>
+#endif
+#ifdef HAVE_GRP_H
+#  include <grp.h>
+#endif
+#include "bio.h"
+
+#include "bu.h"
+
+#ifndef R_OK
+#  define R_OK 4
+#endif
+#ifndef W_OK
+#  define W_OK 2
+#endif
+#ifndef X_OK
+#  define X_OK 1
+#endif
+
+
+int
+bu_file_exists(const char *path)
+{
+    struct stat sbuf;
+
+    if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
+       bu_log("Does [%s] exist? ", path);
+    }
+
+    if (!path || path[0] == '\0') {
+       if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
+           bu_log("NO\n");
+       }
+       /* FAIL */
+       return 0;
+    }
+
+    /* does it exist as a filesystem entity? */
+    if (stat(path, &sbuf) == 0) {
+       if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
+           bu_log("YES\n");
+       }
+       /* OK */
+       return 1;
+    }
+
+    if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
+       bu_log("NO\n");
+    }
+    /* FAIL */
+    return 0;
+}
+
+
+int
+bu_same_file(const char *fn1, const char *fn2)
+{
+    struct stat sb1, sb2;
+
+    if (UNLIKELY(!fn1 || !fn2)) {
+       return 0;
+    }
+
+    if (UNLIKELY(fn1[0] == '\0' || fn2[0] == '\0')) {
+       return 0;
+    }
+
+    if (!bu_file_exists(fn1) || !bu_file_exists(fn2)) {
+       return 0;
+    }
+
+    if ((stat(fn1, &sb1) == 0) &&
+       (stat(fn2, &sb2) == 0) &&
+       (sb1.st_dev == sb2.st_dev) &&
+       (sb1.st_ino == sb2.st_ino)) {
+       return 1;
+    }
+
+    return 0;
+}
+
+
+int
+bu_same_fd(int fd1, int fd2)
+{
+    struct stat sb1, sb2;
+
+    if (UNLIKELY(fd1<0 || fd2<0)) {
+       return 0;
+    }
+
+    /* ares files the same inode on same device? */
+    if ((fstat(fd1, &sb1) == 0) && (fstat(fd2, &sb2) == 0) && (sb1.st_dev == 
sb2.st_dev) && (sb1.st_ino == sb2.st_ino)) {
+       return 1;
+    }
+
+    return 0;
+}
+
+
+/**
+ * _ b u _ f i l e _ a c c e s s
+ *
+ * common guts to the file access functions that returns truthfully if
+ * the current user has the ability permission-wise to access the
+ * specified file.
+ */
+HIDDEN int
+_bu_file_access(const char *path, int access_level)
+{
+    struct stat sb;
+    int mask = 0;
+
+    /* 0 is root or Windows user */
+    uid_t uid = 0;
+
+    /* 0 is wheel or Windows group */
+    gid_t gid = 0;
+
+    int usr_mask = S_IRUSR | S_IWUSR | S_IXUSR;
+    int grp_mask = S_IRGRP | S_IWGRP | S_IXGRP;
+    int oth_mask = S_IROTH | S_IWOTH | S_IXOTH;
+
+    if (UNLIKELY(!path || (path[0] == '\0'))) {
+       return 0;
+    }
+
+    if (stat(path, &sb) == -1) {
+       return 0;
+    }
+
+    if (access_level & R_OK) {
+       mask = S_IRUSR | S_IRGRP | S_IROTH;
+    }
+    if (access_level & W_OK) {
+       mask = S_IWUSR | S_IWGRP | S_IWOTH;
+    }
+    if (access_level & X_OK) {
+       mask = S_IXUSR | S_IXGRP | S_IXOTH;
+    }
+
+#ifdef HAVE_GETEUID
+    uid = geteuid();
+#endif
+#ifdef HAVE_GETEGID
+    gid = getegid();
+#endif
+
+    if ((uid_t)sb.st_uid == uid) {
+       /* we own it */
+       return sb.st_mode & (mask & usr_mask);
+    } else if ((gid_t)sb.st_gid == gid) {
+       /* our primary group */
+       return sb.st_mode & (mask & grp_mask);
+    }
+
+    /* search group database to see if we're in the file's group */
+#if defined(HAVE_PWD_H) && defined (HAVE_GRP_H)
+    {
+       struct passwd *pwdb = getpwuid(uid);
+       if (pwdb && pwdb->pw_name) {
+           int i;
+           struct group *grdb = getgrgid(sb.st_gid);
+           for (i = 0; grdb && grdb->gr_mem[i]; i++) {
+               if (BU_STR_EQUAL(grdb->gr_mem[i], pwdb->pw_name)) {
+                   /* one of our other groups */
+                   return sb.st_mode & (mask & grp_mask);
+               }
+           }
+       }
+    }
+#endif
+
+    /* check other */
+    return sb.st_mode & (mask & oth_mask);;
+}
+
+
+int
+bu_file_readable(const char *path)
+{
+    return _bu_file_access(path, R_OK);
+}
+
+
+int
+bu_file_writable(const char *path)
+{
+    return _bu_file_access(path, W_OK);
+}
+
+
+int
+bu_file_executable(const char *path)
+{
+    return _bu_file_access(path, X_OK);
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */

Deleted: brlcad/trunk/src/libbu/stat.c
===================================================================
--- brlcad/trunk/src/libbu/stat.c       2011-07-16 04:00:43 UTC (rev 45520)
+++ brlcad/trunk/src/libbu/stat.c       2011-07-16 10:42:03 UTC (rev 45521)
@@ -1,238 +0,0 @@
-/*                         S T A T . C
- * BRL-CAD
- *
- * Copyright (c) 2004-2011 United States Government as represented by
- * the U.S. Army Research Laboratory.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this file; see the file named COPYING for more
- * information.
- */
-
-#include "common.h"
-
-#include <string.h>
-#ifdef HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#  include <sys/stat.h>
-#endif
-#ifdef HAVE_PWD_H
-#  include <pwd.h>
-#endif
-#ifdef HAVE_GRP_H
-#  include <grp.h>
-#endif
-#include "bio.h"
-
-#include "bu.h"
-
-#ifndef R_OK
-#  define R_OK 4
-#endif
-#ifndef W_OK
-#  define W_OK 2
-#endif
-#ifndef X_OK
-#  define X_OK 1
-#endif
-
-
-int
-bu_file_exists(const char *path)
-{
-    struct stat sbuf;
-
-    if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
-       bu_log("Does [%s] exist? ", path);
-    }
-
-    if (!path || path[0] == '\0') {
-       if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
-           bu_log("NO\n");
-       }
-       /* FAIL */
-       return 0;
-    }
-
-    /* does it exist as a filesystem entity? */
-    if (stat(path, &sbuf) == 0) {
-       if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
-           bu_log("YES\n");
-       }
-       /* OK */
-       return 1;
-    }
-
-    if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
-       bu_log("NO\n");
-    }
-    /* FAIL */
-    return 0;
-}
-
-
-int
-bu_same_file(const char *fn1, const char *fn2)
-{
-    struct stat sb1, sb2;
-
-    if (UNLIKELY(!fn1 || !fn2)) {
-       return 0;
-    }
-
-    if (UNLIKELY(fn1[0] == '\0' || fn2[0] == '\0')) {
-       return 0;
-    }
-
-    if (!bu_file_exists(fn1) || !bu_file_exists(fn2)) {
-       return 0;
-    }
-
-    if ((stat(fn1, &sb1) == 0) &&
-       (stat(fn2, &sb2) == 0) &&
-       (sb1.st_dev == sb2.st_dev) &&
-       (sb1.st_ino == sb2.st_ino)) {
-       return 1;
-    }
-
-    return 0;
-}
-
-
-int
-bu_same_fd(int fd1, int fd2)
-{
-    struct stat sb1, sb2;
-
-    if (UNLIKELY(fd1<0 || fd2<0)) {
-       return 0;
-    }
-
-    /* ares files the same inode on same device? */
-    if ((fstat(fd1, &sb1) == 0) && (fstat(fd2, &sb2) == 0) && (sb1.st_dev == 
sb2.st_dev) && (sb1.st_ino == sb2.st_ino)) {
-       return 1;
-    }
-
-    return 0;
-}
-
-
-/**
- * _ b u _ f i l e _ a c c e s s
- *
- * common guts to the file access functions that returns truthfully if
- * the current user has the ability permission-wise to access the
- * specified file.
- */
-HIDDEN int
-_bu_file_access(const char *path, int access_level)
-{
-    struct stat sb;
-    int mask = 0;
-
-    /* 0 is root or Windows user */
-    uid_t uid = 0;
-
-    /* 0 is wheel or Windows group */
-    gid_t gid = 0;
-
-    int usr_mask = S_IRUSR | S_IWUSR | S_IXUSR;
-    int grp_mask = S_IRGRP | S_IWGRP | S_IXGRP;
-    int oth_mask = S_IROTH | S_IWOTH | S_IXOTH;
-
-    if (UNLIKELY(!path || (path[0] == '\0'))) {
-       return 0;
-    }
-
-    if (stat(path, &sb) == -1) {
-       return 0;
-    }
-
-    if (access_level & R_OK) {
-       mask = S_IRUSR | S_IRGRP | S_IROTH;
-    }
-    if (access_level & W_OK) {
-       mask = S_IWUSR | S_IWGRP | S_IWOTH;
-    }
-    if (access_level & X_OK) {
-       mask = S_IXUSR | S_IXGRP | S_IXOTH;
-    }
-
-#ifdef HAVE_GETEUID
-    uid = geteuid();
-#endif
-#ifdef HAVE_GETEGID
-    gid = getegid();
-#endif
-
-    if ((uid_t)sb.st_uid == uid) {
-       /* we own it */
-       return sb.st_mode & (mask & usr_mask);
-    } else if ((gid_t)sb.st_gid == gid) {
-       /* our primary group */
-       return sb.st_mode & (mask & grp_mask);
-    }
-
-    /* search group database to see if we're in the file's group */
-#if defined(HAVE_PWD_H) && defined (HAVE_GRP_H)
-    {
-       struct passwd *pwdb = getpwuid(uid);
-       if (pwdb && pwdb->pw_name) {
-           int i;
-           struct group *grdb = getgrgid(sb.st_gid);
-           for (i = 0; grdb && grdb->gr_mem[i]; i++) {
-               if (BU_STR_EQUAL(grdb->gr_mem[i], pwdb->pw_name)) {
-                   /* one of our other groups */
-                   return sb.st_mode & (mask & grp_mask);
-               }
-           }
-       }
-    }
-#endif
-
-    /* check other */
-    return sb.st_mode & (mask & oth_mask);;
-}
-
-
-int
-bu_file_readable(const char *path)
-{
-    return _bu_file_access(path, R_OK);
-}
-
-
-int
-bu_file_writable(const char *path)
-{
-    return _bu_file_access(path, W_OK);
-}
-
-
-int
-bu_file_executable(const char *path)
-{
-    return _bu_file_access(path, X_OK);
-}
-
-
-/*
- * Local Variables:
- * mode: C
- * tab-width: 8
- * indent-tabs-mode: t
- * c-file-style: "stroustrup"
- * End:
- * ex: shiftwidth=4 tabstop=8
- */


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to