[virt-tools-list] [PATCH 45/47] Fix Win32 portability problem in XML reader

Daniel P. Berrange berrange at redhat.com
Wed Aug 25 19:37:40 UTC 2010


stpcpy is a non-standard extension and can be replaced with
g_strdup_printf resulting in much clearer code. The d_type
entry doesn't exist in readdir() for most platforms.

* osinfo/osinfo_dataread.c: Fix Win32 portability
---
 osinfo/osinfo_dataread.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/osinfo/osinfo_dataread.c b/osinfo/osinfo_dataread.c
index ca84a86..ee4b929 100644
--- a/osinfo/osinfo_dataread.c
+++ b/osinfo/osinfo_dataread.c
@@ -694,14 +694,10 @@ static int osinfo_dataread_file(OsinfoDb *db,
 {
     int ret;
     xmlTextReaderPtr reader;
-    char *rel_name = malloc (strlen(dir) + 1 + strlen(filename) + 1);
-    if (!rel_name)
-      return -errno;
-
-    stpcpy(stpcpy(stpcpy(rel_name, dir), "/"), filename);
+    char *rel_name = g_strdup_printf("%s/%s", dir, filename);
 
     reader = xmlReaderForFile(rel_name, NULL, 0);
-    free(rel_name);
+    g_free(rel_name);
     if (!reader) {
         return -EINVAL;
     }
@@ -735,8 +731,8 @@ void osinfo_dataread(OsinfoDb *db, GError **err)
     }
 
     while ((dp=readdir(dir)) != NULL) {
-        if (dp->d_type != DT_REG)
-            continue;
+        if (dp->d_name[0] == '.')
+	    continue;
         ret = osinfo_dataread_file(db, backingDir, dp->d_name, err);
         if (ret != 0)
             break;
-- 
1.7.2.1




More information about the virt-tools-list mailing list