当前位置: 首页>>代码示例>>C++>>正文


C++ SetFilePointerEx函数代码示例

本文整理汇总了C++中SetFilePointerEx函数的典型用法代码示例。如果您正苦于以下问题:C++ SetFilePointerEx函数的具体用法?C++ SetFilePointerEx怎么用?C++ SetFilePointerEx使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetFilePointerEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AllocateFileRange

/**
 * this function tries to make a particular range of a file allocated (corresponding to disk space)
 * it is advisory, and the range specified in the arguments will never contain live data
 */
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
#if defined(WIN32)
    // Windows-specific version
    HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
    LARGE_INTEGER nFileSize;
    int64_t nEndPos = (int64_t)offset + length;
    nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
    nFileSize.u.HighPart = nEndPos >> 32;
    SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
    SetEndOfFile(hFile);
#elif defined(MAC_OSX)
    // OSX specific version
    fstore_t fst;
    fst.fst_flags = F_ALLOCATECONTIG;
    fst.fst_posmode = F_PEOFPOSMODE;
    fst.fst_offset = 0;
    fst.fst_length = (off_t)offset + length;
    fst.fst_bytesalloc = 0;
    if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
        fst.fst_flags = F_ALLOCATEALL;
        fcntl(fileno(file), F_PREALLOCATE, &fst);
    }
    ftruncate(fileno(file), fst.fst_length);
#elif defined(__linux__)
    // Version using posix_fallocate
    off_t nEndPos = (off_t)offset + length;
    posix_fallocate(fileno(file), 0, nEndPos);
#else
    // Fallback version
    // TODO: just write one byte per block
    static const char buf[65536] = {};
    fseek(file, offset, SEEK_SET);
    while (length > 0) {
        unsigned int now = 65536;
        if (length < now)
            now = length;
        fwrite(buf, 1, now, file); // allowed to fail; this function is advisory anyway
        length -= now;
    }
#endif
}
开发者ID:Explore77,项目名称:litecoin,代码行数:45,代码来源:util.cpp

示例2: __win_file_set_end

/*
 * __win_file_set_end --
 *	Truncate or extend a file.
 */
static int
__win_file_set_end(
    WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session, wt_off_t len)
{
	DWORD windows_error;
	WT_FILE_HANDLE_WIN *win_fh;
	WT_SESSION_IMPL *session;
	LARGE_INTEGER largeint;

	win_fh = (WT_FILE_HANDLE_WIN *)file_handle;
	session = (WT_SESSION_IMPL *)wt_session;

	largeint.QuadPart = len;

	if (win_fh->filehandle_secondary == INVALID_HANDLE_VALUE)
		WT_RET_MSG(session, EINVAL,
		    "%s: handle-set-end: no secondary handle",
		    file_handle->name);

	if (SetFilePointerEx(win_fh->filehandle_secondary,
	    largeint, NULL, FILE_BEGIN) == FALSE) {
		windows_error = __wt_getlasterror();
		__wt_errx(session,
		    "%s: handle-set-end: SetFilePointerEx: %s",
		    file_handle->name,
		    __wt_formatmessage(session, windows_error));
		return (__wt_map_windows_error(windows_error));
	}

	if (SetEndOfFile(win_fh->filehandle_secondary) == FALSE) {
		if (GetLastError() == ERROR_USER_MAPPED_FILE)
			return (EBUSY);
		windows_error = __wt_getlasterror();
		__wt_errx(session,
		    "%s: handle-set-end: SetEndOfFile: %s",
		    file_handle->name,
		    __wt_formatmessage(session, windows_error));
		return (__wt_map_windows_error(windows_error));
	}
	return (0);
}
开发者ID:Machyne,项目名称:mongo,代码行数:45,代码来源:os_fs.c

示例3: doOpen

void *__PHYSFS_platformOpenAppend(const char *filename)
{
	void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
	if (retval != NULL)
	{
		HANDLE h = ((WinApiFile *)retval)->handle;
		//DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
		const LARGE_INTEGER zero = { 0 };
		DWORD rc = SetFilePointerEx(h, zero, NULL, FILE_END);
		if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
		{
			const char *err = winApiStrError();
			CloseHandle(h);
			allocator.Free(retval);
			BAIL_MACRO(err, NULL);
		} /* if */
	} /* if */

	return retval;

} /* __PHYSFS_platformOpenAppend */
开发者ID:ahrnbom,项目名称:physfs-uwp,代码行数:21,代码来源:winrt.cpp

