Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b44ba5

Browse files
committed
Revived various of the compatability routines and made them Carbon-compliant. This is needed because the initial carbon-python does not use GUSI.
1 parent a04b24b commit 2b44ba5

4 files changed

Lines changed: 61 additions & 25 deletions

File tree

Mac/Compat/dirent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define DIR struct _dir
1010

1111
struct _dir {
12+
short vrefnum;
1213
long dirid;
1314
int nextfile;
1415
};

Mac/Compat/getwd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ getwd(cwd)
5959
sprintf(cwd, "I/O error %d in PBHGetVolSync", err);
6060
return NULL;
6161
}
62+
#ifdef TARGET_API_MAC_CARBON
63+
p2cstrcpy(cwd, (StringPtr)cwd);
64+
ecwd = strchr(cwd, EOS);
65+
#else
6266
ecwd= strchr((const char *)p2cstr((unsigned char*)cwd), EOS);
67+
#endif
6368
ebuf= buf;
6469
*ebuf = EOS;
6570

6671
/* Next, if at least we're running HFS, walk up the path. */
6772

68-
if (hfsrunning()) {
73+
{
6974
long dirid= pb.w.ioWDDirID;
7075
pb.d.ioVRefNum= pb.w.ioWDVRefNum;
7176
while (dirid != ROOTID) {
@@ -78,7 +83,12 @@ getwd(cwd)
7883
return NULL;
7984
}
8085
dirid= pb.d.ioDrParID;
86+
#ifdef TARGET_API_MAC_CARBON
87+
p2cstrcpy(ebuf, (StringPtr)ebuf);
88+
ebuf += strlen(ebuf);
89+
#else
8190
ebuf += strlen((const char *)p2cstr((unsigned char *)ebuf));
91+
#endif
8292
/* Should check for buf overflow */
8393
}
8494
}

Mac/Compat/macstat.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ macstat(path, buf)
2828
pb.d.ioFDirIndex = 0;
2929
pb.d.ioDrDirID = 0;
3030
pb.f.ioFVersNum = 0; /* Fix found by Timo! See Tech Note 102 */
31-
if (hfsrunning())
32-
err = PBGetCatInfoSync((CInfoPBPtr)&pb);
33-
else
34-
err = PBGetFInfoSync((ParmBlkPtr)&pb);
31+
err = PBGetCatInfoSync((CInfoPBPtr)&pb);
3532
if (err != noErr) {
3633
errno = ENOENT;
3734
return -1;

Mac/Compat/opendir.c

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ DIR *
2020
opendir(path)
2121
char *path;
2222
{
23+
#ifdef TARGET_API_MAC_CARBON
24+
Str255 ppath;
25+
FSSpec fss;
26+
int plen;
27+
OSErr err;
28+
29+
if (opened.nextfile != 0) {
30+
errno = EBUSY;
31+
return NULL; /* A directory is already open. */
32+
}
33+
plen = strlen(path);
34+
c2pstrcpy(ppath, path);
35+
if ( ppath[plen] != ':' )
36+
ppath[++plen] = ':';
37+
ppath[++plen] = 'x';
38+
ppath[0] = plen;
39+
if( (err = FSMakeFSSpec(0, 0, ppath, &fss)) < 0 && err != fnfErr ) {
40+
errno = EIO;
41+
return NULL;
42+
}
43+
opened.dirid = fss.parID;
44+
opened.vrefnum = fss.vRefNum;
45+
opened.nextfile = 1;
46+
return &opened;
47+
#else
2348
union {
2449
WDPBRec d;
2550
VolumeParam v;
@@ -34,22 +59,17 @@ opendir(path)
3459
strncpy(ppath+1, path, ppath[0]= strlen(path));
3560
pb.d.ioNamePtr= (unsigned char *)ppath;
3661
pb.d.ioVRefNum= 0;
37-
if (hfsrunning()) {
38-
pb.d.ioWDProcID= 0;
39-
pb.d.ioWDDirID= 0;
40-
err= PBOpenWD((WDPBPtr)&pb, 0);
41-
}
42-
else {
43-
pb.v.ioVolIndex= 0;
44-
err= PBGetVInfo((ParmBlkPtr)&pb, 0);
45-
}
62+
pb.d.ioWDProcID= 0;
63+
pb.d.ioWDDirID= 0;
64+
err= PBOpenWD((WDPBPtr)&pb, 0);
4665
if (err != noErr) {
4766
errno = ENOENT;
4867
return NULL;
4968
}
5069
opened.dirid= pb.d.ioVRefNum;
5170
opened.nextfile= 1;
5271
return &opened;
72+
#endif
5373
}
5474

5575
/*
@@ -60,14 +80,16 @@ void
6080
closedir(dirp)
6181
DIR *dirp;
6282
{
63-
if (hfsrunning()) {
64-
WDPBRec pb;
65-
66-
pb.ioVRefNum= dirp->dirid;
67-
(void) PBCloseWD(&pb, 0);
68-
}
83+
#ifdef TARGET_API_MAC_CARBON
84+
dirp->nextfile = 0;
85+
#else
86+
WDPBRec pb;
87+
88+
pb.ioVRefNum= dirp->dirid;
89+
(void) PBCloseWD(&pb, 0);
6990
dirp->dirid= 0;
7091
dirp->nextfile= 0;
92+
#endif
7193
}
7294

7395
/*
@@ -88,17 +110,23 @@ readdir(dp)
88110

89111
dir.d_name[0]= 0;
90112
pb.d.ioNamePtr= (unsigned char *)dir.d_name;
113+
#ifdef TARGET_API_MAC_CARBON
114+
pb.d.ioVRefNum= dp->vrefnum;
115+
pb.d.ioDrDirID= dp->dirid;
116+
#else
91117
pb.d.ioVRefNum= dp->dirid;
92-
pb.d.ioFDirIndex= dp->nextfile++;
93118
pb.d.ioDrDirID= 0;
94-
if (hfsrunning())
95-
err= PBGetCatInfo((CInfoPBPtr)&pb, 0);
96-
else
97-
err= PBGetFInfo((ParmBlkPtr)&pb, 0);
119+
#endif
120+
pb.d.ioFDirIndex= dp->nextfile++;
121+
err= PBGetCatInfo((CInfoPBPtr)&pb, 0);
98122
if (err != noErr) {
99123
errno = EIO;
100124
return NULL;
101125
}
126+
#ifdef TARGET_API_MAC_CARBON
127+
p2cstrcpy(dir.d_name, (StringPtr)dir.d_name);
128+
#else
102129
(void) p2cstr((unsigned char *)dir.d_name);
130+
#endif
103131
return &dir;
104132
}

0 commit comments

Comments
 (0)