home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include "crtlocal.h"
-
- static int macstat(StringPtr path, struct stat *buf, short nVRefNum, long lDirID )
- {
- CInfoPBRec cPB;
- bzero(buf, sizeof(struct stat));
- cPB.hFileInfo.ioNamePtr = path;
- cPB.hFileInfo.ioVRefNum = nVRefNum;
- cPB.hFileInfo.ioDirID = lDirID;
- cPB.hFileInfo.ioFDirIndex = 0;
-
- if (PBGetCatInfoSync(&cPB))
- {
- return -1;
- }
-
- /* Type of file: directory or regular file + access */
-
- if (cPB.hFileInfo.ioFlAttrib & ioDirMask)
- {
- buf->st_ino = cPB.dirInfo.ioDrDirID;
- buf->st_mode = S_IFDIR;
- }
- else
- {
- int siz = cPB.hFileInfo.ioFlClpSiz;
- if (!siz) siz = 8192;
- buf->st_blksize = siz;
- buf->st_blocks = (cPB.hFileInfo.ioFlPyLen+siz-1) / siz;
- buf->st_uid = cPB.hFileInfo.ioFlFndrInfo.fdCreator;
- buf->st_gid = cPB.hFileInfo.ioFlFndrInfo.fdType;
- buf->st_ino = cPB.hFileInfo.ioFRefNum;
- buf->st_size = cPB.hFileInfo.ioFlLgLen;
- buf->st_flags = cPB.hFileInfo.ioFlFndrInfo.fdFlags;
- buf->st_mode = S_IFREG;
- }
- buf->st_mode |= cPB.hFileInfo.ioFlAttrib & 0x01 ? S_IREAD : (S_IREAD | S_IWRITE);
- /* last access time, modification time and creation time(?) */
- buf->st_atime = buf->st_mtime = unixTime(cPB.hFileInfo.ioFlMdDat);
- buf->st_ctime = unixTime(cPB.hFileInfo.ioFlCrDat);
- buf->st_dev = (long)cPB.hFileInfo.ioVRefNum;
- buf->st_nlink = 1;
- return 0;
- }
-
- int fstat(int fd, struct stat *buf)
- {
- FCBPBRec pb;
- Str255 name;
- int refnum = crt_fd_tab[fd].fd;
- if (crt_fd_tab[fd].flags & O_PIPE)
- {
- bzero(buf, sizeof(struct stat));
- buf->st_mode = S_IFIFO;
- buf->st_blksize = 8192;
- return 0;
- }
- mysleep(1);
- pb.ioRefNum = refnum;
- pb.ioFCBIndx = 0;
- pb.ioCompletion = 0;
- pb.ioVRefNum = crt_ioVRefNum;
- pb.ioNamePtr = (StringPtr) name;
- PBGetFCBInfoSync(&pb);
- return macstat(name, buf, pb.ioFCBVRefNum, pb.ioFCBParID);
- }
-
- int stat(const char *name, struct stat *buf)
- {
- StringPtr s = cnv_unix_name(name);
- return macstat(s, buf, crt_ioVRefNum, 0);
- }
-