示例4: GetLastError

 void File::truncate(fileofs size) {
     if (len() <= size) {
         return;
     }
     LARGE_INTEGER li;
     li.QuadPart = size;
     if (SetFilePointerEx(_handle, li, NULL, FILE_BEGIN) == 0) {
         _bad = true;
         DWORD dosError = GetLastError();
         log() << "In File::truncate(), SetFilePointerEx for '" << _name
               << "' tried to set the file pointer to " << size
               << " but failed with " << errnoWithDescription(dosError) << std::endl;
         return;
     }
     if (SetEndOfFile(_handle) == 0) {
         _bad = true;
         DWORD dosError = GetLastError();
         log() << "In File::truncate(), SetEndOfFile for '" << _name
               << "' failed with " << errnoWithDescription(dosError) << std::endl;
     }
 }
开发者ID:ANTco,项目名称:mongo,代码行数:21,代码来源:file.cpp

示例5: GetFileReadHandle

U1 MIOSystem::LoadFile( FileInfo& info,STD_VECTOR<U8>& data )
{

	

	data.resize(info.compressize);
	LARGE_INTEGER fpos;
	fpos.QuadPart	=	info.offset;
	LARGE_INTEGER oldpos;
	m_CSRead.Enter();
	HANDLE h = GetFileReadHandle(info.idx&0xffff);
	if(h==NULL){
		m_CSRead.Leave();
		return false;
	}
	SetFilePointerEx(h,fpos,&oldpos,FILE_BEGIN);
	DWORD dwRead=0;
	ReadFile(h,&data[0],info.compressize,&dwRead,NULL);
	m_CSRead.Leave();
	return true;
}
开发者ID:ingeyu,项目名称:airengine,代码行数:21,代码来源:MIOSystem.cpp

示例6: if

bool C_File::Seek(long long val, SeekMode mode, long long* newdest)
{
	if(m_handle!=INVALID_HANDLE_VALUE) 
	{
		LARGE_INTEGER dest, ndest;
		ndest.QuadPart = 0;
		dest.QuadPart = val;

		unsigned int mmode = 0;
		if(mode==Seek_Set) mmode = FILE_BEGIN;
		else if(mode==Seek_Current) mmode = FILE_CURRENT;
		else if(mode==Seek_End) mmode = FILE_END;

		if(SetFilePointerEx(m_handle, dest, &ndest, mmode))
		{
			if(newdest!=0) *newdest = ndest.QuadPart;
			return true;
		}
	}
	return false;
}
开发者ID:omkar-developer,项目名称:OmkEngine,代码行数:21,代码来源:WinPlatformFile.cpp

示例7: SetFilePointerEx

WordPtr Burger::File::GetMark(void)
{
	WordPtr uMark = 0;
	HANDLE fp = m_pFile;
	if (fp) {
		LARGE_INTEGER uNewPointer;
		LARGE_INTEGER uOldPointer;
		uNewPointer.QuadPart = 0;
		// Get the current file mark
		BOOL bPositionResult = SetFilePointerEx(fp,uNewPointer,&uOldPointer,FILE_CURRENT);
		// If no error, restore the old file mark
		if (bPositionResult) {
			if (uOldPointer.HighPart) {
				uMark = 0xFFFFFFFFUL;
			} else {
				uMark = uOldPointer.LowPart;
			}
		}
	}
	return uMark;
}
开发者ID:cometdlut,项目名称:burgerlib,代码行数:21,代码来源:brfilexbox360.cpp

示例8: SetFilePointerEx

long CRawFile::Tell( void ) const
{
#ifdef _WIN32
    LARGE_INTEGER posToMoveTo;
    posToMoveTo.LowPart = 0;
    posToMoveTo.HighPart = 0;

    LARGE_INTEGER currentPos;

    BOOL success = SetFilePointerEx( this->m_file, posToMoveTo, &currentPos, FILE_CURRENT );

    if ( success == FALSE )
        return -1;

    return (long)( currentPos.LowPart );
#elif defined(__linux__)
    return ftell( m_file );
#else
    return -1;
#endif //OS DEPENDANT CODE
}
开发者ID:quiret,项目名称:magic-txd,代码行数:21,代码来源:CFileSystem.stream.raw.cpp

示例9: create_sparse_file

