[netcf-devel] [PATCH 1/4] struct netcf: make sure root always ends in '/'

David Lutterkort lutter at redhat.com
Thu Sep 10 19:28:43 UTC 2009


---
 src/internal.h |    3 ++-
 src/netcf.c    |    8 +++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/internal.h b/src/internal.h
index dfc9fff..9e2f5cd 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -125,7 +125,8 @@
  */
 struct netcf {
     ref_t            ref;
-    char            *root;                /* The filesystem root */
+    char            *root;                /* The filesystem root, always ends
+                                           * with '/' */
     const char      *data_dir;            /* Where to find stylesheets etc. */
     netcf_errcode_t  errcode;
     char            *errdetails;          /* Error details */
diff --git a/src/netcf.c b/src/netcf.c
index 45b4557..5977329 100644
--- a/src/netcf.c
+++ b/src/netcf.c
@@ -31,6 +31,7 @@
 
 #include "internal.h"
 #include "netcf.h"
+#include "dutil.h"
 
 /* Clear error code and details */
 #define API_ENTRY(ncf)                          \
@@ -81,7 +82,12 @@ int ncf_init(struct netcf **ncf, const char *root) {
         goto oom;
     if (root == NULL)
         root = "/";
-    (*ncf)->root = strdup(root);
+    if (root[strlen(root)-1] == '/') {
+        (*ncf)->root = strdup(root);
+    } else {
+        if (xasprintf(&(*ncf)->root, "%s/", root) < 0)
+            goto oom;
+    }
     if ((*ncf)->root == NULL)
         goto oom;
     (*ncf)->data_dir = getenv("NETCF_DATADIR");
-- 
1.6.2.5



More information about the netcf-devel mailing list