예제 #1
0
파일: hsStream.cpp 프로젝트: branan/Plasma
uint32_t hsStream::GetSizeLeft()
{
    uint32_t ret = 0;
    if (GetPosition() > GetEOF())
    {
        hsThrow("Position is beyond EOF");
    }
    else
    {
        ret = GetEOF() - GetPosition();
    }

    return ret;
}
예제 #2
0
char * ReadDataFile (long * pBufferSize, FSSpec * pfsspecData)
{
	NavReplyRecord replyNav;
	NavTypeListHandle hTypeList = (NavTypeListHandle) NewHandleClear (sizeof (NavTypeList) + sizeof (OSType) * 1);
	AEKeyword theKeyword;
	DescType actualType;
	Size actualSize;
	OSStatus err = noErr;
    short fileRef;
    char * pFileBuffer;

	HLock ((Handle) hTypeList);
	(**hTypeList).osTypeCount = 2;
	(**hTypeList).osType[0] = 'TEXT';
	(**hTypeList).osType[1] = '????';

    // select sprite file
	err = NavChooseFile (NULL, &replyNav, NULL, NULL, NULL, NULL, hTypeList, NULL); 
	if ((err == noErr) && (replyNav.validRecord))
		err = AEGetNthPtr (&(replyNav.selection), 1, typeFSS, &theKeyword, &actualType,
						   pfsspecData, sizeof (FSSpec), &actualSize);
	NavDisposeReply (&replyNav);
	if (err != noErr)
		return false;
    FSpOpenDF(pfsspecData, fsRdPerm, &fileRef);
    GetEOF(fileRef, pBufferSize);
    pFileBuffer = (char *) NewPtrClear (*pBufferSize);
    FSRead (fileRef, pBufferSize, pFileBuffer);
    FSClose (fileRef);
	return pFileBuffer;
}
예제 #3
0
unsigned int
XMLMacCarbonFile::size()
{
    OSErr err = noErr;
    unsigned int len = 0;

    if (!mFileValid)
        ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetSize);

    if (gHasHFSPlusAPIs)
    {
        SInt64 bigLen = 0;
        err = FSGetForkSize(mFileRefNum, &bigLen);
        if (err == noErr)
            len = bigLen;
    }
    else
    {
        long longLen;
        err = GetEOF(mFileRefNum, &longLen);
        if (err == noErr)
            len = longLen;
    }

    if (err != noErr)
        ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetSize);

    return len;
}
예제 #4
0
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
{
    SInt16 ref = *((SInt16 *) opaque);
    SInt32 eofPos;
    BAIL_IF_MACRO(oserr(GetEOF(ref, &eofPos)) != noErr, NULL, -1);
    return((PHYSFS_sint64) eofPos);
} /* __PHYSFS_platformFileLength */
예제 #5
0
/* convert icns(icons for MacOS X) to IPIcon */
OSErr	XIconToIPIcon(const FSSpec *theFile,IPIconRec *ipIcon)
{
	OSErr	err;
	IconFamilyHandle	theIconFamily;
	short		refNum;
	long		count;
	
	if (isIconServicesAvailable)
	{
		/* open icns file */
		err=FSpOpenDF(theFile,fsRdPerm,&refNum);
		if (err!=noErr) return err;
		
		err=GetEOF(refNum,&count);
		if (err!=noErr)
		{
			FSClose(refNum);
			return err;
		}
		theIconFamily=(IconFamilyHandle)NewHandle(count);
		HLock((Handle)theIconFamily);
		err=FSRead(refNum,&count,*theIconFamily);
		HUnlock((Handle)theIconFamily);
		
		err=FSClose(refNum);
		
		/* convert IconFamily to IPIcon */
		err=IconFamilyToIPIcon(theIconFamily,ipIcon);
		
		DisposeHandle((Handle)theIconFamily);
		return err;
	}
	else
		return -1;
}
예제 #6
0
파일: macros.c 프로젝트: macssh/macssh
// RAB BetterTelnet 2.0b5
void parseNewMacros(NewMacroInfo *macrost, short fileRef)
{
	Handle macroHandle;
	Ptr macroPtr, pos;
	long macroLength, count, len;
	OSErr fileErr;
	short i, flag;

	fileErr = GetEOF(fileRef, &macroLength);
	macroLength -= 2; // compensate for !CR
	macroHandle = myNewHandle(macroLength);

	if (!macroHandle) { // memory error?
		disposemacros(macrost);
		setupNewMacros(macrost); // this better work, or we crash hard
		return;
	}

	HLock(macroHandle);
	macroPtr = *macroHandle;
	count = macroLength;
	FSRead(fileRef, &count, macroPtr);

	parseNewMacros2(macrost, macroHandle);
}
예제 #7
0
static toff_t
_tiffSeekProc(thandle_t fd, toff_t off, int whence)
{
	long fpos, size;

	if (GetEOF((short) fd, &size) != noErr)
		return EOF;
	(void) GetFPos((short) fd, &fpos);

	switch (whence) {
	case SEEK_CUR:
		if (off + fpos > size)
			SetEOF((short) fd, off + fpos);
		if (SetFPos((short) fd, fsFromMark, off) != noErr)
			return EOF;
		break;
	case SEEK_END:
		if (off > 0)
			SetEOF((short) fd, off + size);
		if (SetFPos((short) fd, fsFromStart, off + size) != noErr)
			return EOF;
		break;
	case SEEK_SET:
		if (off > size)
			SetEOF((short) fd, off);
		if (SetFPos((short) fd, fsFromStart, off) != noErr)
			return EOF;
		break;
	}

	return (toff_t)(GetFPos((short) fd, &fpos) == noErr ? fpos : EOF);
}
예제 #8
0
파일: dosio.cpp 프로젝트: FREEWING-JP/np2pi
long file_seek(FILEH handle, long pointer, int method) {

	SInt32	pos;
	SInt32	setp;

	setp = pointer;
	switch(method) {
		case FSEEK_SET:
			break;
		case FSEEK_CUR:
			if (GetFPos(handle, &pos) != noErr) {
				return(-1);
			}
			setp += pos;
			break;
		case FSEEK_END:
			if (GetEOF(handle, &pos) != noErr) {
				return(-1);
			}
			setp += pos;
			break;
		default:
			return(-1);
	}
	SetFPos(handle, fsFromStart, setp);
	if (GetFPos(handle, &pos) != noErr) {
		return(-1);
	}
	return((long)pos);
}
예제 #9
0
int __PHYSFS_platformEOF(void *opaque)
{
    SInt16 ref = *((SInt16 *) opaque);
    SInt32 eofPos, curPos;
    BAIL_IF_MACRO(oserr(GetEOF(ref, &eofPos)) != noErr, NULL, 1);
    BAIL_IF_MACRO(oserr(GetFPos(ref, &curPos)) != noErr, NULL, 1);
    return(curPos >= eofPos);
} /* __PHYSFS_platformEOF */
예제 #10
0
PicHandle OpenPICTFile(
	short 	vRefNum, 
	Str255 	fName)
{
	short		fRefNum;
	OSErr		err;
	long		curEOF;
	PicHandle	myPic;
	long 		count;
	Ptr 		buffer;
	
	/* open PICT file */
	err = FSOpen(fName, vRefNum, &fRefNum);
	if (err != 0) {
		/*printf("Error - cannot open file\n"); */
		exit(-1);
	}
	
	/* get size of file */
	err = GetEOF(fRefNum, &curEOF);
	if (err != 0) {
		/*printf("Error - cannot get EOF\n"); */
		exit(-2);
	}
	
	/* move the file mark to 512 */
	err = SetFPos(fRefNum, SEEK_SET, 512L);
	if (err != 0) {
		/*printf("Error - cannot seek 512\n"); */
		exit(-3);
	}

	/* size of data to read */
	count = curEOF - 512;
	
	/* create the PicHandle */
	myPic = (PicHandle)NewHandle(count);
	HLock((Handle)myPic);
	
	/* read the PICT info */
	buffer = (Ptr)(*myPic);
	err = FSRead(fRefNum, &count, buffer);
	if (err != 0) {
		/*printf("Error - cannot read\n");*/
		exit(-4);
	}
	HUnlock((Handle)myPic);
	
	/* release the file */
	err = FSClose(fRefNum);
	if (err != 0) {
		/*printf("Error - cannot close file \n"); */
		exit(-5);
	}
	
	return (myPic);
}
예제 #11
0
static toff_t
_tiffSizeProc(thandle_t fd)
{
	long size;

	if (GetEOF((short) fd, &size) != noErr) {
		TIFFError("_tiffSizeProc", "%s: Cannot get file size");
		return (-1L);
	}
	return ((toff_t) size);
}
예제 #12
0
파일: dosio.cpp 프로젝트: FREEWING-JP/np2pi
UINT file_getsize(FILEH handle) {

	SInt32 pos;

	if (GetEOF(handle, &pos) == noErr) {
		return((UINT)pos);
	}
	else {
		return(0);
	}
}
예제 #13
0
파일: ftmac.c 프로젝트: dikerex/theqvd
  static long
  ResourceForkSize(FSSpec*  spec)
  {
    long   len;
    short  refNum;
    OSErr  e;


    e = FSpOpenRF( spec, fsRdPerm, &refNum ); /* I.M. Files 2-155 */
    if ( e == noErr )
    {
      e = GetEOF( refNum, &len );
      FSClose( refNum );
    }

    return ( e == noErr ) ? len : 0;
  }
