Changeset 1152


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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/stdlib.h

    r1151 r1152  
    203203}; 
    204204#else 
     205// NOTE this is not complete and may not be accurate for all versions 
    205206struct dirent { 
    206207    char                d_name[13]; 
     
    214215#endif 
    215216 
    216 // NOTE this is NOT the actual structure returned by dryos opendir! 
     217#if !CAM_DRYOS 
    217218typedef struct { 
    218     unsigned int        fd; // first member is an fd from Open in dryos 
     219    unsigned int        fd; 
    219220    unsigned int        loc; 
    220221    struct dirent       dir; 
    221222} DIR; 
    222  
     223#else 
     224// structure returned by dryos 
     225// actual size may vary depending on version 
     226typedef struct { 
     227    int fh; 
     228    int unk[4]; 
     229} DIR_dryos; 
     230 
     231// struct returned by our wrappers around opendir 
     232typedef struct { 
     233    DIR_dryos *dh; 
     234#ifdef CAM_DRYOS_2_3_R39 
     235    char de_buf[64]; 
     236#else 
     237    char de_buf[40]; 
     238#endif 
     239} DIR; 
     240#endif 
    223241 
    224242extern DIR*           opendir (const char* name); 
  • 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.