Revision: 40447
          http://brlcad.svn.sourceforge.net/brlcad/?rev=40447&view=rev
Author:   bob1961
Date:     2010-09-03 13:17:06 +0000 (Fri, 03 Sep 2010)

Log Message:
-----------
Modified db_open to set dbi_filename to the full path using the current working 
directory if dirname is ".". Still need code to convert all relative paths to 
full paths. This mod fixes the recent rt failure reported by Dwayne for most 
cases.

Modified Paths:
--------------
    brlcad/trunk/src/librt/db_open.c

Modified: brlcad/trunk/src/librt/db_open.c
===================================================================
--- brlcad/trunk/src/librt/db_open.c    2010-09-03 03:08:06 UTC (rev 40446)
+++ brlcad/trunk/src/librt/db_open.c    2010-09-03 13:17:06 UTC (rev 40447)
@@ -155,9 +155,6 @@
     dbip->dbi_title = (char *)0;
     dbip->dbi_uses = 1;
 
-    /* Record the filename and file path */
-    dbip->dbi_filename = bu_strdup(name);
-
     /* XXX At some point, expand with getenv("BRLCAD_FILE_PATH"); */
     argv = (char **)bu_malloc(3 * sizeof(char *), "dbi_filepath[3]");
     argv[0] = bu_strdup(".");
@@ -165,6 +162,48 @@
     argv[2] = NULL;
     dbip->dbi_filepath = argv;
 
+    /*
+     * XXX Need code to convert all relative paths to full paths.
+     *
+     * For now, if dirname is "." use the CWD and
+     * update the filename to include the fullpath.
+     */
+    if (argv[1][0] == '.' && argv[1][1] == '\0') {
+       struct bu_vls fullpath;
+
+       bu_vls_init(&fullpath);
+       bu_free((genptr_t)argv[1], "db_open: argv[1]");
+       argv[1] = getcwd((char *)NULL, (size_t)MAXPATHLEN);
+
+       /* Something went wrong and we didn't get the CWD. So,
+        * free up any memory allocated here and return DBI_NULL */
+       if (argv[1] == NULL) {
+           if (dbip->dbi_mf) {
+               bu_close_mapped_file(dbip->dbi_mf);
+               bu_free_mapped_files(0);
+               dbip->dbi_mf = (struct bu_mapped_file *)NULL;
+           }
+
+           if (dbip->dbi_fp) {
+               fclose(dbip->dbi_fp);
+           }
+
+           bu_free((genptr_t)argv[0], "db_open: argv[0]");
+           bu_free((genptr_t)argv, "db_open: argv");
+           bu_free((char *)dbip, "struct db_i");
+           bu_vls_free(&fullpath);
+
+           return DBI_NULL;
+       }
+
+       bu_vls_printf(&fullpath, "%s/%s", argv[1], name);
+       dbip->dbi_filename = bu_strdup(bu_vls_addr(&fullpath));
+       bu_vls_free(&fullpath);
+    } else {
+       /* Record the filename and file path */
+       dbip->dbi_filename = bu_strdup(name);
+    }
+
     bu_ptbl_init(&dbip->dbi_clients, 128, "dbi_clients[]");
     dbip->dbi_magic = DBI_MAGIC;               /* Now it's valid */
 


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

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to