bool getCRC32(const TCHAR* name, DWORD& CRC,const unsigned char* sideinfo, size_t size) { if (!name) return false; int hFile=openRead(name); if (hFile<0) return false; CRC32 *crc=new CRC32(); const size_t BUFFERSIZE=4096; unsigned char *ucBuffer=new unsigned char[BUFFERSIZE]; __int64 filesize=_lseeki64(hFile,0,SEEK_END); _lseeki64(hFile,0,SEEK_SET); CRC=0; while (filesize-BUFFERSIZE>0) { int rd=_read(hFile,ucBuffer,BUFFERSIZE); filesize-=BUFFERSIZE; CRC=crc->get(ucBuffer,BUFFERSIZE,CRC); }; if (filesize>0) { int rd=_read(hFile,ucBuffer,(unsigned int)(filesize)); CRC=crc->get(ucBuffer,(unsigned int)(filesize),CRC); } // Add sideinfo if (sideinfo && size) CRC=crc->get(sideinfo,size,CRC); _close(hFile); delete[] ucBuffer; delete crc; return true; }
bool WavpackSource::parseWrapper() { int fd = fileno(m_fp.get()); util::FilePositionSaver saver__(fd); _lseeki64(fd, 0, SEEK_SET); WavpackHeader hdr; if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) return false; if (std::memcmp(hdr.ckID, "wvpk", 4) != 0) return false; if (hdr.ckSize < sizeof(hdr) || hdr.ckSize > 0x1000000) return false; std::vector<char> first_block(hdr.ckSize); _lseeki64(fd, 0, SEEK_SET); if (read(fd, &first_block[0], hdr.ckSize) != hdr.ckSize) return false; void *loc = m_module.GetWrapperLocation(&first_block[0], 0); if (!loc) return false; ptrdiff_t off = static_cast<char *>(loc) - &first_block[0]; _lseeki64(fd, off, SEEK_SET); try { WaveSource src(m_fp, false); memcpy(&m_asbd, &src.getSampleFormat(), sizeof(m_asbd)); return true; } catch (const std::runtime_error &) { return false; } }
// This function handles the case where the file is open in UTF-8 text mode and // the translated UTF-16 form of the text has a different number of characters // than the original UTF-8 text (remember: when reading a file in UTF-8 mode, the // lowio library converts the UTF-8 to UTF-16). static __int64 __cdecl common_ftell_translated_utf8_nolock( __crt_stdio_stream const stream, __int64 const lowio_position ) throw() { int const fh = _fileno(stream.public_stream()); // If the buffer has been exhausted, then the current lowio position is also // the current stdio position: if (stream->_cnt == 0) return lowio_position; __int64 const current_buffer_position = (stream->_ptr - stream->_base) / static_cast<__int64>(sizeof(wchar_t)); // Otherwise, we have to re-read the buffer, in binary mode, so that we can // analyze the original UTF-8 text to compute the actual position in the // file. To do this, we seek the lowio pointer back to the beginning of // the stdio buffer, re-read the buffer, then seek the lowio pointer back // to its original location: __int64 const base_buffer_position = _lseeki64(fh, _startpos(fh), SEEK_SET); if (base_buffer_position != _startpos(fh)) return -1; DWORD bytes_read; char raw_buffer[_INTERNAL_BUFSIZ]; if (!ReadFile(reinterpret_cast<HANDLE>(_osfhnd(fh)), raw_buffer, _INTERNAL_BUFSIZ, &bytes_read, nullptr)) return -1; // Seek back to where we were, to ensure the stdio stream is left in a // consistent state (and "unmodified" from before the call): if (_lseeki64(fh, lowio_position, SEEK_SET) < 0) return -1; // This should not normally happen: we should always read enough bytes: if (current_buffer_position > static_cast<__int64>(bytes_read)) return -1; // Scan the raw, untranslated buffer to find the current position, updating // the file pointer to account for newline translation in the buffer: char const* const raw_first = raw_buffer; #pragma warning(disable:__WARNING_UNUSED_POINTER_ASSIGNMENT) // 28930 char const* const raw_last = raw_buffer + bytes_read; char const* raw_it = raw_first; for (__int64 i = 0; i != current_buffer_position && raw_it < raw_last; ++i, ++raw_it) { if (*raw_it == CR) { if (raw_it < raw_last - 1 && *(raw_it + 1) == LF) ++raw_it; } else { raw_it += _utf8_no_of_trailbytes(*raw_it); } } return base_buffer_position + (raw_it - raw_first); }
//----------------------------------------------------------------------------- // Purpose: Lists all of the files in a pakfile // Input : *pakfile - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool Pack_Validate(const char *pakfile) { int hPack = _open(pakfile, _O_RDWR | _O_BINARY); if (hPack == -1) { printf("Couldn't open pakfile '%s'\n", pakfile); return false; } // jump to the end of the file, see if it has a header int64 iFileSize = _filelengthi64(hPack); iFileSize; packappenededheader_t appended; _lseeki64(hPack, (long)(0 - sizeof(packappenededheader_t)), SEEK_END); _read(hPack, &appended, sizeof(appended)); if (!(appended.id[0] == 'P' && appended.id[1] == 'A' && appended.id[2] == 'C' && appended.id[3] == 'K' && appended.id[4] == 'A' && appended.id[5] == 'P' && appended.id[6] == 'P' && appended.id[7] == 'E')) { printf("Invalid pack file '%s'\n", pakfile); return false; } // read in header packheader64_t header; _lseeki64(hPack, appended.packheaderpos, SEEK_SET); _read(hPack, &header, sizeof(header)); int iFilesInPack = (int)(header.dirlen / sizeof(packfile64_t)); // header + file assert( iFileSize == (appended.packheaderpos + sizeof(header) + header.dirlen + sizeof(appended)) ); // read in the directory packfile64_t *packfiles = new packfile64_t[iFilesInPack]; if (header.dirlen) { _lseeki64(hPack, appended.packheaderpos + header.dirofs, SEEK_SET); _read(hPack, packfiles, (long)header.dirlen); } // list for (int i = 0; i < iFilesInPack; i++) { assert(packfiles[i].name[0]); assert(packfiles[i].filelen); // printf("File '%s' size %d\n", packfiles[i].name, (int)packfiles[i].filelen); } _close(hPack); return true; }
result_t File::readAll(obj_ptr<Buffer_base> &retVal, AsyncEvent *ac) { if (m_fd == -1) return CHECK_ERROR(CALL_E_INVALID_CALL); if (!ac) return CHECK_ERROR(CALL_E_NOSYNC); qstring strBuf; int32_t bytes; int64_t p = _lseeki64(m_fd, 0, SEEK_CUR); if (p < 0) return CHECK_ERROR(LastError()); int64_t sz = _lseeki64(m_fd, 0, SEEK_END); if (sz < 0) return CHECK_ERROR(LastError()); if (_lseeki64(m_fd, p, SEEK_SET) < 0) return CHECK_ERROR(LastError()); sz -= p; bytes = (int32_t) sz; if (bytes > 0) { strBuf.resize(bytes); int32_t sz = bytes; char *p = &strBuf[0]; while (sz) { int32_t n = (int32_t) ::_read(m_fd, p, sz > STREAM_BUFF_SIZE ? STREAM_BUFF_SIZE : sz); if (n < 0) return CHECK_ERROR(LastError()); if (n == 0) break; sz -= n; p += n; } strBuf.resize(bytes - sz); } if (strBuf.length() == 0) return CALL_RETURN_NULL; retVal = new Buffer(strBuf); return 0; }
FLACSource::FLACSource(const FLACModule &module, const std::shared_ptr<FILE> &fp): m_eof(false), m_giveup(false), m_initialize_done(false), m_length(0), m_position(0), m_fp(fp), m_module(module) { char buffer[33]; util::check_eof(util::nread(fileno(m_fp.get()), buffer, 33) == 33); if (std::memcmp(buffer, "ID3", 3) == 0) { uint32_t size = 0; for (int i = 6; i < 10; ++i) { size <<= 7; size |= buffer[i]; } CHECKCRT(_lseeki64(fileno(m_fp.get()), 10 + size, SEEK_SET) < 0); util::check_eof(util::nread(fileno(m_fp.get()), buffer, 33) == 33); } uint32_t fcc = util::fourcc(buffer); if ((fcc != 'fLaC' && fcc != 'OggS') || (fcc == 'OggS' && std::memcmp(&buffer[28], "\177FLAC", 5))) throw std::runtime_error("Not a FLAC file"); CHECKCRT(_lseeki64(fileno(m_fp.get()), 0, SEEK_SET) < 0); m_decoder = decoder_t(m_module.stream_decoder_new(), std::bind1st(std::mem_fun(&FLACSource::close), this)); TRYFL(m_module.stream_decoder_set_metadata_respond( m_decoder.get(), FLAC__METADATA_TYPE_VORBIS_COMMENT)); TRYFL(m_module.stream_decoder_set_metadata_respond( m_decoder.get(), FLAC__METADATA_TYPE_PICTURE)); TRYFL((fcc == 'OggS' ? m_module.stream_decoder_init_ogg_stream : m_module.stream_decoder_init_stream) (m_decoder.get(), staticReadCallback, staticSeekCallback, staticTellCallback, staticLengthCallback, staticEofCallback, staticWriteCallback, staticMetadataCallback, staticErrorCallback, this) == FLAC__STREAM_DECODER_INIT_STATUS_OK); TRYFL(m_module.stream_decoder_process_until_end_of_metadata( m_decoder.get())); if (m_giveup || m_asbd.mBitsPerChannel == 0) flac::want(false); m_buffer.set_unit(m_asbd.mChannelsPerFrame); m_initialize_done = true; }
i64 GetFileSize64(char *fileName) { i64 size; int fd=open(fileName,_O_RDONLY|_O_BINARY,0); if (fd==-1) return 0; _lseeki64(fd,0,SEEK_END); size=_telli64(fd); _lseeki64(fd,0,SEEK_SET); _close(fd); return size; }
jlong md_seek(int filedes, jlong pos) { jlong new_pos; if ( pos == (jlong)-1 ) { new_pos = _lseeki64(filedes, 0L, SEEK_END); } else { new_pos = _lseeki64(filedes, pos, SEEK_SET); } return new_pos; }
//----------------------------------------------------------------------------- // Purpose: Deletes any existing files from the pak file //----------------------------------------------------------------------------- void Pack_Clear(const char *pakfile) { // need to use 64-bit capable file I/O calls to handle the giant pack files int fh = _open(pakfile, _O_RDWR | _O_BINARY); if (fh == -1) { printf("Couldn't open pakfile '%s'\n", pakfile); exit(0); return; } // jump to the end of the file, see if it has a header packappenededheader_t appended; _lseeki64(fh, (long)(0 - sizeof(packappenededheader_t)), SEEK_END); _read(fh, &appended, sizeof(appended)); int64 iOriginalFileSize = _filelengthi64(fh); if (appended.id[0] == 'P' && appended.id[1] == 'A' && appended.id[2] == 'C' && appended.id[3] == 'K' && appended.id[4] == 'A' && appended.id[5] == 'P' && appended.id[6] == 'P' && appended.id[7] == 'E') { // we have an appended pack file, look up the header iOriginalFileSize = appended.originalfilesize; // kill any existing pack file assert(iOriginalFileSize >= 0 && iOriginalFileSize <= _filelengthi64(fh)); _chsize(fh, (long)iOriginalFileSize); } // create empty pak header & end signature packheader64_t header = { { 'P', 'K', '6', '4' }, 0, 0 }; packappenededheader_t appendheader = { { 'P', 'A', 'C', 'K', 'A', 'P', 'P', 'E' } }; _lseeki64(fh, 0, SEEK_END); appendheader.packheaderpos = _telli64(fh); appendheader.originalfilesize = iOriginalFileSize; _write(fh, &header, sizeof(header)); _write(fh, &appendheader, sizeof(appendheader)); assert( _filelengthi64(fh) == iOriginalFileSize + sizeof(header) + sizeof(appendheader) ); // finished clearing _close(fh); assert(Pack_Validate(pakfile)); }
void iiDisk_unlock_all(SThisCode* thisCode, SBuilder* lockRoot) { u32 lnI; SDiskLock* dl; // If it's a valid lock, unlock it for (lnI = 0, dl = (SDiskLock*)lockRoot->buffer; lnI < lockRoot->populatedLength; lnI += sizeof(SDiskLock), dl++) { // Is this one locked? if (dl->isValid) { // Seek if (_lseeki64(dl->nFile, dl->nOffset, SEEK_SET) == dl->nOffset) { // Unlock _locking(dl->nFile, _LK_UNLCK, dl->nLength); } else { // If we get here, the file is likely no longer open, so all locks are closed // But, we just silently fall through } // Indicate the lock is no longer valid dl->isValid = false; } } }
bool iiDisk_unlock(SThisCode* thisCode, SBuilder* lockRoot, SDiskLock* dl) { bool llResult; // If it's a valid lock, unlock it llResult = false; if (dl->isValid) { // Seek if (_lseeki64(dl->nFile, dl->nOffset, SEEK_SET) == dl->nOffset) { // Unlock llResult = (_locking(dl->nFile, _LK_UNLCK, dl->nLength) == 0); } else { // If we get here, the file is likely no longer open, so all locks are closed // But, we just silently fall through } // If cleared, indicate the lock is no longer valid dl->isValid = !llResult; } // Indicate success or failure return(llResult); }
/* A portable fseek() function return 0 on success, non-zero on failure (with errno set) */ int my_fseek (FILE *fp, my_off_t offset, int whence) { #if defined (HAVE_FSEEKO) && SIZEOF_OFF_T >= 8 return fseeko(fp, offset, whence); #elif defined (HAVE_FSEEK64) return fseek64(fp, offset, whence); #elif defined (__BEOS__) return _fseek(fp, offset, whence); #elif SIZEOF_FPOS_T >= 8 /* lacking a 64-bit capable fseek(), use a 64-bit capable fsetpos() and fgetpos() to implement fseek()*/ fpos_t pos; switch (whence) { case SEEK_END: #ifdef MS_WINDOWS fflush (fp); if (_lseeki64 (fileno(fp), 0, 2) == -1) return -1; #else if (fseek (fp, 0, SEEK_END) != 0) return -1; #endif /* fall through */ case SEEK_CUR: if (fgetpos (fp, &pos) != 0) return -1; offset += pos; break; /* case SEEK_SET: break; */ } return fsetpos(fp, &offset); #else #error "Large file support, but no way to fseek." #endif }
extern jlib_decl offset_t checked_lseeki64( int handle, offset_t offset, int origin ) { offset_t ret=_lseeki64(handle,offset,origin); if (ret==(offset_t)-1) throw makeErrnoException("checked_lseeki64"); return ret; }
__int64 xftell64 (FILE *f, const char *filename) { #if _MSC_VER > 1200 __int64 where; where = _ftelli64(f); if (where < (__int64)0) FATAL_PERROR(filename); #else __int64 where, filepos; int fd; fd = fileno(f); if(f->_cnt < 0) f->_cnt = 0; if((filepos = _lseeki64(fd, (__int64)0, SEEK_CUR)) < (__int64)0) { FATAL_PERROR(filename); return (__int64)(-1); } if(filepos == (__int64)0) where = (__int64)(f->_ptr - f->_base); else where = filepos - f->_cnt; #endif return where; }
int FastReadStream::_Commit(int stream, __int64 i64BlockNo) { int iCacheBlock; int i; // Already have the block? for(i=0; i<lBlockCount; i++) if (pHeaders[i].i64BlockNo == i64BlockNo) { pHeaders[i].fAccessedBits |= 1L<<stream; // _RPT1(0,"Commit(%I64d): cache hit\n", i64BlockNo); return i; } // Pick a replacement candidate. iCacheBlock = _PickVictim(stream); // Replace it. try { ++lHistory; // _RPT2(0,"Commit(%I64d): cache miss (stream %d)\n", i64BlockNo, stream); if (iFile >= 0) { int iActual; if (-1 == _lseeki64(iFile, i64BlockNo * lBlockSize, SEEK_SET)) throw MyError("FastRead seek error: %s.", strerror(errno)); iActual = _read(iFile, (char *)pBuffer + iCacheBlock * lBlockSize, lBlockSize); if (iActual < 0) throw MyError("FastRead read error: %s.", strerror(errno)); pHeaders[iCacheBlock].lBytes = iActual; } else { LONG lLow = (LONG)i64BlockNo*lBlockSize; LONG lHigh = (LONG)((i64BlockNo*lBlockSize) >> 32); DWORD err, dwActual; if (0xFFFFFFFF == SetFilePointer(hFile, lLow, &lHigh, FILE_BEGIN)) if ((err = GetLastError()) != NO_ERROR) throw MyWin32Error("FastRead seek error: %%s", GetLastError()); if (!ReadFile(hFile, (char *)pBuffer + iCacheBlock * lBlockSize, lBlockSize, &dwActual, NULL)) throw MyWin32Error("FastRead read error: %%s", GetLastError()); pHeaders[iCacheBlock].lBytes = dwActual; } pHeaders[iCacheBlock].i64BlockNo = i64BlockNo; pHeaders[iCacheBlock].fAccessedBits = 1L<<stream; pHeaders[iCacheBlock].lHistoryVal = lHistory; } catch(...) { pHeaders[iCacheBlock].i64BlockNo = -1; pHeaders[iCacheBlock].fAccessedBits = 0; } return iCacheBlock; }
void zmq::swap_t::fill_buf (char *buf, int64_t pos) { if (file_pos != pos) { #ifdef ZMQ_HAVE_WINDOWS __int64 offset = _lseeki64 (fd, pos, SEEK_SET); #else off_t offset = lseek (fd, (off_t) pos, SEEK_SET); #endif errno_assert (offset == pos); file_pos = pos; } size_t octets_stored = 0; size_t octets_total = std::min (block_size, (size_t) (filesize - file_pos)); while (octets_stored < octets_total) { #ifdef ZMQ_HAVE_WINDOWS int rc = _read (fd, &buf [octets_stored], octets_total - octets_stored); #else ssize_t rc = read (fd, &buf [octets_stored], octets_total - octets_stored); #endif errno_assert (rc > 0); octets_stored += rc; } file_pos += octets_total; }
void checkNode(int f, KeyHdr &h, offset_t thisnode) { _lseeki64(f, thisnode, SEEK_SET); char *nodeData = (char *) malloc(h.nodeSize); if (!nodeData || _read(f, nodeData, h.nodeSize) != h.nodeSize) { noteError(thisnode, "Could not read node (error %d)\n", errno); } else { NodeHdr &nodeHdr = *(NodeHdr *) nodeData; swap(nodeHdr); if ( nodeHdr.rightSib > h.phyrec || nodeHdr.leftSib > h.phyrec || nodeHdr.rightSib % h.nodeSize || nodeHdr.leftSib % h.nodeSize || nodeHdr.keyBytes == 0 || nodeHdr.keyBytes > h.nodeSize ) { noteError(thisnode, "Htree: Corrupt key node detected (keyBytes==%x)\n", nodeHdr.keyBytes ); } else if (nodeHdr.crc32 && checkCRC) { unsigned crc = mcrc32(nodeData+sizeof(NodeHdr), nodeHdr.keyBytes, 0); if (nodeHdr.crc32 != crc) { noteError(thisnode, "CRC error on key node (keyBytes==%x)\n", nodeHdr.keyBytes ); } } } free(nodeData); }
void zmq::swap_t::save_write_buf () { if (file_pos != write_buf_start_addr) { #ifdef ZMQ_HAVE_WINDOWS __int64 offset = _lseeki64 (fd, write_buf_start_addr, SEEK_SET); #else off_t offset = lseek (fd, (off_t) write_buf_start_addr, SEEK_SET); #endif errno_assert (offset == write_buf_start_addr); file_pos = write_buf_start_addr; } size_t octets_stored = 0; size_t octets_total = std::min (block_size, (size_t) (filesize - file_pos)); while (octets_stored < octets_total) { #ifdef ZMQ_HAVE_WINDOWS int rc = _write (fd, &write_buf [octets_stored], octets_total - octets_stored); #else ssize_t rc = write (fd, &write_buf [octets_stored], octets_total - octets_stored); #endif errno_assert (rc > 0); octets_stored += rc; } file_pos += octets_total; }
off_t rpl_lseek (int fd, off_t offset, int whence) { #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */ HANDLE h = (HANDLE) _get_osfhandle (fd); if (h == INVALID_HANDLE_VALUE) { errno = EBADF; return -1; } if (GetFileType (h) != FILE_TYPE_DISK) { errno = ESPIPE; return -1; } #else /* BeOS lseek mistakenly succeeds on pipes... */ struct stat statbuf; if (fstat (fd, &statbuf) < 0) return -1; if (!S_ISREG (statbuf.st_mode)) { errno = ESPIPE; return -1; } #endif #if _GL_WINDOWS_64_BIT_OFF_T return _lseeki64 (fd, offset, whence); #else return lseek (fd, offset, whence); #endif }
int ftruncate(int fd, int64_t length) { HANDLE fh = reinterpret_cast<HANDLE>(_get_osfhandle(fd)); if (!fh || _lseeki64(fd, length, SEEK_SET)) { return -1; } return SetEndOfFile(fh) ? 0 : -1; }
OS_Error OSFileSource::ReadFromDisk(void* inBuffer, UInt32 inLength, UInt32* outRcvLen) { #if FILE_SOURCE_BUFFTEST qtss_printf("OSFileSource::Read inLength=%" _U32BITARG_ " fFile=%d\n",inLength,fFile); #endif #if __Win32__ if (_lseeki64(fFile, fPosition, SEEK_SET) == -1) return OSThread::GetErrno(); #else if (lseek(fFile, fPosition, SEEK_SET) == -1) return OSThread::GetErrno(); #endif int rcvLen = ::read(fFile, (char*)inBuffer, inLength); if (rcvLen == -1) return OSThread::GetErrno(); if (outRcvLen != NULL) *outRcvLen = rcvLen; fPosition += rcvLen; fReadPos = fPosition; return OS_NoErr; }
static int ftruncate(int fd, __int64 length) { HANDLE fh = (HANDLE)_get_osfhandle(fd); if (!fh || _lseeki64(fd, length, SEEK_SET)) { return -1; } return SetEndOfFile(fh) ? 0 : -1; }
FLAC__StreamDecoderTellStatus FLACSource::tellCallback(uint64_t *offset) { int64_t off = _lseeki64(fileno(m_fp.get()), 0, SEEK_CUR); if (off < 0) return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; *offset = off; return FLAC__STREAM_DECODER_TELL_STATUS_OK; }
FLAC__StreamDecoderSeekStatus FLACSource::seekCallback(uint64_t offset) { m_eof = false; if (_lseeki64(fileno(m_fp.get()), offset, SEEK_SET) == offset) return FLAC__STREAM_DECODER_SEEK_STATUS_OK; else return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; }
/* XXX: use llseek */ static offset_t file_seek(URLContext *h, offset_t pos, int whence) { int fd = (size_t)h->priv_data; #if defined(__MINGW32__) return _lseeki64(fd, pos, whence); #else return lseek(fd, pos, whence); #endif }
/* XXX: use llseek */ static offset_t file_seek(URLContext *h, offset_t pos, int whence) { int fd = (size_t)h->priv_data; #if defined(CONFIG_WIN32) && !defined(__CYGWIN__) return _lseeki64(fd, pos, whence); #else return lseek(fd, pos, whence); #endif }
SDiskLock* iiDisk_lock_range(SThisCode* thisCode, SBuilder* lockRoot, s32 tnFile, s64 tnOffset, s32 tnLength, uptr tnExtra) { u32 lnI; SDiskLock* dl; ////////// // Iterate to find an empty slot ////// for (lnI = 0, dl = (SDiskLock*)lockRoot->buffer; lnI < lockRoot->populatedLength; lnI += sizeof(SDiskLock), dl++) { // Is this slot empty? if (!dl->isValid) break; // Yes } ////////// // When we get here, we have a slot or not ////// if (lnI >= lockRoot->populatedLength) { // Create a new one dl = (SDiskLock*)iBuilder_appendData(lockRoot, (cs8*)NULL, sizeof(SDiskLock)); // Note: disk members are all initialized to 0s } ////////// // Physically try the lock ////// dl->isValid = true; dl->nFile = tnFile; dl->nOffset = tnOffset; dl->nLength = 0; // Seek to the offset if (_lseeki64(tnFile, tnOffset, SEEK_SET) == tnOffset) { // Lock the bytes if (_locking(tnFile, _LK_NBLCK, tnLength) == 0) { // Indicate a successful lock dl->nLength = tnLength; } } else { // The length being 0 will indicate the lock failed // So we just let it fall through } ////////// // Indicate success or failure ////// return(dl); }
int __cdecl _fseeki64 ( #endif /* _MT */ FILE *str, __int64 offset, int whence ) { REG1 FILE *stream; _ASSERTE(str != NULL); /* Init stream pointer */ stream = str; if ( !inuse(stream) || ((whence != SEEK_SET) && (whence != SEEK_CUR) && (whence != SEEK_END)) ) { errno=EINVAL; return(-1); } /* Clear EOF flag */ stream->_flag &= ~_IOEOF; /* If seeking relative to current location, then convert to a seek relative to beginning of file. This accounts for buffering, etc. by letting fseek() tell us where we are. */ if (whence == SEEK_CUR) { offset += _ftelli64_lk(stream); whence = SEEK_SET; } /* Flush buffer as necessary */ _flush(stream); /* If file opened for read/write, clear flags since we don't know what the user is going to do next. If the file was opened for read access only, decrease _bufsiz so that the next _filbuf won't cost quite so much */ if (stream->_flag & _IORW) stream->_flag &= ~(_IOWRT|_IOREAD); else if ( (stream->_flag & _IOREAD) && (stream->_flag & _IOMYBUF) && !(stream->_flag & _IOSETVBUF) ) stream->_bufsiz = _SMALL_BUFSIZ; /* Seek to the desired locale and return. */ return(_lseeki64(_fileno(stream), offset, whence) == -1i64 ? -1 : 0); }
result_t File::rewind() { if (m_fd == -1) return CHECK_ERROR(CALL_E_INVALID_CALL); if (_lseeki64(m_fd, 0, SEEK_SET) < 0) return CHECK_ERROR(LastError()); return 0; }
unsigned countLevels(int f, KeyHdr &h, offset_t firstnode) { _lseeki64(f, firstnode, SEEK_SET); char *nodeData = (char *) malloc(h.nodeSize); if (!nodeData || _read(f, nodeData, h.nodeSize) != h.nodeSize) { noteError(firstnode, "Could not read node (error %d)\n", errno); free(nodeData); return 0; } else { NodeHdr &nodeHdr = *(NodeHdr *) nodeData; swap(nodeHdr); if (!nodeHdr.leafFlag) { unsigned __int64 fpos = *(unsigned __int64 *) (nodeData + sizeof(nodeHdr)); _WINREV(fpos); free(nodeData); return countLevels(f, h, fpos)+1; } else { free(nodeData); return 1; } } }