コード例 #1
0
ファイル: FileCopy.c プロジェクト: fduhia/metamage_1
static	OSErr	PreflightFileCopySpace(short srcVRefNum,
									   long srcDirID,
									   ConstStr255Param srcName,
									   ConstStr255Param dstVolName,
									   short dstVRefNum,
									   Boolean *spaceOK)
{
	UniversalFMPB pb;
	OSErr error;
	unsigned long dstFreeBlocks;
	unsigned long dstBlksPerAllocBlk;
	unsigned long srcDataBlks;
	unsigned long srcResourceBlks;
	
	error = XGetVolumeInfoNoName(dstVolName, dstVRefNum, &pb.xPB);
	if ( error == noErr )
	{
		/* get allocation block size (always multiple of 512) and divide by 512
		  to get number of 512-byte blocks per allocation block */
		dstBlksPerAllocBlk = ((unsigned long)pb.xPB.ioVAlBlkSiz >> 9);
		
		/* Convert freeBytes to free disk blocks (512-byte blocks) */
		dstFreeBlocks = U32SetU(U64ShiftRight(pb.xPB.ioVFreeBytes, 9));
		
		/* Now, get the size of the file's data resource forks */
		pb.hPB.fileParam.ioNamePtr = (StringPtr)srcName;
		pb.hPB.fileParam.ioVRefNum = srcVRefNum;
		pb.hPB.fileParam.ioFVersNum = 0;
		pb.hPB.fileParam.ioDirID = srcDirID;
		pb.hPB.fileParam.ioFDirIndex = 0;
		error = PBHGetFInfoSync(&pb.hPB);
		if ( error == noErr )
		{
			/* Since space on Mac OS disks is always allocated in allocation blocks, */
			/* this code takes into account rounding up to the end of an allocation block. */

			/* get number of 512-byte blocks needed for data fork */
			if ( ((unsigned long)pb.hPB.fileParam.ioFlLgLen & 0x000001ff) != 0 )
			{
				srcDataBlks = ((unsigned long)pb.hPB.fileParam.ioFlLgLen >> 9) + 1;
			}
			else
			{
コード例 #2
0
ファイル: file.c プロジェクト: forostm/libecw
NCSError NCSRemoveDir( const char *pDirName)
{
#ifdef LINUX
	if(rmdir(pDirName) == 0) {
#elif defined(_WIN32_WCE)
	if(RemoveDirectory(OS_STRING(pDirName)) != 0) {
#else
	if(rmdir(pDirName) == 0) {
#endif
		return(NCS_SUCCESS);
	} else {
		return(NCS_FILEIO_ERROR);
	}
}

/* 
** Seek to given position
*/
INT64 NCSFileSeekNative(NCS_FILE_HANDLE hFile,
				  INT64 nOffset,
				  NCS_FILE_ORIGIN origin)
{
#if defined WIN32
	LARGE_INTEGER li;

	li.QuadPart = nOffset;

	li.LowPart = SetFilePointer(hFile,						// file handle
						li.LowPart,							// low 32 bits
						&li.HighPart,						// high 32 bits
						origin);						// relative to start of file

	if( li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR )
		return( -1 );
	else
		return( li.QuadPart );
#elif defined PALM
	switch(origin) {
		case NCS_FILE_SEEK_START:
				hFile->iOffset = nOffset;
			break;
		case NCS_FILE_SEEK_CURRENT:
				hFile->iOffset += nOffset;
			break;
		case NCS_FILE_SEEK_END:
				hFile->iOffset = hFile->nDBSize + nOffset - 1;
	}
	return(hFile->iOffset);
#elif defined MACINTOSH
	UINT32	myOffset;
	int		result; 
			
	myOffset = U32SetU(nOffset);
			
	if(!myOffset) result = 0;
			
	result = SetFPos((short)hFile, fsFromStart, myOffset);
			
	if(!result) return myOffset;
	else return (0);
#elif defined SOLARIS
	return (INT64) llseek(hFile, (offset_t)nOffset, origin);
#elif defined LINUX
	return (INT64) lseek64(hFile, (__off64_t)nOffset, origin);
#elif defined HPUX
	return (INT64) lseek64(hFile, (off64_t)nOffset, origin);
#elif defined IRIX
	return (INT64) lseek64(hFile, (off64_t)nOffset, origin);
#elif defined MACOSX
    return (INT64) lseek(hFile, nOffset, origin);
#endif
}

/*
** Get current file position
*/
INT64 NCSFileTellNative(NCS_FILE_HANDLE hFile)
{
#if defined WIN32
	LARGE_INTEGER li;

	li.QuadPart = 0;

	li.LowPart = SetFilePointer(hFile,						// file handle
						li.LowPart,							// low 32 bits
						&li.HighPart,						// high 32 bits
						FILE_CURRENT);						// relative to present position

	if( li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR )
		return(-1);
	else
		return(li.QuadPart);

#elif defined MACINTOSH

	long  myOffset;
	OSErr	result;
		
	result = GetFPos((short)hFile, &myOffset);
			
	if (result==noErr)
		return ((INT64)myOffset);
	else
		return ((INT64)-1);

#elif defined PALM
	return(hFile->iOffset);
#elif defined SOLARIS
	INT64 nOffset = llseek(hFile, (offset_t)0, SEEK_CUR);
	return(nOffset);
#elif defined IRIX
	return((INT64)telli64(hFile));
#elif defined LINUX
	return (INT64) lseek64(hFile, (__off64_t)0, SEEK_CUR);
#elif defined HPUX
	return (INT64) lseek64(hFile, (off64_t)0, SEEK_CUR);
#elif defined MACOSX
	return (INT64) lseek(hFile, (long)0, SEEK_CUR);
#else
#error ERROR: EcwFileGetPos() routine is not defined for this platform
#endif
}