1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/*
Copyright (c) 1990-2003 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
macstat.c
* This file provides a unix like file-stat routine
* for V7 Unix systems that don't have such procedures.
*
*
---------------------------------------------------------------------------*/
/*****************************************************************************/
/* Includes */
/*****************************************************************************/
#include <string.h>
#include <stdio.h>
#include <sound.h>
#define UNZIP_INTERNAL
#include "unzip.h"
#include "macstat.h"
#include "helpers.h"
#include "pathname.h"
#include "macstuff.h"
#include "mactime.h"
/*****************************************************************************/
/* Global Vars */
/*****************************************************************************/
extern int errno;
extern MACINFO newExtraField; /* contains all extra-field data */
extern short MacZipMode;
/*****************************************************************************/
/* Prototypes */
/*****************************************************************************/
/*****************************************************************************/
/* Functions */
/*****************************************************************************/
int UZmacstat(const char *path, struct stat *buf)
{
Boolean isDirectory;
long dirID;
char fullpath[NAME_MAX], UnmangledPath[NAME_MAX];
CInfoPBRec fpb;
HVolumeParam vpb;
FSSpec fileSpec;
OSErr err, err2;
short CurrentFork;
AssertStr(path,path)
Assert_it(buf,"","")
memset(buf, 0, sizeof(struct stat)); /* zero out all fields */
RfDfFilen2Real(UnmangledPath, path, MacZipMode,
(newExtraField.flags & EB_M3_FL_NOCHANGE), &CurrentFork);
GetCompletePath(fullpath, path, &fileSpec, &err);
err2 = PrintUserHFSerr((err != -43) && (err != 0) && (err != -120),
err, path);
printerr("GetCompletePath:", err2, err2, __LINE__, __FILE__, path);
if (err != noErr) {
errno = err;
return -1;
}
/*
* Fill the fpb & vpb struct up with info about file or directory.
*/
FSpGetDirectoryID(&fileSpec, &dirID, &isDirectory);
vpb.ioVRefNum = fpb.hFileInfo.ioVRefNum = fileSpec.vRefNum;
vpb.ioNamePtr = fpb.hFileInfo.ioNamePtr = fileSpec.name;
if (isDirectory) {
fpb.hFileInfo.ioDirID = fileSpec.parID;
} else {
fpb.hFileInfo.ioDirID = dirID;
}
fpb.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfo(&fpb, false);
if (err == noErr) {
vpb.ioVolIndex = 0;
err = PBHGetVInfoSync((HParmBlkPtr)&vpb);
if (err == noErr && buf != NULL) {
/*
* Files are always readable by everyone.
*/
buf->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
/*
* Use the Volume Info & File Info to fill out stat buf.
*/
if (fpb.hFileInfo.ioFlAttrib & 0x10) {
buf->st_mode |= S_IFDIR;
buf->st_nlink = 2;
} else {
buf->st_nlink = 1;
if (fpb.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000) {
buf->st_mode |= S_IFLNK;
} else {
buf->st_mode |= S_IFREG;
}
}
if ((fpb.hFileInfo.ioFlAttrib & 0x10) ||
(fpb.hFileInfo.ioFlFndrInfo.fdType == 'APPL')) {
/*
* Directories and applications are executable by everyone.
*/
buf->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH;
}
if ((fpb.hFileInfo.ioFlAttrib & 0x01) == 0) {
/*
* If not locked, then everyone has write acces.
*/
buf->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
}
buf->st_ino = fpb.hFileInfo.ioDirID;
buf->st_dev = fpb.hFileInfo.ioVRefNum;
buf->st_uid = -1;
buf->st_gid = -1;
buf->st_rdev = 0;
if (CurrentFork == ResourceFork)
buf->st_size = fpb.hFileInfo.ioFlRLgLen;
else
buf->st_size = fpb.hFileInfo.ioFlLgLen;
buf->st_blksize = vpb.ioVAlBlkSiz;
buf->st_blocks = (buf->st_size + buf->st_blksize - 1)
/ buf->st_blksize;
/*
* The times returned by the Mac file system are in the
* local time zone. We convert them to GMT so that the
* epoch starts from GMT. This is also consistent with
* what is returned from "clock seconds".
*/
buf->st_mtime = MacFtime2UnixFtime(fpb.hFileInfo.ioFlMdDat);
buf->st_ctime = MacFtime2UnixFtime(fpb.hFileInfo.ioFlCrDat);
buf->st_atime = buf->st_ctime; /* best guess */
#ifdef DEBUG_TIME
{
struct tm *tp = localtime(&buf->st_mtime);
printf(
"\nUZmacstat: local buf->st_mtime is %ld = %d/%2d/%2d %2d:%2d:%2d",
buf->st_mtime, tp->tm_year, tp->tm_mon+1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec);
tp = gmtime(&buf->st_mtime);
printf(
"\nUZmacstat: UTC buf->st_mtime is %ld = %d/%2d/%2d %2d:%2d:%2d\n",
buf->st_mtime, tp->tm_year, tp->tm_mon+1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec);
}
#endif /* DEBUG_TIME */
}
}
if (err != noErr) {
errno = err;
}
return (err == noErr ? 0 : -1);
}
|