platform/unix.c
changeset 657 dad3b5c307a9
parent 570 b331437b9ec0
child 677 c8e2615d6173
equal deleted inserted replaced
656:d2c34dbf2c83 657:dad3b5c307a9
    74 
    74 
    75 
    75 
    76 #ifdef PHYSFS_NO_CDROM_SUPPORT
    76 #ifdef PHYSFS_NO_CDROM_SUPPORT
    77 
    77 
    78 /* Stub version for platforms without CD-ROM support. */
    78 /* Stub version for platforms without CD-ROM support. */
    79 char **__PHYSFS_platformDetectAvailableCDs(void)
    79 void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
    80 {
    80 {
    81     char **retval = (char **) malloc(sizeof (char *));
       
    82     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
       
    83     *retval = NULL;
       
    84     return(retval);
       
    85 } /* __PHYSFS_platformDetectAvailableCDs */
    81 } /* __PHYSFS_platformDetectAvailableCDs */
    86 
    82 
    87 
    83 
    88 #elif (defined PHYSFS_DARWIN)  /* "Big Nasty." */
    84 #elif (defined PHYSFS_DARWIN)  /* "Big Nasty." */
    89 /*
    85 /*
   164 
   160 
   165     return(retval);
   161     return(retval);
   166 } /* darwinIsMountedDisc */
   162 } /* darwinIsMountedDisc */
   167 
   163 
   168 
   164 
   169 char **__PHYSFS_platformDetectAvailableCDs(void)
   165 void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
   170 {
   166 {
   171     const char *devPrefix = "/dev/";
   167     const char *devPrefix = "/dev/";
   172     int prefixLen = strlen(devPrefix);
   168     int prefixLen = strlen(devPrefix);
   173     mach_port_t masterPort = 0;
   169     mach_port_t masterPort = 0;
   174     char **retval = (char **) malloc(sizeof (char *));
       
   175     int cd_count = 1;  /* We count the NULL entry. */
       
   176     struct statfs *mntbufp;
   170     struct statfs *mntbufp;
   177     int i, mounts;
   171     int i, mounts;
   178 
   172 
   179     retval[0] = NULL;
   173     retval[0] = NULL;
   180 
   174 
   189         if (strncmp(dev, devPrefix, prefixLen) != 0)  /* a virtual device? */
   183         if (strncmp(dev, devPrefix, prefixLen) != 0)  /* a virtual device? */
   190             continue;
   184             continue;
   191 
   185 
   192         dev += prefixLen;
   186         dev += prefixLen;
   193         if (darwinIsMountedDisc(dev, masterPort))
   187         if (darwinIsMountedDisc(dev, masterPort))
   194         {
   188             cb(data, mnt);
   195             char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
       
   196             if (tmp)
       
   197             {
       
   198                 retval = tmp;
       
   199                 retval[cd_count - 1] = (char *) malloc(strlen(mnt) + 1);
       
   200                 if (retval[cd_count - 1])
       
   201                 {
       
   202                     strcpy(retval[cd_count - 1], mnt);
       
   203                     cd_count++;
       
   204                 } /* if */
       
   205             } /* if */
       
   206         } /* if */
       
   207     } /* for */
   189     } /* for */
   208 
       
   209     retval[cd_count - 1] = NULL;
       
   210     return(retval);
       
   211 } /* __PHYSFS_platformDetectAvailableCDs */
   190 } /* __PHYSFS_platformDetectAvailableCDs */
   212 
   191 
   213 #elif (defined PHYSFS_HAVE_SYS_UCRED_H)
   192 #elif (defined PHYSFS_HAVE_SYS_UCRED_H)
   214 
   193 
   215 char **__PHYSFS_platformDetectAvailableCDs(void)
   194 void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
   216 {
   195 {
   217     char **retval = (char **) malloc(sizeof (char *));
   196     int i;
   218     int cd_count = 1;  /* We count the NULL entry. */
       
   219     struct statfs *mntbufp = NULL;
   197     struct statfs *mntbufp = NULL;
   220     int mounts;
   198     int mounts = getmntinfo(&mntbufp, MNT_WAIT);
   221     int i;
       
   222 
       
   223     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
       
   224 
       
   225     mounts = getmntinfo(&mntbufp, MNT_WAIT);
       
   226 
   199 
   227     for (i = 0; i < mounts; i++)
   200     for (i = 0; i < mounts; i++)
   228     {
   201     {
   229         int add_it = 0;
   202         int add_it = 0;
   230 
   203 
   234             add_it = 1;
   207             add_it = 1;
   235 
   208 
   236         /* add other mount types here */
   209         /* add other mount types here */
   237 
   210 
   238         if (add_it)
   211         if (add_it)
   239         {
   212             cb(data, mntbufp[i].f_mntonname);
   240             char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
       
   241             if (tmp)
       
   242             {
       
   243                 retval = tmp;
       
   244                 retval[cd_count - 1] = (char *)
       
   245                                 malloc(strlen(mntbufp[i].f_mntonname) + 1);
       
   246                 if (retval[cd_count - 1])
       
   247                 {
       
   248                     strcpy(retval[cd_count - 1], mntbufp[i].f_mntonname);
       
   249                     cd_count++;
       
   250                 } /* if */
       
   251             } /* if */
       
   252         } /* if */
       
   253     } /* for */
   213     } /* for */
   254 
       
   255     retval[cd_count - 1] = NULL;
       
   256     return(retval);
       
   257 } /* __PHYSFS_platformDetectAvailableCDs */
   214 } /* __PHYSFS_platformDetectAvailableCDs */
   258 
   215 
   259 #elif (defined PHYSFS_HAVE_MNTENT_H)
   216 #elif (defined PHYSFS_HAVE_MNTENT_H)
   260 
   217 
   261 char **__PHYSFS_platformDetectAvailableCDs(void)
   218 void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
   262 {
   219 {
   263     char **retval = (char **) malloc(sizeof (char *));
       
   264     int cd_count = 1;  /* We count the NULL entry. */
       
   265     FILE *mounts = NULL;
   220     FILE *mounts = NULL;
   266     struct mntent *ent = NULL;
   221     struct mntent *ent = NULL;
   267 
   222 
   268     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
       
   269 
       
   270     *retval = NULL;
       
   271     mounts = setmntent("/etc/mtab", "r");
   223     mounts = setmntent("/etc/mtab", "r");
   272     BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, retval);
   224     if (mounts == NULL)
       
   225     {
       
   226         __PHYSFS_setError(ERR_IO_ERROR);
       
   227         return;
       
   228     } /* if */
   273 
   229 
   274     while ( (ent = getmntent(mounts)) != NULL )
   230     while ( (ent = getmntent(mounts)) != NULL )
   275     {
   231     {
   276         int add_it = 0;
   232         int add_it = 0;
   277         if (strcmp(ent->mnt_type, "iso9660") == 0)
   233         if (strcmp(ent->mnt_type, "iso9660") == 0)
   278             add_it = 1;
   234             add_it = 1;
   279 
   235 
   280         /* add other mount types here */
   236         /* add other mount types here */
   281 
   237 
   282         if (add_it)
   238         if (add_it)
   283         {
   239             cb(data, ent->mnt_dir);
   284             char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
       
   285             if (tmp)
       
   286             {
       
   287                 retval = tmp;
       
   288                 retval[cd_count-1] = (char *) malloc(strlen(ent->mnt_dir) + 1);
       
   289                 if (retval[cd_count - 1])
       
   290                 {
       
   291                     strcpy(retval[cd_count - 1], ent->mnt_dir);
       
   292                     cd_count++;
       
   293                 } /* if */
       
   294             } /* if */
       
   295         } /* if */
       
   296     } /* while */
   240     } /* while */
   297 
   241 
   298     endmntent(mounts);
   242     endmntent(mounts);
   299 
   243 
   300     retval[cd_count - 1] = NULL;
       
   301     return(retval);
       
   302 } /* __PHYSFS_platformDetectAvailableCDs */
   244 } /* __PHYSFS_platformDetectAvailableCDs */
   303 
   245 
   304 #endif
   246 #endif
   305 
   247 
   306 
   248