diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2000-06-02 21:38:19 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2000-06-02 21:38:19 (GMT) |
commit | 2b44ba5203a45c54caec57695e20ef6cc4c870a2 (patch) | |
tree | 1467d4b49f1eb35ccfcb76404c5228af2081d4c7 /Mac/Compat/opendir.c | |
parent | a04b24bf8d7dfd881176427e1140a410e2df6d41 (diff) | |
download | cpython-2b44ba5203a45c54caec57695e20ef6cc4c870a2.zip cpython-2b44ba5203a45c54caec57695e20ef6cc4c870a2.tar.gz cpython-2b44ba5203a45c54caec57695e20ef6cc4c870a2.tar.bz2 |
Revived various of the compatability routines and made them Carbon-compliant. This is needed because the initial carbon-python does not use GUSI.
Diffstat (limited to 'Mac/Compat/opendir.c')
-rw-r--r-- | Mac/Compat/opendir.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/Mac/Compat/opendir.c b/Mac/Compat/opendir.c index d24f5fd..f803236 100644 --- a/Mac/Compat/opendir.c +++ b/Mac/Compat/opendir.c @@ -20,6 +20,31 @@ DIR * opendir(path) char *path; { +#ifdef TARGET_API_MAC_CARBON + Str255 ppath; + FSSpec fss; + int plen; + OSErr err; + + if (opened.nextfile != 0) { + errno = EBUSY; + return NULL; /* A directory is already open. */ + } + plen = strlen(path); + c2pstrcpy(ppath, path); + if ( ppath[plen] != ':' ) + ppath[++plen] = ':'; + ppath[++plen] = 'x'; + ppath[0] = plen; + if( (err = FSMakeFSSpec(0, 0, ppath, &fss)) < 0 && err != fnfErr ) { + errno = EIO; + return NULL; + } + opened.dirid = fss.parID; + opened.vrefnum = fss.vRefNum; + opened.nextfile = 1; + return &opened; +#else union { WDPBRec d; VolumeParam v; @@ -34,15 +59,9 @@ opendir(path) strncpy(ppath+1, path, ppath[0]= strlen(path)); pb.d.ioNamePtr= (unsigned char *)ppath; pb.d.ioVRefNum= 0; - if (hfsrunning()) { - pb.d.ioWDProcID= 0; - pb.d.ioWDDirID= 0; - err= PBOpenWD((WDPBPtr)&pb, 0); - } - else { - pb.v.ioVolIndex= 0; - err= PBGetVInfo((ParmBlkPtr)&pb, 0); - } + pb.d.ioWDProcID= 0; + pb.d.ioWDDirID= 0; + err= PBOpenWD((WDPBPtr)&pb, 0); if (err != noErr) { errno = ENOENT; return NULL; @@ -50,6 +69,7 @@ opendir(path) opened.dirid= pb.d.ioVRefNum; opened.nextfile= 1; return &opened; +#endif } /* @@ -60,14 +80,16 @@ void closedir(dirp) DIR *dirp; { - if (hfsrunning()) { - WDPBRec pb; - - pb.ioVRefNum= dirp->dirid; - (void) PBCloseWD(&pb, 0); - } +#ifdef TARGET_API_MAC_CARBON + dirp->nextfile = 0; +#else + WDPBRec pb; + + pb.ioVRefNum= dirp->dirid; + (void) PBCloseWD(&pb, 0); dirp->dirid= 0; dirp->nextfile= 0; +#endif } /* @@ -88,17 +110,23 @@ readdir(dp) dir.d_name[0]= 0; pb.d.ioNamePtr= (unsigned char *)dir.d_name; +#ifdef TARGET_API_MAC_CARBON + pb.d.ioVRefNum= dp->vrefnum; + pb.d.ioDrDirID= dp->dirid; +#else pb.d.ioVRefNum= dp->dirid; - pb.d.ioFDirIndex= dp->nextfile++; pb.d.ioDrDirID= 0; - if (hfsrunning()) - err= PBGetCatInfo((CInfoPBPtr)&pb, 0); - else - err= PBGetFInfo((ParmBlkPtr)&pb, 0); +#endif + pb.d.ioFDirIndex= dp->nextfile++; + err= PBGetCatInfo((CInfoPBPtr)&pb, 0); if (err != noErr) { errno = EIO; return NULL; } +#ifdef TARGET_API_MAC_CARBON + p2cstrcpy(dir.d_name, (StringPtr)dir.d_name); +#else (void) p2cstr((unsigned char *)dir.d_name); +#endif return &dir; } |