Revision: 48507
          http://brlcad.svn.sourceforge.net/brlcad/?rev=48507&view=rev
Author:   starseeker
Date:     2012-01-12 15:50:25 +0000 (Thu, 12 Jan 2012)
Log Message:
-----------
rename to bu_realpath.

Modified Paths:
--------------
    brlcad/trunk/include/bu.h
    brlcad/trunk/src/libbu/CMakeLists.txt
    brlcad/trunk/src/libbu/brlcad_path.c
    brlcad/trunk/src/libbu/file.c

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

Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h   2012-01-12 15:48:26 UTC (rev 48506)
+++ brlcad/trunk/include/bu.h   2012-01-12 15:50:25 UTC (rev 48507)
@@ -3018,6 +3018,22 @@
 BU_EXPORT extern size_t bu_dir_list(const char *path, const char *pattern, 
char ***files);
 
 
+/** @file libbu/realpath.c
+ *
+ */
+
+/**
+ * Call canonicalization routines to both expand and validate
+ * a path name.  
+ *
+ * Returns a pointer to the canonical path. If resolved_path is
+ * NULL, caller is responsible for freeing the returned path
+ * via bu_free.  If supplying a result string, the string must hold
+ * at least MAXPATHLEN characters.
+ */
+BU_EXPORT extern char * bu_realpath(const char *path, char *resolved_path);
+
+
 /** @file libbu/brlcad_path.c
  *
  * @brief

Modified: brlcad/trunk/src/libbu/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/CMakeLists.txt       2012-01-12 15:48:26 UTC (rev 
48506)
+++ brlcad/trunk/src/libbu/CMakeLists.txt       2012-01-12 15:50:25 UTC (rev 
48507)
@@ -74,6 +74,7 @@
     rb_rotate.c
     rb_search.c
     rb_walk.c
+        realpath.c
     semaphore.c
     simd.c
     str.c

Modified: brlcad/trunk/src/libbu/brlcad_path.c
===================================================================
--- brlcad/trunk/src/libbu/brlcad_path.c        2012-01-12 15:48:26 UTC (rev 
48506)
+++ brlcad/trunk/src/libbu/brlcad_path.c        2012-01-12 15:50:25 UTC (rev 
48507)
@@ -268,7 +268,7 @@
     lhs = bu_argv0_full_path();
     if (lhs) {
        char *dirpath;
-       char *real_path = bu_file_path_canonicalize(lhs);
+       char *real_path = bu_realpath(lhs, NULL);
        dirpath = bu_dirname(real_path);
        snprintf(real_path, MAXPATHLEN, "%s", dirpath);
        bu_free(dirpath, "free bu_dirname");

Modified: brlcad/trunk/src/libbu/file.c
===================================================================
--- brlcad/trunk/src/libbu/file.c       2012-01-12 15:48:26 UTC (rev 48506)
+++ brlcad/trunk/src/libbu/file.c       2012-01-12 15:50:25 UTC (rev 48507)
@@ -325,31 +325,6 @@
     }
 }
 
-
-char *  
-bu_file_path_canonicalize(const char *path) 
-{
-  char *dirpath;
-  char *resolved_path = (char *)bu_calloc(MAXPATHLEN+1, sizeof(char), 
"resolved_path alloc");
-#ifdef HAVE_REALPATH
-  dirpath = realpath(path, resolved_path);
-  if (!dirpath) {
-    /* if path lookup failed, resort to simple copy */
-    bu_strlcpy(resolved_path, path, (size_t)MAXPATHLEN);
-  }
-#else
-  /* Best solution currently available for Windows
-   * See 
https://www.securecoding.cert.org/confluence/display/seccode/FIO02-C.+Canonicalize+path+names+originating+from+untrusted+sources
 */
-#  ifdef HAVE_GETFULLPATHNAME
-  GetFullPathName(lhs, MAXPATHLEN, resolved_path, NULL);
-#  else
-  /* Last resort - if NOTHING is defined, do a simple copy */
-  bu_strlcpy(resolved_path, lhs, (size_t)MAXPATHLEN);
-#  endif
-#endif
-  return resolved_path;
-}
-
 /*
  * Local Variables:
  * mode: C

Added: brlcad/trunk/src/libbu/realpath.c
===================================================================
--- brlcad/trunk/src/libbu/realpath.c                           (rev 0)
+++ brlcad/trunk/src/libbu/realpath.c   2012-01-12 15:50:25 UTC (rev 48507)
@@ -0,0 +1,63 @@
+/*                       R E A L P A T H . 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 <limits.h>
+#include <stdlib.h>
+
+#include "bio.h"
+
+#include "bu.h"
+
+char *  
+bu_realpath(const char *path, char *resolved_path) 
+{
+  char *dirpath;
+  if (!resolved_path)
+    resolved_path = (char *)bu_calloc(MAXPATHLEN, sizeof(char), "resolved_path 
alloc");
+#ifdef HAVE_REALPATH
+  dirpath = realpath(path, resolved_path);
+  if (!dirpath) {
+    /* if path lookup failed, resort to simple copy */
+    bu_strlcpy(resolved_path, path, (size_t)MAXPATHLEN);
+  }
+#else
+  /* Best solution currently available for Windows
+   * See 
https://www.securecoding.cert.org/confluence/display/seccode/FIO02-C.+Canonicalize+path+names+originating+from+untrusted+sources
 */
+#  ifdef HAVE_GETFULLPATHNAME
+  GetFullPathName(lhs, MAXPATHLEN, resolved_path, NULL);
+#  else
+  /* Last resort - if NOTHING is defined, do a simple copy */
+  bu_strlcpy(resolved_path, lhs, (size_t)MAXPATHLEN);
+#  endif
+#endif
+  return resolved_path;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/src/libbu/realpath.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

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


------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to