From a02436d7c29ad18fab01245fa924aba9d814f6cc Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 7 Aug 2001 03:33:44 +0000 Subject: [PATCH] Added CD-ROM detection code. --- platform/unix.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/platform/unix.c b/platform/unix.c index 6229ebd1..42bed070 100644 --- a/platform/unix.c +++ b/platform/unix.c @@ -39,7 +39,7 @@ #include #include #include - +#include #define __PHYSICSFS_INTERNAL__ #include "physfs_internal.h" @@ -49,11 +49,41 @@ const char *__PHYSFS_platformDirSeparator = "/"; char **__PHYSFS_platformDetectAvailableCDs(void) { - /* !!! write me. */ - char **retval = malloc(sizeof (char *)); - if (retval != NULL) - *retval = NULL; + char **retval = (char **) malloc(sizeof (char *)); + int cd_count = 1; /* We count the NULL entry. */ + FILE *mounts = NULL; + struct mntent *ent = NULL; + + *retval = NULL; + mounts = setmntent("/etc/mtab", "r"); + BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, retval); + + while ( (ent = getmntent(mounts)) != NULL ) + { + int add_it = 0; + if (strcmp(ent->mnt_type, "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(ent->mnt_dir) + 1); + if (retval[cd_count-1]) + { + strcpy(retval[cd_count-1], ent->mnt_dir); + cd_count++; + } /* if */ + } /* if */ + } /* if */ + } /* while */ + + endmntent(mounts); + retval[cd_count - 1] = NULL; return(retval); } /* __PHYSFS_detectAvailableCDs */