11/* Minimal 'stat' emulation: tells directories from files and
22 gives length and mtime.
33 Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
4+ Updated to give more info, August 1994.
45*/
56
6- #include "stat .h"
7+ #include "macstat .h"
78#include "macdefs.h"
89
910/* Bits in ioFlAttrib: */
1011#define LOCKBIT (1<<0) /* File locked */
1112#define DIRBIT (1<<4) /* It's a directory */
1213
1314int
14- stat (path , buf )
15+ macstat (path , buf )
1516 char * path ;
16- struct stat * buf ;
17+ struct macstat * buf ;
1718{
1819 union {
1920 DirInfo d ;
@@ -23,35 +24,42 @@ stat(path, buf)
2324 char name [256 ];
2425 short err ;
2526
26- pb .d .ioNamePtr = (unsigned char * )c2pstr (strcpy (name , 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 */
27+ pb .d .ioNamePtr = (unsigned char * )c2pstr (strcpy (name , path ));
28+ pb .d .ioVRefNum = 0 ;
29+ pb .d .ioFDirIndex = 0 ;
30+ pb .d .ioDrDirID = 0 ;
31+ pb .f .ioFVersNum = 0 ; /* Fix found by Timo! See Tech Note 102 */
3132 if (hfsrunning ())
32- err = PBGetCatInfo ((CInfoPBPtr )& pb , FALSE);
33+ err = PBGetCatInfo ((CInfoPBPtr )& pb , FALSE);
3334 else
34- err = PBGetFInfo ((ParmBlkPtr )& pb , FALSE);
35+ err = PBGetFInfo ((ParmBlkPtr )& pb , FALSE);
3536 if (err != noErr ) {
3637 errno = ENOENT ;
3738 return -1 ;
3839 }
3940 if (pb .d .ioFlAttrib & LOCKBIT )
40- buf -> st_mode = 0444 ;
41+ buf -> st_mode = 0444 ;
4142 else
42- buf -> st_mode = 0666 ;
43+ buf -> st_mode = 0666 ;
4344 if (pb .d .ioFlAttrib & DIRBIT ) {
4445 buf -> st_mode |= 0111 | S_IFDIR ;
45- buf -> st_size = pb .d .ioDrNmFls ;
46- buf -> st_rsize = 0 ;
46+ buf -> st_size = pb .d .ioDrNmFls ;
47+ buf -> st_rsize = 0 ;
4748 }
4849 else {
4950 buf -> st_mode |= S_IFREG ;
5051 if (pb .f .ioFlFndrInfo .fdType == 'APPL' )
5152 buf -> st_mode |= 0111 ;
52- buf -> st_size = pb .f .ioFlLgLen ;
53- buf -> st_rsize = pb .f .ioFlRLgLen ;
5453 }
55- buf -> st_mtime = pb .f .ioFlMdDat - TIMEDIFF ;
54+ buf -> st_ino = pb .hf .ioDirID ;
55+ buf -> st_nlink = 1 ;
56+ buf -> st_uid = 1 ;
57+ buf -> st_gid = 1 ;
58+ buf -> st_size = pb .f .ioFlLgLen ;
59+ buf -> st_mtime = buf -> st_atime = pb .f .ioFlMdDat ;
60+ buf -> st_ctime = pb .f .ioFlCrDat ;
61+ buf -> st_rsize = pb .f .ioFlRLgLen ;
62+ * (unsigned long * )buf -> st_type = pb .f .ioFlFndrInfo .fdType ;
63+ * (unsigned long * )buf -> st_creator = pb .f .ioFlFndrInfo .fdCreator ;
5664 return 0 ;
5765}
0 commit comments