annotate Mac/Compat/macstat.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents d41eee6d2ff7
children 16155989fa93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* Minimal 'stat' emulation: tells directories from files and
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 gives length and mtime.
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
4 Updated to give more info, August 1994.
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 */
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
7 #include "macstat.h"
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include "macdefs.h"
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 /* Bits in ioFlAttrib: */
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #define LOCKBIT (1<<0) /* File locked */
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #define DIRBIT (1<<4) /* It's a directory */
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 int
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
15 macstat(path, buf)
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 char *path;
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
17 struct macstat *buf;
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 {
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 union {
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 DirInfo d;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 FileParam f;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 HFileInfo hf;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 } pb;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 short err;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
2177
9f500a34c355 Some of these were overwriting their argument with a pascal
Jack Jansen <jack.jansen@cwi.nl>
parents: 1822
diff changeset
26 pb.d.ioNamePtr = (unsigned char *)Pstring(path);
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
27 pb.d.ioVRefNum = 0;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
28 pb.d.ioFDirIndex = 0;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
29 pb.d.ioDrDirID = 0;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
30 pb.f.ioFVersNum = 0; /* Fix found by Timo! See Tech Note 102 */
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 if (hfsrunning())
5267
d41eee6d2ff7 Fixed for compiling without OLDROUTINENAMES and OLDROUTINELOCATIONS
Jack Jansen <jack.jansen@cwi.nl>
parents: 2928
diff changeset
32 err = PBGetCatInfoSync((CInfoPBPtr)&pb);
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 else
5267
d41eee6d2ff7 Fixed for compiling without OLDROUTINENAMES and OLDROUTINELOCATIONS
Jack Jansen <jack.jansen@cwi.nl>
parents: 2928
diff changeset
34 err = PBGetFInfoSync((ParmBlkPtr)&pb);
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 if (err != noErr) {
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 errno = ENOENT;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 return -1;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 }
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 if (pb.d.ioFlAttrib & LOCKBIT)
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
40 buf->st_mode = 0444;
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 else
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
42 buf->st_mode = 0666;
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 if (pb.d.ioFlAttrib & DIRBIT) {
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 buf->st_mode |= 0111 | S_IFDIR;
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
45 buf->st_size = pb.d.ioDrNmFls;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
46 buf->st_rsize = 0;
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 }
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 else {
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 buf->st_mode |= S_IFREG;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 if (pb.f.ioFlFndrInfo.fdType == 'APPL')
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 buf->st_mode |= 0111;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 }
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
53 buf->st_ino = pb.hf.ioDirID;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
54 buf->st_nlink = 1;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
55 buf->st_uid = 1;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
56 buf->st_gid = 1;
2928
792e39dfe216 set some fields to zero for directories
Guido van Rossum <guido@python.org>
parents: 2177
diff changeset
57 buf->st_size = (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlLgLen;
1822
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
58 buf->st_mtime = buf->st_atime = pb.f.ioFlMdDat;
76d0f2b3b9ee Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents: 1821
diff changeset
59 buf->st_ctime = pb.f.ioFlCrDat;
2928
792e39dfe216 set some fields to zero for directories
Guido van Rossum <guido@python.org>
parents: 2177
diff changeset
60 buf->st_rsize = (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlRLgLen;
792e39dfe216 set some fields to zero for directories
Guido van Rossum <guido@python.org>
parents: 2177
diff changeset
61 *(unsigned long *)buf->st_type =
792e39dfe216 set some fields to zero for directories
Guido van Rossum <guido@python.org>
parents: 2177
diff changeset
62 (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlFndrInfo.fdType;
792e39dfe216 set some fields to zero for directories
Guido van Rossum <guido@python.org>
parents: 2177
diff changeset
63 *(unsigned long *)buf->st_creator =
792e39dfe216 set some fields to zero for directories
Guido van Rossum <guido@python.org>
parents: 2177
diff changeset
64 (buf->st_mode & S_IFDIR) ? 0 : pb.f.ioFlFndrInfo.fdCreator;
1821
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 return 0;
40594f80ab3c Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 }