static void
create_sparse_file(const char *path, const struct sparse *s)
{
	char buff[1024];
	HANDLE handle;
	DWORD dmy;

	memset(buff, ' ', sizeof(buff));

	handle = CreateFileA(path, GENERIC_WRITE, 0,
	    NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
	    NULL);
	assert(handle != INVALID_HANDLE_VALUE);
	assert(DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0,
	    NULL, 0, &dmy, NULL) != 0);
	while (s->type != END) {
		if (s->type == HOLE) {
			LARGE_INTEGER distance;

			distance.QuadPart = s->size;
			assert(SetFilePointerEx(handle, distance,
			    NULL, FILE_CURRENT) != 0);
		} else {
			DWORD w, wr;
			size_t size;

			size = s->size;
			while (size) {
				if (size > sizeof(buff))
					w = sizeof(buff);
				else
					w = (DWORD)size;
				assert(WriteFile(handle, buff, w, &wr, NULL) != 0);
				size -= wr;
			}
		}
		s++;
	}
	assertEqualInt(CloseHandle(handle), 1);
}
开发者ID:HunterChen,项目名称:libarchive,代码行数:40,代码来源:test_sparse_basic.c

示例10: _dodecomp

__int64 NSISCALL _dodecomp(__int64 offset, HANDLE hFileOut, unsigned char *outbuf, int outbuflen)
{
  DWORD r;
  __int64 input_len;
  __int64 retval;
  if (offset>=0)
  {
    dbd_pos=g_blocks[NB_DATA].offset+offset;
    SetFilePointerEx(dbd_hFile,(LARGE_INTEGER*)&dbd_pos,NULL,FILE_BEGIN);
  }
  retval=__ensuredata(sizeof(__int64));
  if (retval<0) return retval;

  if (!ReadFile(dbd_hFile,(LPVOID)&input_len,sizeof(__int64),&r,NULL) || r!=sizeof(__int64)) return -3;
  dbd_pos+=sizeof(__int64);

  retval=__ensuredata(input_len);
  if (retval < 0) return retval;

  if (!outbuf)
  {
    while (input_len > 0)
    {
      DWORD t;
      DWORD l=min(input_len,IBUFSIZE);
      if (!ReadFile(dbd_hFile,(LPVOID)_inbuffer,l,&r,NULL) || l != r) return -3;
      if (!WriteFile(hFileOut,_inbuffer,r,&t,NULL) || t != l) return -2;
      retval+=r;
      input_len-=r;
      dbd_pos+=r;
    }
  }
  else
  {
    if (!ReadFile(dbd_hFile,(LPVOID)outbuf,min(input_len,outbuflen),&r,NULL)) return -3;
    retval=r;
    dbd_pos+=r;
  }
  return retval;
}
开发者ID:Argimko,项目名称:Nsis64,代码行数:40,代码来源:fileform.c

示例11: create_very_big_file

bool create_very_big_file(_In_ const wchar_t* file_path, _In_ uint32_t size_in_mb)
{
	_ASSERTE(NULL != file_path);
	if (NULL == file_path) return false;

	if (is_file_existsW(file_path))
	{
		::DeleteFileW(file_path);
	}

	// create very big file
	HANDLE file_handle = CreateFile(
		file_path,
		GENERIC_WRITE,
		FILE_SHARE_READ,
		NULL,
		CREATE_NEW,
		FILE_ATTRIBUTE_NORMAL,
		NULL
		);
	if (INVALID_HANDLE_VALUE == file_handle)
	{
		print("err ] CreateFile( %ws ) failed. gle = %u", file_path, GetLastError());
		return false;
	}

	LARGE_INTEGER file_size = { 0 };
	file_size.QuadPart = (uint32_t)(1024 * 1024) * size_in_mb;
	if (!SetFilePointerEx(file_handle, file_size, NULL, FILE_BEGIN))
	{
		print("err ] SetFilePointerEx() failed. gle = %u", GetLastError());

		CloseHandle(file_handle);
		return false;
	}

	SetEndOfFile(file_handle);
	CloseHandle(file_handle);
	return true;
}
开发者ID:cosmicb0y,项目名称:CopyFile,代码行数:40,代码来源:CopyFile.cpp

示例12: while