예제 #14
0
파일: file.c 프로젝트: forostm/libecw
INT64 NCSFileSeek(int hFile,
				  	   INT64 nOffset,
				  	   int origin)
{
#ifdef WIN32

	return((INT64)_lseeki64(hFile, (__int64)nOffset, origin));

#elif defined MACINTOSH
	
	long fpos, size;

	if (GetEOF((short) hFile, &size) != noErr)
		return EOF;
	(void) GetFPos((short) hFile, &fpos);

	switch (origin) {
	case SEEK_CUR:
		if (nOffset + fpos > size)
			SetEOF((short) hFile, nOffset + fpos);
		if (SetFPos((short) hFile, fsFromMark, nOffset) != noErr)
			return EOF;
		break;
	case SEEK_END:
		if (nOffset > 0)
			SetEOF((short) hFile, nOffset + size);
		if (SetFPos((short) hFile, fsFromStart, nOffset + size) != noErr)
			return EOF;
		break;
	case SEEK_SET:
		if (nOffset > size)
			SetEOF((short) hFile, nOffset);
		if (SetFPos((short) hFile, fsFromStart, nOffset) != noErr)
			return EOF;
		break;
	}

	return (INT64)(GetFPos((short) hFile, &fpos) == noErr ? fpos : EOF);
	
#else	/* WIN32 */

#error: NCSFileSeek()
#endif	/* WIN32 */
}
예제 #15
0
파일: file.c 프로젝트: forostm/libecw
/*
** Get current file position
*/
INT64 NCSFileTell(int hFile)
{
#ifdef WIN32

	return((INT64)_telli64(hFile));

#elif defined MACINTOSH
/*   Simon's code
	UINT32		fileLocation;
	fgetpos(hFile,(unsigned long *)&fileLocation);
	return((UINT64)fileLocation);
*/ 
	long fpos, size;

	if (GetEOF((short) hFile, &size) != noErr)
		return EOF;
	return (INT64)size;
	//return (INT64) GetFPos((short) hFile, &fpos);

#else	/* WIN32 */
#error	NCSFileTell()
#endif	/* WIN32 */
}
예제 #16
0
void
InitLicTxt(void)
{
	Rect	destRect, viewRect;
	FSSpec	licFile;
	long 	dirID, dataSize;
	short 	vRefNum, dataRef, resRef;
	unsigned char* 	cLicFName;
	Str255			pLicFName;
	OSErr	err;
	Handle 	text, stylHdl;
	
	ERR_CHECK(GetCWD(&dirID, &vRefNum));
	
	/* open and read license file */
	HLock(gControls->cfg->licFileName);
	if(**gControls->cfg->licFileName != nil)
	{
		cLicFName = CToPascal(*gControls->cfg->licFileName);
		
		ERR_CHECK(FSMakeFSSpec(vRefNum, dirID, cLicFName, &licFile));
		if (cLicFName)
			DisposePtr((char*)cLicFName);
	}
	else /* assume default license filename from str rsrc */
	{	
		GetResourcedString(pLicFName, rInstList, sLicenseFName);
		ERR_CHECK(FSMakeFSSpec(vRefNum, dirID, pLicFName, &licFile));
	}
	HUnlock(gControls->cfg->licFileName);
	
	/* read license text */
	ERR_CHECK(FSpOpenDF( &licFile, fsRdPerm, &dataRef));
	ERR_CHECK(GetEOF(dataRef, &dataSize));

	if (dataSize > 0)
	{
		if (!(text = NewHandle(dataSize)))
		{
			ErrorHandler(eMem, nil);
			return;
		}
		ERR_CHECK(FSRead(dataRef, &dataSize, *text));
	}
	else
		text = nil;
	ERR_CHECK(FSClose(dataRef));

	/* get 'styl' if license is multistyled */
	resRef = FSpOpenResFile( &licFile, fsRdPerm);
	ERR_CHECK(ResError());

	UseResFile(resRef);
	stylHdl = RGetResource('styl', 128);
	ERR_CHECK(ResError());
	
	if(stylHdl)
		DetachResource(stylHdl);
	else
		stylHdl = nil;
	CloseResFile(resRef);
	
	/* TE specific init */
	HLock( (Handle) gControls->lw->licBox);
	SetRect(&viewRect, 	(*(gControls->lw->licBox))->contrlRect.left, 
						(*(gControls->lw->licBox))->contrlRect.top, 
						(*(gControls->lw->licBox))->contrlRect.right, 
						(*(gControls->lw->licBox))->contrlRect.bottom);
	HUnlock( (Handle) gControls->lw->licBox);

	destRect.left = viewRect.left;
		viewRect.right = (*(gControls->lw->scrollBar))->contrlRect.left; 
	destRect.right = viewRect.right;
	destRect.top = viewRect.top;
	destRect.bottom = viewRect.bottom * kNumLicScrns;
	
	// gControls->lw->licTxt = (TEHandle) NewPtrClear(sizeof(TEPtr));
	
	TextFont(applFont);
	TextFace(normal);
	TextSize(9);
	
	HLock(text);
	if (stylHdl)
	{
		gControls->lw->licTxt = TEStyleNew( &destRect, &viewRect );
		TEStyleInsert( *text, dataSize, (StScrpRec ** )stylHdl, 
						gControls->lw->licTxt);
	}
	else
	{
		gControls->lw->licTxt = TENew( &destRect, &viewRect);
		TEInsert( *text, dataSize, gControls->lw->licTxt);
	}
	HUnlock(text);
	
	TextFont(systemFont);
	TextSize(12);
	
	TESetAlignment(teFlushDefault, gControls->lw->licTxt);
}
예제 #17
0
파일: lseg.c 프로젝트: GnoConsortium/gno
/*
 *  The caller is responsible for opening the file, passing its refNum,
 *  and closing it after we're done
 */
