Ignore:
Timestamp:
04/24/11 04:01:38 (2 years ago)
Author:
reyalP
Message:

change dryos directory wrappers to allow readdir on multiple directories. May fix some problems with "purge raw" in dryos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/platform/generic/wrappers.c

    r1151 r1152  
    362362} 
    363363 
     364//---------------------------------------------------------------------------- 
     365// directory wrappers 
     366#ifndef CAM_DRYOS 
    364367void *opendir(const char* name) { 
    365368    return _opendir(name); 
    366369} 
    367  
    368370void* readdir(void *d) { 
    369 # if !CAM_DRYOS 
    370371    return _readdir(d); 
    371 #else 
    372 // TODO this makes a single static buffer for all directory handles. 
    373 // This means you can only use one at a time, unless you memcpy! 
    374 #ifdef CAM_DRYOS_2_3_R39 
    375   static char de[64]; 
    376 #else 
    377   static char de[40]; 
    378 #endif 
    379  
    380   _ReadFastDir(d, de); 
    381   return de[0]? de : (void*)0; 
    382 #endif 
    383 } 
    384  
     372} 
    385373int closedir(void *d) { 
    386374    return _closedir(d); 
     
    390378    return _rewinddir(d); 
    391379} 
     380#else // dryos 
     381// TODO duplicated in stdlib.h! 
     382// structure returned by dryos 
     383// actual size may vary depending on version 
     384typedef struct { 
     385    int fh; 
     386    int unk[4]; 
     387} DIR_dryos; 
     388 
     389// struct returned by our wrappers around opendir 
     390typedef struct { 
     391    DIR_dryos *dh; 
     392#ifdef CAM_DRYOS_2_3_R39 
     393    char de_buf[64]; 
     394#else 
     395    char de_buf[40]; 
     396#endif 
     397} DIR; 
     398 
     399DIR *opendir(const char* name) { 
     400    DIR *d; 
     401    DIR_dryos *dh = _opendir(name); 
     402    if(!dh) { 
     403        return (void *)0; 
     404    } 
     405    d = _malloc(sizeof(DIR)); 
     406    if(!d) { 
     407        _closedir(dh); 
     408        return (void *)0; 
     409    } 
     410    d->dh = dh; 
     411    return d; 
     412} 
     413 
     414void* readdir(DIR *d) { 
     415  _ReadFastDir(d->dh, d->de_buf); 
     416  return d->de_buf[0]? d->de_buf : (void*)0; 
     417} 
     418 
     419int closedir(DIR *d) { 
     420    int r; 
     421    if(!d) { 
     422        return -1; 
     423    } 
     424    r = _closedir(d->dh); 
     425    _free(d);     
     426    return r; 
     427} 
     428 
     429void rewinddir(DIR *d) { 
     430    if(!d) { 
     431        return; 
     432    } 
     433    _rewinddir(d->dh); 
     434} 
     435#endif // dryos dir functions 
    392436 
    393437int stat(char *name, void *pStat) { 
Note: See TracChangeset for help on using the changeset viewer.