platform/os2.c
changeset 657 dad3b5c307a9
parent 599 44af228dd59a
child 691 71d9affe0d8a
equal deleted inserted replaced
656:d2c34dbf2c83 657:dad3b5c307a9
   252     DosClose(hfile);
   252     DosClose(hfile);
   253     return((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01));
   253     return((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01));
   254 } /* is_cdrom_drive */
   254 } /* is_cdrom_drive */
   255 
   255 
   256 
   256 
   257 char **__PHYSFS_platformDetectAvailableCDs(void)
   257 void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
   258 {
   258 {
   259     ULONG dummy;
   259     ULONG dummy = 0;
   260     ULONG drivemap;
   260     ULONG drivemap = 0;
   261     ULONG i, bit;
   261     ULONG i, bit;
   262     APIRET rc;
   262     APIRET rc = DosQueryCurrentDisk(&dummy, &drivemap);
   263     char **retval;
       
   264     PHYSFS_uint32 cd_count = 1;   /* we count the NULL entry. */
       
   265 
       
   266     retval = (char **) malloc(sizeof (char *));
       
   267     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
       
   268     *retval = NULL;
       
   269 
       
   270     rc = DosQueryCurrentDisk(&dummy, &drivemap);
       
   271     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, retval);
   263     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, retval);
   272 
   264 
   273     for (i = 0, bit = 1; i < 26; i++, bit <<= 1)
   265     for (i = 0, bit = 1; i < 26; i++, bit <<= 1)
   274     {
   266     {
   275         if (drivemap & bit)  /* this logical drive exists. */
   267         if (drivemap & bit)  /* this logical drive exists. */
   276         {
   268         {
   277             if ((is_cdrom_drive(i)) && (disc_is_inserted(i)))
   269             if ((is_cdrom_drive(i)) && (disc_is_inserted(i)))
   278             {
   270             {
   279                 char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
   271                 char drive[4] = "x:\\";
   280                 if (tmp)
   272                 drive[0] = ('A' + i);
   281                 {
   273                 cb(data, drive);
   282                     char *str = (char *) malloc(4);
       
   283                     retval = tmp;
       
   284                     retval[cd_count - 1] = str;
       
   285                     if (str)
       
   286                     {
       
   287                         str[0] = ('A' + i);
       
   288                         str[1] = ':';
       
   289                         str[2] = '\\';
       
   290                         str[3] = '\0';
       
   291                         cd_count++;
       
   292                     } /* if */
       
   293                 } /* if */
       
   294             } /* if */
   274             } /* if */
   295         } /* if */
   275         } /* if */
   296     } /* for */
   276     } /* for */
   297 
       
   298     retval[cd_count - 1] = NULL;
       
   299     return(retval);
       
   300 } /* __PHYSFS_platformDetectAvailableCDs */
   277 } /* __PHYSFS_platformDetectAvailableCDs */
   301 
   278 
   302 
   279 
   303 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
   280 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
   304 {
   281 {
   415 
   392 
   416     return(retval);
   393     return(retval);
   417 } /* __PHYSFS_platformCvtToDependent */
   394 } /* __PHYSFS_platformCvtToDependent */
   418 
   395 
   419 
   396 
   420 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   397 void __PHYSFS_platformEnumerateFiles(const char *dirname,
   421                                                   int omitSymLinks)
   398                                      int omitSymLinks,
       
   399                                      PHYSFS_StringCallback callback,
       
   400                                      void *callbackdata)
   422 {
   401 {
   423     char spec[CCHMAXPATH];
   402     char spec[CCHMAXPATH];
   424     LinkedStringList *ret = NULL, *p = NULL;
       
   425     FILEFINDBUF3 fb;
   403     FILEFINDBUF3 fb;
   426     HDIR hdir = HDIR_CREATE;
   404     HDIR hdir = HDIR_CREATE;
   427     ULONG count = 1;
   405     ULONG count = 1;
   428     APIRET rc;
   406     APIRET rc;
   429 
   407 
   437                       &fb, sizeof (fb), &count, FIL_STANDARD);
   415                       &fb, sizeof (fb), &count, FIL_STANDARD);
   438     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
   416     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
   439     while (count == 1)
   417     while (count == 1)
   440     {
   418     {
   441         if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0))
   419         if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0))
   442             ret = __PHYSFS_addToLinkedStringList(ret, &p, fb.achName, -1);
   420             callback(callbackdata, fb.achName);
   443 
   421 
   444         DosFindNext(hdir, &fb, sizeof (fb), &count);
   422         DosFindNext(hdir, &fb, sizeof (fb), &count);
   445     } /* while */
   423     } /* while */
   446 
   424 
   447     DosFindClose(hdir);
   425     DosFindClose(hdir);
   448     return(ret);
       
   449 } /* __PHYSFS_platformEnumerateFiles */
   426 } /* __PHYSFS_platformEnumerateFiles */
   450 
   427 
   451 
   428 
   452 char *__PHYSFS_platformCurrentDir(void)
   429 char *__PHYSFS_platformCurrentDir(void)
   453 {
   430 {