[PATCH 4/8] Files: add a wrapper for opendir()

Lubomir I. Ivanov neolit123 at gmail.com
Wed Dec 18 14:47:02 UTC 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

This is only used in uemis-downloader.c for now, but we
still need the UTF-16 conversation.

Patch also remove some includes from linux.c, windows.c, macos.c.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 dive.h    |  1 +
 linux.c   |  6 +++++-
 macos.c   |  6 +++++-
 windows.c | 15 ++++++++++++++-
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/dive.h b/dive.h
index faacd28..46cbbf6 100644
--- a/dive.h
+++ b/dive.h
@@ -637,6 +637,7 @@ extern void export_dives_uddf(const char *filename, const bool selected);
 extern int subsurface_open(const char *path, int oflags, mode_t mode);
 extern FILE *subsurface_fopen(const char *path, const char *mode);
 extern int subsurface_sqlite3_open(const char *path, sqlite3 **handle);
+extern void *subsurface_opendir(const char *path);
 
 extern void shift_times(const timestamp_t amount);
 
diff --git a/linux.c b/linux.c
index 6c760ac..5380d2c 100644
--- a/linux.c
+++ b/linux.c
@@ -8,7 +8,6 @@
 #include <fnmatch.h>
 #include <stdio.h>
 #include <fcntl.h>
-#include <sqlite3.h>
 
 const char system_divelist_default_font[] = "Sans 8";
 
@@ -116,3 +115,8 @@ int subsurface_sqlite3_open(const char *path, sqlite3 **handle)
 {
 	return sqlite3_open(path, handle);
 }
+
+void *subsurface_opendir(const char *path)
+{
+	return (void *)opendir(path);
+}
diff --git a/macos.c b/macos.c
index eda291d..ffae52a 100644
--- a/macos.c
+++ b/macos.c
@@ -11,7 +11,6 @@
 #include <sys/syslimits.h>
 #include <stdio.h>
 #include <fcntl.h>
-#include <sqlite3.h>
 
 /* macos defines CFSTR to create a CFString object from a constant,
  * but no similar macros if a C string variable is supposed to be
@@ -96,3 +95,8 @@ int subsurface_sqlite3_open(const char *path, sqlite3 **handle)
 {
 	return sqlite3_open(path, handle);
 }
+
+void *subsurface_opendir(const char *path)
+{
+	return (void *)opendir(path);
+}
diff --git a/windows.c b/windows.c
index 27be1df..826ecd4 100644
--- a/windows.c
+++ b/windows.c
@@ -6,7 +6,7 @@
 #include <shlobj.h>
 #include <stdio.h>
 #include <fcntl.h>
-#include <sqlite3.h>
+#include <dirent.h>
 
 const char system_divelist_default_font[] = "Sans 8";
 
@@ -155,3 +155,16 @@ int subsurface_sqlite3_open(const char *path, sqlite3 **handle)
 	}
 	return ret;
 }
+
+/* here we return a void pointer instead of _WDIR or DIR pointer */
+void *subsurface_opendir(const char *path)
+{
+	_WDIR *ret = NULL;
+	wchar_t *wpath = utf8_to_utf16(path);
+	if (wpath) {
+		ret = _wopendir(wpath);
+		free((void *)wpath);
+		return (void *)ret;
+	}
+	return (void *)ret;
+}
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list