1994-08-26 06:09:48 -03:00
|
|
|
/* Minimal 'stat' emulation: tells directories from files and
|
|
|
|
gives length and mtime.
|
|
|
|
Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
|
1994-08-29 05:42:37 -03:00
|
|
|
Updated to give more info, August 1994.
|
1994-08-26 06:09:48 -03:00
|
|
|
*/
|
|
|
|
|
1994-08-29 05:42:37 -03:00
|
|
|
#include "macstat.h"
|
1994-08-26 06:09:48 -03:00
|
|
|
#include "macdefs.h"
|
|
|
|
|
|
|
|
/* Bits in ioFlAttrib: */
|
|
|
|
#define LOCKBIT (1<<0) /* File locked */
|
|
|
|
#define DIRBIT (1<<4) /* It's a directory */
|
|
|
|
|
|
|
|
int
|
1994-08-29 05:42:37 -03:00
|
|
|
macstat(path, buf)
|
1994-08-26 06:09:48 -03:00
|
|
|
char *path;
|
1994-08-29 05:42:37 -03:00
|
|
|
struct macstat *buf;
|
1994-08-26 06:09:48 -03:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
DirInfo d;
|
|
|
|
FileParam f;
|
|
|
|
HFileInfo hf;
|
|
|
|
} pb;
|
|
|
|
short err;
|
|
|
|
|
1995-01-18 09:55:41 -04:00
|
|
|
pb.d.ioNamePtr = (unsigned char *)Pstring(path);
|
1994-08-29 05:42:37 -03:00
|
|
|
pb.d.ioVRefNum = 0;
|
|
|
|
pb.d.ioFDirIndex = 0;
|
|
|
|
pb.d.ioDrDirID = 0;
|
|
|
|
pb.f.ioFVersNum = 0; /* Fix found by Timo! See Tech Note 102 */
|
1994-08-26 06:09:48 -03:00
|
|
|
if (hfsrunning())
|
1994-08-29 05:42:37 -03:00
|
|
|
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
|
1994-08-26 06:09:48 -03:00
|
|
|
else
|
1994-08-29 05:42:37 -03:00
|
|
|
err = PBGetFInfo((ParmBlkPtr)&pb, FALSE);
|
1994-08-26 06:09:48 -03:00
|
|
|
if (err != noErr) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (pb.d.ioFlAttrib & LOCKBIT)
|
1994-08-29 05:42:37 -03:00
|
|
|
buf->st_mode = 0444;
|
1994-08-26 06:09:48 -03:00
|
|
|
else
|
1994-08-29 05:42:37 -03:00
|
|
|
buf->st_mode = 0666;
|
1994-08-26 06:09:48 -03:00
|
|
|
if (pb.d.ioFlAttrib & DIRBIT) {
|
|
|
|
buf->st_mode |= 0111 | S_IFDIR;
|
1994-08-29 05:42:37 -03:00
|
|
|
buf->st_size = pb.d.ioDrNmFls;
|
|
|
|
buf->st_rsize = 0;
|
1994-08-26 06:09:48 -03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf->st_mode |= S_IFREG;
|
|
|
|
if (pb.f.ioFlFndrInfo.fdType == 'APPL')
|
|
|
|
buf->st_mode |= 0111;
|
|
|
|
}
|
1994-08-29 05:42:37 -03:00
|
|
|
buf->st_ino = pb.hf.ioDirID;
|
|
|
|
buf->st_nlink = 1;
|
|
|
|
buf->st_uid = 1;
|
|
|
|
buf->st_gid = 1;
|
|
|
|
buf->st_size = pb.f.ioFlLgLen;
|
|
|
|
buf->st_mtime = buf->st_atime = pb.f.ioFlMdDat;
|
|
|
|
buf->st_ctime = pb.f.ioFlCrDat;
|
|
|
|
buf->st_rsize = pb.f.ioFlRLgLen;
|
|
|
|
*(unsigned long *)buf->st_type = pb.f.ioFlFndrInfo.fdType;
|
|
|
|
*(unsigned long *)buf->st_creator = pb.f.ioFlFndrInfo.fdCreator;
|
1994-08-26 06:09:48 -03:00
|
|
|
return 0;
|
|
|
|
}
|