Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/macos/source/macstat.c view on Meta::CPAN
/*
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) {
( run in 0.789 second using v1.01-cache-2.11-cpan-437f7b0c052 )