From cb2a15d302c34c11baa37ac9717a0f43a01e2fba Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 5 Mar 2002 19:16:38 +0000 Subject: [PATCH] Darwin support by Patrick Stein. --- platform/unix.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/platform/unix.c b/platform/unix.c index 3227237d..17831dae 100644 --- a/platform/unix.c +++ b/platform/unix.c @@ -6,6 +6,12 @@ * This file written by Ryan C. Gordon. */ +#if ((defined __APPLE__) && (defined __MACH__)) +# if (!defined __DARWIN__) +# define __DARWIN__ +# endif +#endif + #if (defined __STRICT_ANSI__) #define __PHYSFS_DOING_STRICT_ANSI__ #endif @@ -40,6 +46,11 @@ #include #include #include +#include + +#if (defined __DARWIN__) +#include +#endif #define __PHYSICSFS_INTERNAL__ #include "physfs_internal.h" @@ -47,6 +58,53 @@ const char *__PHYSFS_platformDirSeparator = "/"; + +#if (defined __DARWIN__) + +char **__PHYSFS_platformDetectAvailableCDs(void) +{ + char **retval = (char **) malloc(sizeof (char *)); + int cd_count = 1; /* We count the NULL entry. */ + struct statfs* mntbufp = NULL; + int mounts; + int ii; + + mounts = getmntinfo( &mntbufp, MNT_WAIT ); + + for ( ii=0; ii < mounts; ++ii ) { + int add_it = 0; + + if ( strcmp( mntbufp[ii].f_fstypename, "iso9660") == 0 ) + add_it = 1; + /* !!! other mount types? */ + + if (add_it) + { + char **tmp = realloc(retval, sizeof (char *) * cd_count + 1); + if (tmp) + { + retval = tmp; + retval[cd_count-1] = (char *) + malloc(strlen(mntbufp[ ii ].f_mntonname) + 1); + if (retval[cd_count-1]) + { + strcpy(retval[cd_count-1], mntbufp[ ii ].f_mntonname); + cd_count++; + } /* if */ + } /* if */ + } /* if */ + } + + free( mntbufp ); + + retval[cd_count - 1] = NULL; + return(retval); +} /* __PHYSFS_platformDetectAvailableCDs */ + + +#else /* non-Darwin implementation... */ + + char **__PHYSFS_platformDetectAvailableCDs(void) { char **retval = (char **) malloc(sizeof (char *)); @@ -85,7 +143,9 @@ char **__PHYSFS_platformDetectAvailableCDs(void) retval[cd_count - 1] = NULL; return(retval); -} /* __PHYSFS_detectAvailableCDs */ +} /* __PHYSFS_platformDetectAvailableCDs */ + +#endif static char *copyEnvironmentVariable(const char *varname)