Added ref to Misc/NEWS file; added hint to run regen script on Linux.
[python/dscho.git] / Mac / Compat / macstat.c
bloba1265afbd7fcb53fe5ce8b2d69504f917e71f168
1 /* Minimal 'stat' emulation: tells directories from files and
2 gives length and mtime.
3 Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
4 Updated to give more info, August 1994.
5 */
7 #include "macstat.h"
8 #include "macdefs.h"
10 /* Bits in ioFlAttrib: */
11 #define LOCKBIT (1<<0) /* File locked */
12 #define DIRBIT (1<<4) /* It's a directory */
14 int
15 macstat(path, buf)
16 char *path;
17 struct macstat *buf;
19 union {
20 DirInfo d;
21 FileParam f;
22 HFileInfo hf;
23 } pb;
24 short err;
26 pb.d.ioNamePtr = (unsigned char *)Pstring(path);
27 pb.d.ioVRefNum = 0;
28 pb.d.ioFDirIndex = 0;
29 pb.d.ioDrDirID = 0;
30 pb.f.ioFVersNum = 0; /* Fix found by Timo! See Tech Note 102 */
31 if (hfsrunning())
32 err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
33 else
34 err = PBGetFInfo((ParmBlkPtr)&pb, FALSE);
35 if (err != noErr) {
36 errno = ENOENT;
37 return -1;
39 if (pb.d.ioFlAttrib & LOCKBIT)
40 buf->st_mode = 0444;
41 else
42 buf->st_mode = 0666;
43 if (pb.d.ioFlAttrib & DIRBIT) {
44 buf->st_mode |= 0111 | S_IFDIR;
45 buf->st_size = pb.d.ioDrNmFls;
46 buf->st_rsize = 0;
48 else {
49 buf->st_mode |= S_IFREG;
50 if (pb.f.ioFlFndrInfo.fdType == 'APPL')
51 buf->st_mode |= 0111;
53 buf->st_ino = pb.hf.ioDirID;
54 buf->st_nlink = 1;
55 buf->st_uid = 1;
56 buf->st_gid = 1;
57 buf->st_size = (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlLgLen;
58 buf->st_mtime = buf->st_atime = pb.f.ioFlMdDat;
59 buf->st_ctime = pb.f.ioFlCrDat;
60 buf->st_rsize = (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlRLgLen;
61 *(unsigned long *)buf->st_type =
62 (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlFndrInfo.fdType;
63 *(unsigned long *)buf->st_creator =
64 (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlFndrInfo.fdCreator;
65 return 0;