]> granicus.if.org Git - python/commitdiff
Revived various of the compatability routines and made them Carbon-compliant. This...
authorJack Jansen <jack.jansen@cwi.nl>
Fri, 2 Jun 2000 21:38:19 +0000 (21:38 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Fri, 2 Jun 2000 21:38:19 +0000 (21:38 +0000)
Mac/Compat/dirent.h
Mac/Compat/getwd.c
Mac/Compat/macstat.c
Mac/Compat/opendir.c

index 44cfc5a97253f2548641de5ddf89f0c46665a461..7cfe40433e5dab42dd41e222dbf13c54ae3fc9bb 100644 (file)
@@ -9,6 +9,7 @@
 #define DIR  struct _dir
 
 struct _dir {
+       short vrefnum;
        long dirid;
        int nextfile;
 };
index 16b010a97d7be62b5b9a3cc284b90655c26ffd9f..a58fb6a4ac15b9df3c2315524a977322edb65ac0 100644 (file)
@@ -59,13 +59,18 @@ getwd(cwd)
                sprintf(cwd, "I/O error %d in PBHGetVolSync", err);
                return NULL;
        }
+#ifdef TARGET_API_MAC_CARBON
+       p2cstrcpy(cwd, (StringPtr)cwd);
+       ecwd = strchr(cwd, EOS);
+#else
        ecwd= strchr((const char *)p2cstr((unsigned char*)cwd), EOS);
+#endif
        ebuf= buf;
        *ebuf = EOS;
        
        /* Next, if at least we're running HFS, walk up the path. */
        
-       if (hfsrunning()) {
+       {
                long dirid= pb.w.ioWDDirID;
                pb.d.ioVRefNum= pb.w.ioWDVRefNum;
                while (dirid != ROOTID) {
@@ -78,7 +83,12 @@ getwd(cwd)
                                return NULL;
                        }
                        dirid= pb.d.ioDrParID;
+#ifdef TARGET_API_MAC_CARBON
+                       p2cstrcpy(ebuf, (StringPtr)ebuf);
+                       ebuf += strlen(ebuf);
+#else
                        ebuf += strlen((const char *)p2cstr((unsigned char *)ebuf));
+#endif
                        /* Should check for buf overflow */
                }
        }
index 8c67994525612a4b840ce3e2196c1275087c5fff..ee2c099dd7bbd5d67ba321991d53e25f5b67ef5d 100644 (file)
@@ -28,10 +28,7 @@ macstat(path, buf)
        pb.d.ioFDirIndex = 0;
        pb.d.ioDrDirID = 0;
        pb.f.ioFVersNum = 0; /* Fix found by Timo! See Tech Note 102 */
-       if (hfsrunning())
-               err = PBGetCatInfoSync((CInfoPBPtr)&pb);
-       else
-               err = PBGetFInfoSync((ParmBlkPtr)&pb);
+       err = PBGetCatInfoSync((CInfoPBPtr)&pb);
        if (err != noErr) {
                errno = ENOENT;
                return -1;
index d24f5fd53129c67ccb6e00c015edb8d22e3292c8..f8032368781f6cc1f6460c7fe5a575503e3197b0 100644 (file)
@@ -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;
 }