Пример #1
0
pascal	OSErr	FSpSetFInfoCompat(const FSSpec *spec,
                                  const FInfo *fndrInfo)
{
#if !__MACOSSEVENORLATER
    if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() )
    {
        OSErr			result;
        HParamBlockRec	pb;

        pb.fileParam.ioVRefNum = spec->vRefNum;
        pb.fileParam.ioDirID = spec->parID;
        pb.fileParam.ioNamePtr = (StringPtr) &(spec->name);
        pb.fileParam.ioFVersNum = 0;
        pb.fileParam.ioFDirIndex = 0;
        result = PBHGetFInfoSync(&pb);
        if ( result == noErr )
        {
            pb.fileParam.ioFlFndrInfo = *fndrInfo;
            pb.fileParam.ioDirID = spec->parID;
            result = PBHSetFInfoSync(&pb);
        }
        return ( result );
    }
    else
#endif	/* !__MACOSSEVENORLATER */
    {
        return ( FSpSetFInfo(spec, fndrInfo) );
    }
}
Пример #2
0
/*
 *  int open(const char *path, int oflag)
 *
 *      Opens a file stream.
 */
int my_open(char *path, int oflag)
{
    FSSpec          spec;
    char            permission;
    HParamBlockRec  hpb;
    OSErr           err, errno;
    Boolean targetIsFolder, wasAliased;

    AssertStr(path,path)

    /* Setup permission */
    if ((oflag & 0x03) == O_RDWR)
        permission = fsRdWrPerm;
    else
        permission = (oflag & O_RDONLY) ? fsRdPerm : 0 + (oflag & O_WRONLY) ? fsWrPerm : 0;

        FSpLocationFromFullPath(strlen(path),path, &spec);
        if ((oflag & (O_ALIAS | O_NRESOLVE)) == 0)
            ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
        hpb.fileParam.ioNamePtr = spec.name;
        hpb.fileParam.ioVRefNum = spec.vRefNum;
        hpb.fileParam.ioDirID = spec.parID;
        hpb.ioParam.ioPermssn = permission;

        if (oflag & O_RSRC)         /* open the resource fork of the file */
            err = PBHOpenRFSync(&hpb);
        else                        /* open the data fork of the file */
            err = PBHOpenDFSync(&hpb);

    if ((err == fnfErr) && (oflag & O_CREAT)) {
        hpb.fileParam.ioFlVersNum = 0;
        err = PBHCreateSync(&hpb);
        if (err == noErr) {
            /* Set the finder info */
            unsigned long secs;
            unsigned long isbinary = oflag & O_BINARY;

            hpb.fileParam.ioFlFndrInfo.fdType = '\?\?\?\?';
            hpb.fileParam.ioFlFndrInfo.fdCreator = '\?\?\?\?';
            hpb.fileParam.ioFlFndrInfo.fdFlags = 0;
            if (oflag & O_ALIAS)        /* set the alias bit */
                hpb.fileParam.ioFlFndrInfo.fdFlags = kIsAlias;
            else                                        /* clear all flags */
                hpb.fileParam.ioFlFndrInfo.fdFlags = 0;

            GetDateTime(&secs);
            hpb.fileParam.ioFlCrDat = hpb.fileParam.ioFlMdDat = secs;
            PBHSetFInfoSync(&hpb);
        }

        if (err && (err != dupFNErr)) {
            errno = err; return -1;
        }

            if (oflag & O_RSRC)         /* open the resource fork of the file */
                err = PBHOpenRFSync(&hpb);
            else                        /* open the data fork of the file */
                err = PBHOpenDFSync(&hpb);
    }

    if (err && (err != dupFNErr) && (err != opWrErr)) {
        errno = err; return -1;
    }

    if (oflag & O_TRUNC) {
        IOParam pb;

        pb.ioRefNum = hpb.ioParam.ioRefNum;
        pb.ioMisc = 0L;
        err = PBSetEOFSync((ParmBlkPtr)&pb);
        if (err != noErr) {
            errno = err; return -1;
        }
    }

    if (oflag & O_APPEND) lseek(hpb.ioParam.ioRefNum,0,SEEK_END);

    return (hpb.ioParam.ioRefNum);
}