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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/*
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 1999-Oct-05 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
unixlike.c
Macintosh-specific routines to emulate unixfunctions.
---------------------------------------------------------------------------*/
/*****************************************************************************/
/* Includes */
/*****************************************************************************/
#include "zip.h"
#include <string.h>
#include <stdio.h>
#include <sound.h>
#include "unixlike.h"
#include "helpers.h"
#include "pathname.h"
#include "macstuff.h"
#include "macglob.h"
#include "mactime.h"
/*****************************************************************************/
/* Global Vars */
/*****************************************************************************/
extern MacZipGlobals MacZip;
extern int errno;
/*****************************************************************************/
/* Prototypes */
/*****************************************************************************/
/*****************************************************************************/
/* Functions */
/*****************************************************************************/
/*
*----------------------------------------------------------------------
*
* MacStat --
*
* This function replaces the library version of stat. The stat
* function provided by most Mac compiliers is rather broken and
* incomplete.
*
* Results:
* See stat documentation.
*
* Side effects:
* See stat documentation.
*
*----------------------------------------------------------------------
*/
int Zmacstat(const char *Fname, struct stat *buf)
{
OSErr err, rc;
short fullPathLength;
Handle hFullPath;
char path[NAME_MAX], path2[NAME_MAX];
HVolumeParam vpb;
static unsigned long count_of_files = 0;
AssertStr(Fname,Fname)
Assert_it(buf,"","")
UserStop();
memset(buf, 0, sizeof(buf)); /* zero out all fields */
RfDfFilen2Real(path2, Fname, MacZip.MacZipMode, MacZip.DataForkOnly,
&MacZip.CurrentFork);
GetCompletePath(path, path2, &MacZip.fileSpec, &err);
err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
printerr("GetCompletePath:", err, err, __LINE__, __FILE__, path);
if (err != noErr) {
errno = err;
return -1;
}
/* Collect here some more information, it's not related to Macstat.
(note: filespec gets changed later in this function) */
/* clear string-buffer */
memset(MacZip.FullPath, 0x00, sizeof(MacZip.FullPath));
rc = FSpGetFullPath(&MacZip.fileSpec, &fullPathLength, &hFullPath);
strncpy(MacZip.FullPath, *hFullPath, fullPathLength);
DisposeHandle(hFullPath); /* we don't need it any more */
/* Collect some more information not related to Macstat */
/*
* Fill the fpb & vpb struct up with info about file or directory.
*/
FSpGetDirectoryID(&MacZip.fileSpec, &MacZip.dirID, &MacZip.isDirectory);
vpb.ioVRefNum = MacZip.fpb.hFileInfo.ioVRefNum = MacZip.fileSpec.vRefNum;
vpb.ioNamePtr = MacZip.fpb.hFileInfo.ioNamePtr = MacZip.fileSpec.name;
if (MacZip.isDirectory) {
MacZip.fpb.hFileInfo.ioDirID = MacZip.fileSpec.parID;
/*
* Directories are executable by everyone.
*/
buf->st_mode |= UNX_IXUSR | UNX_IXGRP | UNX_IXOTH | UNX_IFDIR;
} else {
MacZip.fpb.hFileInfo.ioDirID = MacZip.dirID;
}
MacZip.fpb.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync((CInfoPBPtr)&MacZip.fpb);
if (err == noErr) {
vpb.ioVolIndex = 0;
err = PBHGetVInfoSync((HParmBlkPtr)&vpb);
if (err == noErr && buf != NULL) {
/*
* Files are always readable by everyone.
*/
buf->st_mode |= UNX_IRUSR | UNX_IRGRP | UNX_IROTH;
/*
* Use the Volume Info & File Info to fill out stat buf.
*/
if (MacZip.fpb.hFileInfo.ioFlAttrib & 0x10) {
buf->st_mode |= UNX_IFDIR;
buf->st_nlink = 2;
} else {
buf->st_nlink = 1;
if (MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000) {
buf->st_mode |= UNX_IFLNK;
} else {
buf->st_mode |= UNX_IFREG;
}
}
if (MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType == 'APPL') {
/*
* Applications are executable by everyone.
*/
buf->st_mode |= UNX_IXUSR | UNX_IXGRP | UNX_IXOTH;
}
if ((MacZip.fpb.hFileInfo.ioFlAttrib & 0x01) == 0){
/*
* If not locked, then everyone has write acces.
*/
buf->st_mode |= UNX_IWUSR | UNX_IWGRP | UNX_IWOTH;
}
buf->st_ino = MacZip.fpb.hFileInfo.ioDirID;
buf->st_dev = MacZip.fpb.hFileInfo.ioVRefNum;
buf->st_uid = -1;
buf->st_gid = -1;
buf->st_rdev = 0;
if (MacZip.CurrentFork == ResourceFork)
buf->st_size = MacZip.fpb.hFileInfo.ioFlRLgLen;
else
buf->st_size = MacZip.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".
*/
if (!MacZip.isDirectory) {
MacZip.CreatDate = MacZip.fpb.hFileInfo.ioFlCrDat;
MacZip.ModDate = MacZip.fpb.hFileInfo.ioFlMdDat;
MacZip.BackDate = MacZip.fpb.hFileInfo.ioFlBkDat;
} else {
MacZip.CreatDate = MacZip.fpb.dirInfo.ioDrCrDat;
MacZip.ModDate = MacZip.fpb.dirInfo.ioDrMdDat;
MacZip.BackDate = MacZip.fpb.dirInfo.ioDrBkDat;
}
#ifdef IZ_CHECK_TZ
if (!zp_tz_is_valid)
{
MacZip.HaveGMToffset = false;
MacZip.Md_UTCoffs = 0L;
MacZip.Cr_UTCoffs = 0L;
MacZip.Bk_UTCoffs = 0L;
}
else
#endif
{
/* Do not use GMT offsets when Md_UTCoffs calculation
* fails, since this time stamp is used for time
* comparisons in Zip and UnZip operations.
* We do not bother when GMT offset calculation fails for
* any other time stamp value. Instead we simply assume
* a default value of 0.
*/
MacZip.HaveGMToffset =
GetGMToffsetMac(MacZip.ModDate, &MacZip.Md_UTCoffs);
if (MacZip.HaveGMToffset) {
GetGMToffsetMac(MacZip.CreatDate, &MacZip.Cr_UTCoffs);
GetGMToffsetMac(MacZip.BackDate, &MacZip.Bk_UTCoffs);
} else {
MacZip.Cr_UTCoffs = 0L;
MacZip.Bk_UTCoffs = 0L;
}
}
#ifdef DEBUG_TIME
{
printf("\nZmacstat: MacZip.HaveGMToffset: %d",
MacZip.HaveGMToffset);
printf("\nZmacstat: Mac modif: %lu local -> UTOffset: %d",
MacZip.ModDate, MacZip.Md_UTCoffs);
printf("\nZmacstat: Mac creat: %lu local -> UTOffset: %d",
MacZip.CreatDate, MacZip.Cr_UTCoffs);
printf("\nZmacstat: Mac back: %lu local -> UTOffset: %d",
MacZip.BackDate, MacZip.Bk_UTCoffs);
}
#endif /* DEBUG_TIME */
buf->st_mtime = MacFtime2UnixFtime(MacZip.ModDate);
buf->st_ctime = MacFtime2UnixFtime(MacZip.CreatDate);
buf->st_atime = buf->st_mtime;
#ifdef DEBUG_TIME
{
printf("\nZmacstat: Unix modif: %lu UTC; Mac: %lu local",
buf->st_mtime, MacZip.ModDate);
printf("\nZmacstat: Unix creat: %lu UTC; Mac: %lu local\n",
buf->st_ctime, MacZip.CreatDate);
}
#endif /* DEBUG_TIME */
if (noisy)
{
if (MacZip.StatingProgress)
{
count_of_files++;
InformProgress(MacZip.RawCountOfItems, count_of_files );
}
else
count_of_files = 0;
}
}
}
if (err != noErr) {
errno = err;
}
MacZip.isMacStatValid = true;
return (err == noErr ? 0 : -1);
}
/*
*----------------------------------------------------------------------
*
* chmod --
*
* Results:
* See chmod documentation.
*
* Side effects:
* See chmod documentation.
*
*----------------------------------------------------------------------
*/
int chmod(char *path, int mode)
{
HParamBlockRec hpb;
OSErr err;
hpb.fileParam.ioNamePtr = C2PStr(path);
hpb.fileParam.ioVRefNum = 0;
hpb.fileParam.ioDirID = 0;
if (mode & 0200) {
err = PBHRstFLockSync(&hpb);
} else {
err = PBHSetFLockSync(&hpb);
}
if (err != noErr) {
errno = err;
return -1;
}
return 0;
}
|