2 * Macintosh version of UNIX directory access package
3 * (opendir, readdir, closedir).
4 * Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
13 * Open a directory. This means calling PBOpenWD.
14 * The value returned is always the address of opened, or NULL.
15 * (I have as yet no use for multiple open directories; this could
16 * be implemented by allocating memory dynamically.)
23 #if TARGET_API_MAC_CARBON
29 if (opened
.nextfile
!= 0) {
31 return NULL
; /* A directory is already open. */
34 c2pstrcpy(ppath
, path
);
35 if ( ppath
[plen
] != ':' )
39 if( (err
= FSMakeFSSpec(0, 0, ppath
, &fss
)) < 0 && err
!= fnfErr
) {
43 opened
.dirid
= fss
.parID
;
44 opened
.vrefnum
= fss
.vRefNum
;
55 if (opened
.nextfile
!= 0) {
57 return NULL
; /* A directory is already open. */
59 strncpy(ppath
+1, path
, ppath
[0]= strlen(path
));
60 pb
.d
.ioNamePtr
= (unsigned char *)ppath
;
64 err
= PBOpenWD((WDPBPtr
)&pb
, 0);
69 opened
.dirid
= pb
.d
.ioVRefNum
;
83 #if TARGET_API_MAC_CARBON
88 pb
.ioVRefNum
= dirp
->dirid
;
89 (void) PBCloseWD(&pb
, 0);
96 * Read the next directory entry.
109 static struct dirent dir
;
112 pb
.d
.ioNamePtr
= (unsigned char *)dir
.d_name
;
113 #if TARGET_API_MAC_CARBON
114 pb
.d
.ioVRefNum
= dp
->vrefnum
;
115 pb
.d
.ioDrDirID
= dp
->dirid
;
117 pb
.d
.ioVRefNum
= dp
->dirid
;
120 pb
.d
.ioFDirIndex
= dp
->nextfile
++;
121 err
= PBGetCatInfo((CInfoPBPtr
)&pb
, 0);
126 #if TARGET_API_MAC_CARBON
127 p2cstrcpy(dir
.d_name
, (StringPtr
)dir
.d_name
);
129 (void) p2cstr((unsigned char *)dir
.d_name
);