platform/unix.c
changeset 63 cb9a4714b844
parent 41 ff60d39d0862
child 67 5000499d4ee2
equal deleted inserted replaced
62:16f36aa0b9d3 63:cb9a4714b844
    37 #include <sys/stat.h>
    37 #include <sys/stat.h>
    38 #include <sys/param.h>
    38 #include <sys/param.h>
    39 #include <dirent.h>
    39 #include <dirent.h>
    40 #include <time.h>
    40 #include <time.h>
    41 #include <errno.h>
    41 #include <errno.h>
    42 
    42 #include <mntent.h>
    43 
    43 
    44 #define __PHYSICSFS_INTERNAL__
    44 #define __PHYSICSFS_INTERNAL__
    45 #include "physfs_internal.h"
    45 #include "physfs_internal.h"
    46 
    46 
    47 
    47 
    48 const char *__PHYSFS_platformDirSeparator = "/";
    48 const char *__PHYSFS_platformDirSeparator = "/";
    49 
    49 
    50 char **__PHYSFS_platformDetectAvailableCDs(void)
    50 char **__PHYSFS_platformDetectAvailableCDs(void)
    51 {
    51 {
    52     /* !!! write me. */
    52     char **retval = (char **) malloc(sizeof (char *));
    53     char **retval = malloc(sizeof (char *));
    53     int cd_count = 1;  /* We count the NULL entry. */
    54     if (retval != NULL)
    54     FILE *mounts = NULL;
    55         *retval = NULL;
    55     struct mntent *ent = NULL;
    56 
    56 
       
    57     *retval = NULL;
       
    58     mounts = setmntent("/etc/mtab", "r");
       
    59     BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, retval);
       
    60 
       
    61     while ( (ent = getmntent(mounts)) != NULL )
       
    62     {
       
    63         int add_it = 0;
       
    64         if (strcmp(ent->mnt_type, "iso9660") == 0)
       
    65             add_it = 1;
       
    66         /* !!! other mount types? */
       
    67 
       
    68         if (add_it)
       
    69         {
       
    70             char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
       
    71             if (tmp)
       
    72             {
       
    73                 retval = tmp;
       
    74                 retval[cd_count-1] = (char *) malloc(strlen(ent->mnt_dir) + 1);
       
    75                 if (retval[cd_count-1])
       
    76                 {
       
    77                     strcpy(retval[cd_count-1], ent->mnt_dir);
       
    78                     cd_count++;
       
    79                 } /* if */
       
    80             } /* if */
       
    81         } /* if */
       
    82     } /* while */
       
    83 
       
    84     endmntent(mounts);
       
    85 
       
    86     retval[cd_count - 1] = NULL;
    57     return(retval);
    87     return(retval);
    58 } /* __PHYSFS_detectAvailableCDs */
    88 } /* __PHYSFS_detectAvailableCDs */
    59 
    89 
    60 
    90 
    61 static char *copyEnvironmentVariable(const char *varname)
    91 static char *copyEnvironmentVariable(const char *varname)