void scanOMF(int fd, char *fname)
{
OMFhead header;
longword off = 0l;
PositionRecGS p;
int kind;
int i;

    p.pCount = 2;
    p.refNum = fd;
    GetEOF(&p);

    while (off < p.position) {
        lseek(fd, off, SEEK_SET);
        read(fd,&header,sizeof(header));
        /* First time through, check validity of OMF header [v1.1] */
        if (off == 0  &&  notOMF(&header))   {
           printf("Note: %s is not a recognized OMF file\n", fname);
           return;
        }
        lseek(fd, off+header.DISPNAME+10, SEEK_SET);
        if (header.LABLEN == 0) {
            read(fd, name, 1);
            read(fd, name+1, name[0]);
        } else {
            name[0] = header.LABLEN;
            read(fd, name+1, header.LABLEN);
        }
        printf("%s",fname);
        i = strlen(fname);
        while (i++ < 20) putchar(' ');

        kind = header.KIND & 0x1F;
        switch (kind)   {
            case 0x00:
                if (decimal_output)
                   printf(" %s %8ld ", segTypes[kind],header.LENGTH);
                else
                   printf(" %s 0x%06lX ", segTypes[kind],header.LENGTH);
                /* Check code segment for stack allocation [v1.1] */
                /* Position to beginning of data */
                lseek(fd, off+header.DISPDATA, SEEK_SET);
                /* Check the code */
                checkCodeStack(fd);
                break;
            case 0x01:
            case 0x02:
            case 0x04:
            case 0x08:
            case 0x10:
            case 0x12:
                if (decimal_output)
                   printf(" %s %8ld        ", segTypes[kind],header.LENGTH);
                else
                   printf(" %s 0x%06lX        ", segTypes[kind],header.LENGTH);
                break;
            default:
                printf(" unknown (0x%02X)     ", kind);
            }
        prntAscii(name+1,name[0]);
        putchar('\n');
        /* In OMF version 1, the first field is a block count */
        if (header.VERSION == 1)
           off += (header.BYTECNT * 512);
        else
           off += header.BYTECNT;
        /* Check for unusual case that causes infinite loop [v1.1] */
        if (header.BYTECNT == 0) break;
    }
}
예제 #18
0
OSErr QTInfo_MakeFilePreview (Movie theMovie, short theRefNum, ICMProgressProcRecordPtr theProgressProc)
{
    unsigned long			myModDate;
    PreviewResourceRecord	myPNOTRecord;
    long					myEOF;
    long					mySize;
    unsigned long			myAtomHeader[2];	// an atom header: size and type
    OSType					myPreviewType;
    OSErr					myErr = noErr;

    //////////
    //
    // determine whether theRefNum is a file reference number of a data fork or a resource fork;
    // if it's a resource fork, then we'll just call the existing ICM function MakeFilePreview
    //
    //////////

    if (QTInfo_IsRefNumOfResourceFork(theRefNum)) {
        myErr = MakeFilePreview(theRefNum, theProgressProc);
        goto bail;
    }

    //////////
    //
    // determine the preview type
    //
    //////////

    // if the movie has a movie preview, use that as the file preview; otherwise use a thumbnail
    // of the movie poster frame as the file preview
    if (QTInfo_MovieHasPreview(theMovie))
        myPreviewType = MovieAID;
    else
        myPreviewType = kQTFileTypePicture;

    //////////
    //
    // construct the 'pnot' atom
    //
    //////////

    // fill in the 'pnot' atom header
    myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + sizeof(myPNOTRecord));
    myAtomHeader[1] = EndianU32_NtoB(ShowFilePreviewComponentType);

    // fill in the 'pnot' atom data
    GetDateTime(&myModDate);

    myPNOTRecord.modDate = EndianU32_NtoB(myModDate);		// the modification time of the preview
    myPNOTRecord.version = EndianS16_NtoB(0);				// version number; must be 0
    myPNOTRecord.resType = EndianU32_NtoB(myPreviewType);	// atom type containing preview
    myPNOTRecord.resID = EndianS16_NtoB(1);					// the 1-based index of the atom of the specified type to use

    //////////
    //
    // write the 'pnot' atom at the end of the data fork
    //
    //////////

    // get the current logical end-of-file and extend it by the desired amount
    myErr = GetEOF(theRefNum, &myEOF);
    if (myErr != noErr)
        goto bail;

    myErr = SetEOF(theRefNum, myEOF + sizeof(myAtomHeader) + sizeof(myPNOTRecord));
    if (myErr != noErr)
        goto bail;

    // set the file mark
    myErr = SetFPos(theRefNum, fsFromStart, myEOF);
    if (myErr != noErr)
        goto bail;

    // write the atom header into the file
    mySize = sizeof(myAtomHeader);
    myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
    if (myErr != noErr)
        goto bail;

    // write the atom data into the file
    mySize = sizeof(myPNOTRecord);
    myErr = FSWrite(theRefNum, &mySize, &myPNOTRecord);
    if (myErr != noErr)
        goto bail;

    //////////
    //
    // write the preview data atom at the end of the data fork
    //
    //////////

    if (myPreviewType == MovieAID) {
        // in theory, we don't need to do anything here, since our 'pnot' atom points
        // to the 'moov' atom; in practice, this doesn't work correctly (it seems like
        // a bug in StandardGetFilePreview)
    }

    if (myPreviewType == kQTFileTypePicture) {
        PicHandle		myPicture = NULL;
        PicHandle		myThumbnail = NULL;

        // get the poster frame picture
        myPicture = GetMoviePosterPict(theMovie);
        if (myPicture != NULL) {

            // create a thumbnail
            myThumbnail = (PicHandle)NewHandleClear(4);
            if (myThumbnail != NULL) {
                myErr = MakeThumbnailFromPicture(myPicture, 0, myThumbnail, theProgressProc);
                if (myErr == noErr) {

                    myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + GetHandleSize((Handle)myThumbnail));
                    myAtomHeader[1] = EndianU32_NtoB(myPreviewType);

                    // write the atom header into the file
                    mySize = sizeof(myAtomHeader);
                    myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
                    if (myErr == noErr) {
                        // write the atom data into the file
                        mySize = GetHandleSize((Handle)myThumbnail);
                        myErr = FSWrite(theRefNum, &mySize, *myThumbnail);
                    }
                }

                KillPicture(myThumbnail);
            }

            KillPicture(myPicture);
        }
    }

#if 0
    // here's how you'd add a text preview; note that the text is hard-coded here....
    if (myPreviewType == kQTFileTypeText) {
        char 	myText[] = "The penguin gradually appears from the mist of the ice floe.";

        myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + strlen(myText));
        myAtomHeader[1] = EndianU32_NtoB(myPreviewType);

        // write the atom header into the file
        mySize = sizeof(myAtomHeader);
        myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
        if (myErr != noErr)
            goto bail;

        // write the atom data into the file
        mySize = strlen(myText);
        myErr = FSWrite(theRefNum, &mySize, myText);
        if (myErr != noErr)
            goto bail;
    }
#endif

#if TARGET_OS_MAC
    if (myErr == noErr) {
        short				myVolNum;

        // flush the volume
        myErr = GetVRefNum(theRefNum, &myVolNum);
        if (myErr != noErr)
            goto bail;

        myErr = FlushVol(NULL, myVolNum);
    }
#endif

bail:
    return(myErr);
}