void mDisk::readSector(char* data, long long startingSector, int nBytes, int& numberOfBytesRead)
{
	numberOfBytesRead = 0;
	int nBytesLeft = nBytes;
	//pointer to the starting position of data field
	char* pointer = data;
	int numberOfBytesToRead;

	while (nBytesLeft > 0)
	{
		if (startingSector > this->ending || startingSector < this->starting)
		{
			LARGE_INTEGER offset;
			offset.QuadPart = startingSector;
			offset.QuadPart *= 512;
			SetFilePointerEx(this->vol, offset, 0, FILE_BEGIN);

			DWORD nOfRead;
			ReadFile(this->vol, this->disk, (DWORD)MAXSECTOR*512, &nOfRead, 0);

			this->starting = startingSector;
			this->ending = this->starting + (nOfRead / 512 + int(nOfRead % 512 > 0)) - 1;
		}

		if (this->ending < startingSector)
			return;
		//point to the position of startingSector between this->starting and this->ending
		char* startingPointer = this->disk + (startingSector - this->starting) * 512;
		int numberOfBytesToCopy = min((this->ending - startingSector + 1) * 512, nBytesLeft);
		memcpy(pointer, startingPointer, numberOfBytesToCopy);
		
		numberOfBytesRead += numberOfBytesToCopy;
		nBytesLeft -= numberOfBytesToCopy;
		//shift the pointer to the next position of data field to copy
		pointer += numberOfBytesToCopy;
		//shift the starting sector to the next position in disk
		startingSector += numberOfBytesToCopy / 512 + int(numberOfBytesToCopy % 512 > 0);
	}
	
}
开发者ID:hungnguyen0606,项目名称:ATPHDL,代码行数:40,代码来源:mDisk.cpp

示例13: createfile

HANDLE createfile(const TCHAR *filename, size_w length)
{
	TCHAR tmpfile[MAX_PATH];
	const TCHAR *newname = filename;
	HANDLE hFile;

	if(filename == 0)
	{
		GetTempPath(MAX_PATH, tmpfile);
		GetTempFileName(tmpfile, TEXT("~HX"), 0, tmpfile);

		newname = tmpfile;
	}

	hFile = CreateFile(newname, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0);

	if(hFile != INVALID_HANDLE_VALUE)
	{
		LARGE_INTEGER set;
		LARGE_INTEGER result;

		set.QuadPart = length;
	
		// allocate space for desired file size
		if(SetFilePointerEx(hFile, set, &result, FILE_BEGIN))
		{
			if(SetEndOfFile(hFile))
			{
				return hFile;
			}
		}

		CloseHandle(hFile);
	}

	if(filename == 0)
		DeleteFile(tmpfile);

	return 0;
}
开发者ID:rajeshpillai,项目名称:HexEdit,代码行数:40,代码来源:seqbuf.cpp

示例14: Seek

int FSSys::Seek( int fd, SEEK_FILE_MODE mode, seek_t pos, seek_t* pRet,  int* err, FSCInfo* info )
{
	HANDLE* p = this->handles.Handle( fd );

	if ( !p ) { SetError( err, ERROR_INVALID_PARAMETER ); return -1; }

	LARGE_INTEGER li;
	li.QuadPart = pos;

	if ( !SetFilePointerEx( *p, li, &li, mode ) )
	{
		SetError( err, GetLastError() );
		return -1;
	}

	if ( pRet )
	{
		*pRet = li.QuadPart;
	}

	return 0;
}
开发者ID:KonstantinKuklin,项目名称:WalCommander,代码行数:22,代码来源:vfs.cpp

示例15: __wt_ftruncate

/*
 * __wt_ftruncate --
 *	Truncate a file.
 */
int
__wt_ftruncate(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t len)
{
	WT_DECL_RET;
	LARGE_INTEGER largeint;

	largeint.QuadPart = len;

	if ((ret = SetFilePointerEx(
	    fh->filehandle_secondary, largeint, NULL, FILE_BEGIN)) == FALSE)
		WT_RET_MSG(session, __wt_errno(), "%s SetFilePointerEx error",
		    fh->name);

	ret = SetEndOfFile(fh->filehandle_secondary);
	if (ret != FALSE)
		return (0);

	if (GetLastError() == ERROR_USER_MAPPED_FILE)
		return (EBUSY);

	WT_RET_MSG(session, __wt_errno(), "%s SetEndOfFile error", fh->name);
}
开发者ID:7segments,项目名称:mongo-1,代码行数:26,代码来源:os_ftruncate.c


注:本文中的SetFilePointerEx函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。