platform/beos.cpp
changeset 657 dad3b5c307a9
parent 504 3420d82f9b01
child 745 df04959950eb
equal deleted inserted replaced
656:d2c34dbf2c83 657:dad3b5c307a9
    43 
    43 
    44 int __PHYSFS_platformDeinit(void)
    44 int __PHYSFS_platformDeinit(void)
    45 {
    45 {
    46     return(1);  /* always succeed. */
    46     return(1);  /* always succeed. */
    47 } /* __PHYSFS_platformDeinit */
    47 } /* __PHYSFS_platformDeinit */
    48 
       
    49 
       
    50 
       
    51 /* caller needs to malloc() mntpnt, and expect us to free() it. */
       
    52 static void addDisc(char *mntpnt, char ***discs, int *disccount)
       
    53 {
       
    54     char **tmp = (char **) realloc(*discs, sizeof (char *) * (*disccount + 1));
       
    55     if (tmp)
       
    56     {
       
    57         tmp[*disccount - 1] = mntpnt;
       
    58         *discs = tmp;
       
    59         (*disccount)++;
       
    60     } /* if */
       
    61 } /* addDisc */
       
    62 
    48 
    63 
    49 
    64 static char *getMountPoint(const char *devname)
    50 static char *getMountPoint(const char *devname)
    65 {
    51 {
    66     BVolumeRoster mounts;
    52     BVolumeRoster mounts;
    99 
    85 
   100     /*
    86     /*
   101      * This function is lifted from Simple Directmedia Layer (SDL):
    87      * This function is lifted from Simple Directmedia Layer (SDL):
   102      *  http://www.libsdl.org/
    88      *  http://www.libsdl.org/
   103      */
    89      */
   104 static void tryDir(const char *dirname, char ***discs, int *disccount)
    90 static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
   105 {
    91 {
   106     BDirectory dir;
    92     BDirectory dir;
   107     dir.SetTo(dirname);
    93     dir.SetTo(d);
   108     if (dir.InitCheck() != B_NO_ERROR)
    94     if (dir.InitCheck() != B_NO_ERROR)
   109         return;
    95         return;
   110 
    96 
   111     dir.Rewind();
    97     dir.Rewind();
   112     BEntry entry;
    98     BEntry entry;
   125             continue;
   111             continue;
   126 
   112 
   127         if (entry.IsDirectory())
   113         if (entry.IsDirectory())
   128         {
   114         {
   129             if (strcmp(e.name, "floppy") != 0)
   115             if (strcmp(e.name, "floppy") != 0)
   130                 tryDir(name, discs, disccount);
   116                 tryDir(name, callback, data);
   131         } /* if */
   117         } /* if */
   132 
   118 
   133         else
   119         else
   134         {
   120         {
   135             bool add_it = false;
   121             bool add_it = false;
   145                     {
   131                     {
   146                         if (g.device_type == B_CD)
   132                         if (g.device_type == B_CD)
   147                         {
   133                         {
   148                             char *mntpnt = getMountPoint(name);
   134                             char *mntpnt = getMountPoint(name);
   149                             if (mntpnt != NULL)
   135                             if (mntpnt != NULL)
   150                                 addDisc(mntpnt, discs, disccount);
   136                             {
       
   137                                 callback(data, mntpnt);
       
   138                                 free(mntpnt);  /* !!! FIXME: lose this malloc! */
       
   139                             } /* if */
   151                         } /* if */
   140                         } /* if */
   152                     } /* if */
   141                     } /* if */
   153                 } /* if */
   142                 } /* if */
   154             } /* if */
   143             } /* if */
   155 
   144 
   157         } /* else */
   146         } /* else */
   158     } /* while */
   147     } /* while */
   159 } /* tryDir */
   148 } /* tryDir */
   160 
   149 
   161 
   150 
   162 char **__PHYSFS_platformDetectAvailableCDs(void)
   151 void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
   163 {
   152 {
   164     char **retval = (char **) malloc(sizeof (char *));
   153     tryDir("/dev/disk", cb, data);
   165     int cd_count = 1;  /* We count the NULL entry. */
       
   166     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
       
   167     tryDir("/dev/disk", &retval, &cd_count);
       
   168     retval[cd_count - 1] = NULL;
       
   169     return(retval);
       
   170 } /* __PHYSFS_platformDetectAvailableCDs */
   154 } /* __PHYSFS_platformDetectAvailableCDs */
   171 
   155 
   172 
   156 
   173 static team_id getTeamID(void)
   157 static team_id getTeamID(void)
   174 {
   158 {