Exemplo n.º 1
0
FILE *MacFopen(const char *path, const char *mode)
{
static char TruncPath[NAME_MAX];
OSErr   err = 0;

AssertStr(path,path)

            /* open zipfile or tempzip */
if (strcmp(zipfile,path) == 0)
    {
    GetCompletePath(MacZip.ZipFullPath,path,&MacZip.ZipFileSpec,&err);
    err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
    printerr("GetCompletePath:",err,err,__LINE__,__FILE__,path);
    if (CheckMountedVolumes(MacZip.ZipFullPath) > 1)
        DoWarnUserDupVol(MacZip.ZipFullPath);

    /* tempfile should appear in the same directory of the zipfile
       -> save path of zipfile */
    TruncFilename(TruncPath, MacZip.ZipFullPath);
    return fopen(MacZip.ZipFullPath, mode);
    }

if (strcmp(tempzip,path) == 0)
    {  /* add path of zipfile */
    sstrcat(TruncPath,tempzip);
    GetCompletePath(MacZip.TempZipFullPath,TruncPath,&MacZip.TempZipFileSpec,&err);
    err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
    printerr("GetCompletePath:",err,err,__LINE__,__FILE__,path);

    return fopen(MacZip.TempZipFullPath, mode);
    }

printerr("MacFopen:",err,err,__LINE__,__FILE__,path);
return NULL;
}
Exemplo n.º 2
0
char *getenv(const char *name)
{
FILE *fp;
char *LineStr = NULL;
EnviromentPair *Env1;
FSSpec spec;
OSErr err;

if (IgnoreEnvironment)
    return NULL;  /* user wants to ignore the environment vars */

if (name == NULL)
    return NULL;

GetCompletePath(CompletePath,"MacZip.Env",&spec,&err);

/* try open the file in the current folder */
fp = FSp_fopen(&spec,"r");
if (fp == NULL)
    { /* Okey, lets try open the file in the preference folder */
    FSpFindFolder_Name(
                   kOnSystemDisk,
                   kPreferencesFolderType,
                   kDontCreateFolder,
                   &spec,
                   "\pMacZip.Env");
    fp = FSp_fopen(&spec,"r");
    if (fp == NULL)
        {
        return NULL; /* there is no enviroment-file */
        }
    }
Exemplo n.º 3
0
DIR *opendir(char *dirName)
{
    int fullPath;
    unsigned pathLen;
    char *s;
    HParamBlockRec hPB;
    CInfoPBRec cPB;
    DIR *dPtr;
    OSErr err;
    FSSpec spec;
    char CompletePath[NAME_MAX];

    GetCompletePath(CompletePath, dirName, &spec, &err);
    printerr("GetCompletePath", err, err, __LINE__, __FILE__, dirName);

    if (dirName == NULL || *dirName == '\0' ||
        (pathLen = strlen(dirName)) >= 256) {
        errno = EINVAL;
        return NULL;
    }


    /* Get information about volume. */
    memset(&hPB, '\0', sizeof(hPB));

    if (((s = strchr(dirName, ':')) == NULL) || (*dirName == ':')) {
        fullPath = false;
    } else {
        *(s + 1) = '\0';
        hPB.volumeParam.ioVolIndex = -1;
        fullPath = true;
    }

    hPB.volumeParam.ioNamePtr = spec.name;

    err = PBHGetVInfoSync(&hPB);

    if ((err != noErr) || (hPB.volumeParam.ioVFSID != 0)) {
        errno = ENOENT;
        return NULL;
    }

    /* Get information about file. */

    memset(&cPB, '\0', sizeof(cPB));

    if (fullPath)
        cPB.hFileInfo.ioVRefNum = hPB.volumeParam.ioVRefNum;

    cPB.hFileInfo.ioNamePtr = spec.name;

    err = PBGetCatInfoSync(&cPB);

    if (err != noErr) {
        errno = (err == fnfErr) ? ENOENT : EIO;
        return NULL;
    }

    if (!(cPB.hFileInfo.ioFlAttrib & ioDirMask)) {
        errno = ENOTDIR;
        return NULL;
    }

    /* Get space for, and fill in, DIR structure. */

    if ((dPtr = (DIR *)malloc(sizeof(DIR))) == NULL) {
        return NULL;
    }

    dPtr->ioVRefNum = cPB.dirInfo.ioVRefNum;
    dPtr->ioDrDirID = cPB.dirInfo.ioDrDirID;
    dPtr->ioFDirIndex = 1;
    dPtr->flags = 0;

    return dPtr;
}
Exemplo n.º 4
0
int destroy(char *path)
{
static char lastpath[NAME_MAX];
static FSSpec  trashfolder;
static Boolean FirstCall = true;
static char Num = 0;
static Boolean  Immediate_File_Deletion = false;
char    currpath[NAME_MAX], *envptr;
FSSpec  fileToDelete;
OSErr   err;

/* init this function */
if ((path == NULL) ||
    (strlen(path) == 0))
    {
    FirstCall = true;
    Num = 0;
    return -1;
    }

UserStop();

RfDfFilen2Real(currpath, path, MacZip.MacZipMode,
                MacZip.DataForkOnly, &MacZip.CurrentFork);
GetCompletePath(currpath,currpath,&fileToDelete, &err);

if (FirstCall == true)
    {
    FirstCall = false;
    sstrcpy(lastpath,currpath);
    err = FSpFindFolder(fileToDelete.vRefNum, kTrashFolderType,
                      kDontCreateFolder,&trashfolder);
    printerr("FSpFindFolder:",err,err,__LINE__,__FILE__,path);

    envptr = getenv("Immediate_File_Deletion");
    if (!(envptr == (char *)NULL || *envptr == '\0'))
        {
        if (stricmp(envptr,"yes") == 0)
            Immediate_File_Deletion = true;
        else
            Immediate_File_Deletion = false;
        }

    if (Immediate_File_Deletion)
        {
        err = FSpDelete(&fileToDelete);
        return err;
        }

    err = CatMove (fileToDelete.vRefNum, fileToDelete.parID,
                   fileToDelete.name, trashfolder.parID, trashfolder.name);
    return err;
    }

if (strcmp(currpath,lastpath) == 0)
    {
    return 0; /* ignore, file is already deleted */
    }
else
    {

    if (Immediate_File_Deletion)
        {
        err = FSpDelete(&fileToDelete);
        sstrcpy(lastpath,path);
        return err;
        }

    err = CatMove (fileToDelete.vRefNum, fileToDelete.parID,
                   fileToDelete.name, trashfolder.parID, trashfolder.name);

    /* -48 = file is already existing so we have to rename it before
       moving the file */
    if (err == -48)
        {
        Num++;
        if (fileToDelete.name[0] >= 28) /* cut filename if to long */
            fileToDelete.name[0] = 28;
        P2CStr(fileToDelete.name);
        sprintf(currpath,"%s~%d",(char *)fileToDelete.name,Num);
        C2PStr(currpath);
        C2PStr((char *)fileToDelete.name);
        err = HRename (fileToDelete.vRefNum, fileToDelete.parID,
                       fileToDelete.name, (unsigned char *) currpath);
        err = CatMove (fileToDelete.vRefNum, fileToDelete.parID,
                       (unsigned char *) currpath, trashfolder.parID,
                       trashfolder.name);
        }
    }

sstrcpy(lastpath,currpath);
return err;
}
Exemplo n.º 5
0
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);
}