changeset 2644:45a6b33a003a

Linux: Isolate linux/android specific code in #ifdef __linux__ So on unrecognized platforms the functions should just return 0. This should allow Android to get filesystem info through Linux calls.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 16 Aug 2021 06:51:28 +0000
parents 28ca1e59e76f
children cb984fab3a17
files dwcompat.c dwcompat.h
diffstat 2 files changed, 11 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/dwcompat.c	Fri Aug 13 22:19:45 2021 +0000
+++ b/dwcompat.c	Mon Aug 16 06:51:28 2021 +0000
@@ -22,7 +22,7 @@
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/statvfs.h>
-#else
+#elif defined(__linux__)
 #include <mntent.h>
 #include <sys/vfs.h>
 #endif
@@ -169,7 +169,7 @@
 		fclose(fp);
 	}
 	return 0;
-#elif !defined(__ANDROID__)
+#elif defined(__linux__)
 	FILE *fp = setmntent(MOUNTED, "r");
 	struct mntent mnt;
 	struct statfs sfs;
@@ -277,7 +277,7 @@
 		fclose(fp);
 	}
 	return 0;
-#elif !defined(__ANDROID__)
+#elif defined(__linux__)
 	FILE *fp = setmntent(MOUNTED, "r");
 	struct mntent mnt;
 	char buffer[1024];
@@ -327,7 +327,6 @@
 	DosError(FERR_ENABLEHARDERR);
 	if (rc == NO_ERROR)
 		return 1;
-
 #elif defined(__WIN32__) || defined(WINNT)
 	char buffer[10] = "C:\\", volname[100];
 	DWORD spc, bps, fc;
@@ -348,7 +347,6 @@
 			return 1;
 		index++;
 	}
-	return 0;
 #elif defined(__sun__)
 	FILE *fp = fopen("/etc/mnttab", "r");
 	struct mnttab mnt;
@@ -373,7 +371,7 @@
 		}
 		fclose(fp);
 	}
-#elif !defined(__ANDROID__)
+#elif defined(__linux__)
 	FILE *fp = setmntent(MOUNTED, "r");
 	struct mntent mnt;
 	char buffer[1024];
@@ -406,7 +404,7 @@
 
 void API getfsname(int drive, char *buf, int len)
 {
-#if defined(__UNIX__) || defined(__MAC__) || defined(__IOS__)
+#if defined(__UNIX__) || defined(__MAC__) || defined(__IOS__) || defined(__ANDROID__)
 #if defined(__FreeBSD__) || defined(__MAC__) || defined(__IOS__)
 	struct statfs *fsp = NULL;
 	int entries, index = 1;
@@ -438,7 +436,7 @@
 		}
 		fclose(fp);
 	}
-#else
+#elif defined(__linux__)
 	FILE *fp = setmntent(MOUNTED, "r");
 	struct mntent mnt;
 	char buffer[1024];
@@ -703,7 +701,7 @@
 static int locale_number = -1, locale_count = 0;
 static char **locale_text = NULL;
 
-void _compat_free_locale(void)
+void _dwcompat_free_locale(void)
 {
 	if(locale_text)
 	{
@@ -719,7 +717,7 @@
 	}
 }
 
-int _stripcrlf(char *buf)
+int _dwcompat_stripcrlf(char *buf)
 {
 	int z, len = (int)strlen(buf);
 
@@ -743,7 +741,7 @@
 	static char text[1025];
 	int count = 0;
 
-	_compat_free_locale();
+	_dwcompat_free_locale();
 
 	if(fp)
 	{
@@ -755,7 +753,7 @@
 
 			while(!feof(fp))
 			{
-				if(fgets(text, 1024, fp) && _stripcrlf(text) &&
+				if(fgets(text, 1024, fp) && _dwcompat_stripcrlf(text) &&
 				   strncasecmp(text, "LOCALE=", 7) == 0)
 				{
 					if(current > -1)
--- a/dwcompat.h	Fri Aug 13 22:19:45 2021 +0000
+++ b/dwcompat.h	Mon Aug 16 06:51:28 2021 +0000
@@ -11,6 +11,7 @@
 #else
 #define HAVE_DIRENT_H 1
 #define HAVE_PIPE 1
+#define HAVE_VSNPRINTF 1
 #endif
 
 /* Attempt to include 64 bit file functions on various unix flavors */