static void test_ftello (void) { FILE *f; int ret; off64_t pos; f = fopen64 (name, "w"); ret = fseeko64 (f, TWO_GB+100, SEEK_SET); if (ret == -1 && errno == ENOSYS) { error (0, 0, "fseeko64 is not supported."); exit (EXIT_SUCCESS); } if (ret == -1 && errno == EINVAL) { error (0, 0, "LFS seems not to be supported"); exit (EXIT_SUCCESS); } if (ret == -1) { error (0, errno, "fseeko64 failed with error"); exit (EXIT_FAILURE); } ret = fwrite ("Hello", 1, 5, f); if (ret == -1 && errno == EFBIG) { error (0, errno, "LFS seems not to be supported"); exit (EXIT_SUCCESS); } if (ret == -1 && errno == ENOSPC) { error (0, 0, "Not enough space to write file."); exit (EXIT_SUCCESS); } if (ret != 5) error (EXIT_FAILURE, errno, "Cannot write test string to large file"); pos = ftello64 (f); if (pos != TWO_GB+105) { error (0, 0, "ftello64 gives wrong result."); exit (EXIT_FAILURE); } fclose (f); }
void WriteThread::internalFlushAndSeekToZero() { flushBuffer(); if(fseeko64(file, 0, SEEK_SET)!=0) { errorString_internal=std::string(strerror(errno))+", errno: "+std::to_string(errno); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"["+std::to_string(id)+"] Unable to seek after open: "+fileName+", error: "+errorString_internal); emit error(); return; } stopIt=false; emit flushedAndSeekedToZero(); }
static wicedfs_usize_t hostfile_special_global_wicedfs_read( void* user_param, void* buf, wicedfs_usize_t size, wicedfs_usize_t pos ) { (void) user_param; /* Seek to the requested hardware location in the image file */ if ( 0 != fseeko64( image_file, (off64_t)(pos), SEEK_SET) ) { return 0; } /* Read the requested data from the image file */ return fread( buf, 1, (size_t)size, image_file ); }
void GCodeExport::replaceTagInStart(const char* tag, const char* replaceValue) { if (f == stdout) { log("Replace:%s:%s\n", tag, replaceValue); return; } off64_t oldPos = ftello64(f); char buffer[1024]; fseeko64(f, 0, SEEK_SET); fread(buffer, 1024, 1, f); char* c = strstr(buffer, tag); memset(c, ' ', strlen(tag)); if (c) memcpy(c, replaceValue, strlen(replaceValue)); fseeko64(f, 0, SEEK_SET); fwrite(buffer, 1024, 1, f); fseeko64(f, oldPos, SEEK_SET); }
double getTimeValue(SMOutputAPI* smoapi, long timeIndex) { F_OFF offset; double value; // --- compute offset into output file offset = smoapi->ResultsPos + timeIndex*smoapi->BytesPerPeriod; // --- re-position the file and read the result fseeko64(smoapi->file, offset, SEEK_SET); fread(&value, RECORDSIZE * 2, 1, smoapi->file); return value; }
inline BOOL ByteStreamIn::seek(const I64 position) { if (tell() != position) { #if defined _WIN32 && ! defined (__MINGW32__) return !(_fseeki64(file, position, SEEK_SET)); #elif defined (__MINGW32__) return !(fseeko64(file, (off_t)position, SEEK_SET)); #else return !(fseeko(file, (off_t)position, SEEK_SET)); #endif } return TRUE; }
void FileIO::Seek( const SeekAnchor anchor, const uint64_t offset, std::error_code * error ) { if (error) error->clear(); const int origin = [&anchor](){ switch(anchor) { case SeekAnchor::Current: return SEEK_CUR; break; case SeekAnchor::Beginning: return SEEK_SET; break; case SeekAnchor::End: return SEEK_END; break; default: assert(!"Invalid anchor"); return SEEK_CUR; }}(); #if defined(_WIN32) # if defined(_MSC_VER) const int res = _fseeki64(file_handle_, offset, origin); # else const int res = fseeko64(file_handle_, offset, origin); # endif #else const int res = fseeko(file_handle_, offset, origin); #endif if ( error != nullptr && res != 0 ) { if ( ferror(file_handle_) ) { *error = make_error_code(file_io_error::StreamError); } else { assert( ! "Unknown error in FileIO::Seek" ); *error = make_error_code(file_io_error::UnknownError); } } }
static bool patchApplyPPF3(FILE *f, u8 **rom, int *size) { fseek(f, 0, SEEK_END); int count = ftell(f); if (count < 56+4+1024) return false; count -= 56+4; fseek(f, 56, SEEK_SET); int imagetype = fgetc(f); int blockcheck = fgetc(f); int undo = fgetc(f); fgetc(f); u8 *mem = *rom; if (blockcheck) { u8 block[1024]; fread(&block, 1, 1024, f); if (memcmp(&mem[(imagetype == 0) ? 0x9320 : 0x80A0], &block, 1024) != 0) return false; count -= 1024; } int idlen = ppfFileIdLen(f, 2); if (idlen > 0) count -= 16 + 16 + idlen; fseek(f, 56+4+(blockcheck ? 1024 : 0), SEEK_SET); while (count > 0) { __off64_t offset = readInt8(f); if (offset == -1) break; int len = fgetc(f); if (len == EOF) break; if (offset+len > *size) break; if (fread(&mem[offset], 1, len, f) != (size_t)len) break; if (undo) fseeko64(f, len, SEEK_CUR); count -= 8 + 1 + len; if (undo) count -= len; } return (count == 0); }
static int iso_readtoc(unsigned char *b, unsigned char starttrack, int msf) { int len=4; int blocks; if (iso_empty) return 0; fseeko64(iso_file, 0, SEEK_END); blocks = (int) (ftello64(iso_file) / 2048); if (starttrack <= 1) { b[len++] = 0; // Reserved b[len++] = 0x14; // ADR, control b[len++] = 1; // Track number b[len++] = 0; // Reserved // Start address if (msf) { b[len++] = 0; // reserved b[len++] = 0; // minute b[len++] = 2; // second b[len++] = 0; // frame } else { b[len++] = 0; b[len++] = 0; b[len++] = 0; b[len++] = 0; // logical sector 0 } } b[2]=b[3]=1; /*First and last track numbers*/ b[len++] = 0; // Reserved b[len++] = 0x16; // ADR, control b[len++] = 0xaa; // Track number b[len++] = 0; // Reserved if (msf) { b[len++] = 0; // reserved b[len++] = (uint8_t)(((blocks + 150) / 75) / 60); // minute b[len++] = (uint8_t)(((blocks + 150) / 75) % 60); // second b[len++] = (uint8_t)((blocks + 150) % 75); // frame; } else { b[len++] = (uint8_t)((blocks >> 24) & 0xff); b[len++] = (uint8_t)((blocks >> 16) & 0xff); b[len++] = (uint8_t)((blocks >> 8) & 0xff); b[len++] = (uint8_t)((blocks >> 0) & 0xff); } b[0] = (uint8_t)(((len-4) >> 8) & 0xff); b[1] = (uint8_t)((len-4) & 0xff); return len; }
void object::test<8>() { string stmpfile(TOP_BUILD_DIR); stmpfile += "/lt.test8.log"; const char *filename = stmpfile.c_str(); unlink(filename); FILE *file = fopen64(filename, "w"); fseeko64(file, 3*1024*1024*1024L, SEEK_SET); fwrite("end", 1, 3, file); fclose(file); Logger *root = alog::Logger::getRootLogger(); root->setAppender(alog::FileAppender::getAppender(filename)); root->log(LOG_LEVEL_ERROR,"test8"); Logger::shutdown(); unlink(filename); }
void tmd_process(tmd_context* ctx, u32 actions) { if (ctx->buffer == 0) ctx->buffer = malloc(ctx->size); if (ctx->buffer) { fseeko64(ctx->file, ctx->offset, SEEK_SET); fread(ctx->buffer, 1, ctx->size, ctx->file); if (actions & InfoFlag) { tmd_print(ctx); } } }
typedef struct { } /* Standard Linux driver, will read very large Harddrives. As long as drive doesn't exceed 2TB. */ signed int test(unsigned char *buffer, unsigned long sector, unsigned short sectors, void *pParam) { off64_t address; address = (off64_t) sector * 512; fseeko64(pParam, address, 0); fread(buffer, 512, sectors, pParam); return sectors; }
bool CXBTFReader::Load(const CXBTFFrame& frame, unsigned char* buffer) const { if (m_file == nullptr) return false; #if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_ANDROID) if (fseeko(m_file, static_cast<off_t>(frame.GetOffset()), SEEK_SET) == -1) #else if (fseeko64(m_file, static_cast<off_t>(frame.GetOffset()), SEEK_SET) == -1) #endif return false; if (fread(buffer, 1, static_cast<size_t>(frame.GetPackedSize()), m_file) != frame.GetPackedSize()) return false; return true; }
float getNodeValue(SMOutputAPI* smoapi, long timeIndex, int nodeIndex, SMO_nodeAttribute attr) { F_OFF offset; float value; // --- compute offset into output file offset = smoapi->ResultsPos + timeIndex*smoapi->BytesPerPeriod + 2 * RECORDSIZE; // offset for node offset += RECORDSIZE*(smoapi->Nsubcatch*smoapi->SubcatchVars + nodeIndex*smoapi->NodeVars + attr); // --- re-position the file and read the result fseeko64(smoapi->file, offset, SEEK_SET); fread(&value, RECORDSIZE, 1, smoapi->file); return value; }
int64_t CoreIOReader::Length() { CoreAssert(this != NULL); CoreAssert(IsOpen()); #ifndef __GNUC__ MutexHolder mh(&m_ioMutex); #endif #ifdef HAS_FPOS64 fpos64_t lastpos, endpos; #if defined(TARGET_COMPILER_VC) || defined(TARGET_COMPILER_BORLAND) || \ (defined(TARGET_COMPILER_ICC) && defined(TARGET_OS_WINDOWS)) lastpos = _ftelli64(m_fileInputPointer); _fseeki64(m_fileInputPointer, 0, SEEK_END); endpos = _ftelli64(m_fileInputPointer); _fseeki64(m_fileInputPointer, lastpos, SEEK_SET); #elif defined (TARGET_OS_MACOSX) || defined (TARGET_OS_NETBSD) || \ defined (TARGET_OS_FREEBSD) || defined (TARGET_OS_OPENBSD) || \ defined (TARGET_COMPILER_MINGW) fgetpos(m_fileInputPointer, &lastpos); fseek(m_fileInputPointer, 0, SEEK_END); fgetpos(m_fileInputPointer, &endpos); fsetpos(m_fileInputPointer, &lastpos); #else fgetpos64(m_fileInputPointer, &lastpos); fseeko64(m_fileInputPointer, 0, SEEK_END); fgetpos64(m_fileInputPointer, &endpos); fsetpos64(m_fileInputPointer, &lastpos); #endif #else fpos_t lastpos, endpos; lastpos = ftell(m_fileInputPointer); fseek(m_fileInputPointer, 0, SEEK_END); endpos = ftell(m_fileInputPointer); fseek(m_fileInputPointer, lastpos, SEEK_SET); #endif #if defined (TARGET_OS_WINDOWS) || defined (TARGET_OS_MACOSX) || defined (TARGET_OS_FREEBSD) || \ defined (TARGET_OS_NETBSD) || defined (TARGET_OS_OPENBSD) || defined (TARGET_COMPILER_CYGWIN) || \ defined (TARGET_OS_NDSFIRMWARE) return endpos; #elif defined (TARGET_OS_LINUX) return endpos.__pos; #endif }
signed int fnRead(unsigned char *buffer, unsigned long sector, unsigned short sectors, BLK_DEV_LINUX pDevice) { unsigned long long address; unsigned long Read; address = (unsigned long long) sector * pDevice->BlockSize; FF_PendSemaphore(pDevice->AccessSem); { fseeko64(pDevice->pDevice, address, 0); Read = fread(buffer, pDevice->BlockSize, sectors, pDevice->pDevice); } FF_ReleaseSemaphore(pDevice->AccessSem); read_inc(); return Read / pDevice->BlockSize; }
void replaceFirstItem(char *file, char *tempFile) { FILE * source = fopen64(file,"r"); checkIfNull(source); FILE * destination = fopen64(tempFile,"r+"); checkIfNull(destination); unsigned long val; while(fread(&val, sz ,1,source)!=0){ fwrite(&val,sz,1,destination); fseeko64(destination,sz,SEEK_CUR); } checkIfNotZero(fclose(source)); checkIfNotZero(fclose(destination)); }
/** Read function provided to WicedFS * * This reads data from the hardware device (a local host file) * * @param[in] user_param - The user_param value passed when wicedfs_init was called (use for hardware device handles) * @param[out] buf - The buffer to be filled with data * @param[in] size - The number of bytes to read * @param[in] pos - Absolute hardware device location to read from * * @return Number of bytes successfully read (i.e. 0 on failure) */ static wicedfs_usize_t hostfile_wicedfs_read( void* user_param, void* buf, wicedfs_usize_t size, wicedfs_usize_t pos ) { wicedfs_usize_t result; if ( bad_read_countdown == 0 ) { bad_read_countdown--; return 0; } if ( bad_read_countdown != -1 ) { bad_read_countdown--; } if ( short_read_countdown == 0 ) { short_read_countdown--; return (size>0)? size-1 : 0; } if ( short_read_countdown != -1 ) { short_read_countdown--; } /* Seek to the requested hardware location in the image file */ if ( 0 != fseeko64( (FILE*)user_param, (off64_t)(pos), SEEK_SET) ) { return 0; } /* Read the requested data from the image file */ result = fread( buf, 1, (size_t)size, (FILE*)user_param ); if ( ( corruption_countdown >= 0 ) && ( corruption_countdown < (int)size ) ) { ((unsigned char*)buf)[ corruption_countdown ] |= (unsigned char)0xa5; corruption_countdown = -1; } if ( corruption_countdown != -1 ) { short_read_countdown -= (int)size; } return result; }
static Sint64 SDLCALL stdio_seek(SDL_RWops * context, Sint64 offset, int whence) { #ifdef HAVE_FSEEKO64 if (fseeko64(context->hidden.stdio.fp, (off64_t)offset, whence) == 0) { return ftello64(context->hidden.stdio.fp); } #elif defined(HAVE_FSEEKO) if (fseeko(context->hidden.stdio.fp, (off_t)offset, whence) == 0) { return ftello(context->hidden.stdio.fp); } #else if (fseek(context->hidden.stdio.fp, offset, whence) == 0) { return (ftell(context->hidden.stdio.fp)); } #endif return SDL_Error(SDL_EFSEEK); }
signed int fnWrite(unsigned char *buffer, unsigned long sector, unsigned short sectors, BLK_DEV_LINUX pDevice) { unsigned long long address; unsigned long Written; address = (unsigned long long) sector * pDevice->BlockSize; FF_PendSemaphore(pDevice->AccessSem); { fseeko64(pDevice->pDevice, address, 0); Written = fwrite(buffer, pDevice->BlockSize, sectors, pDevice->pDevice); } FF_ReleaseSemaphore(pDevice->AccessSem); write_inc(); return Written / pDevice->BlockSize; }
std::streampos FileOutputStreambuf::seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode /*which*/) { int whence = way == std::ios_base::beg ? SEEK_SET : way == std::ios_base::cur ? SEEK_CUR : SEEK_END; if (way != std::ios_base::cur || off != 0) sync(); #if _WIN32 return _fseeki64(_file.get(), off, whence) == 0 ? _ftelli64(_file.get()) : -1; #elif __APPLE__ return fseeko(_file.get(), off, whence) == 0 ? ftello(_file.get()) : -1; #else return fseeko64(_file.get(), off, whence) == 0 ? ftello64(_file.get()) : -1; #endif }
void writeSolution(char * inputFile) { FILE * source = fopen64(tempFile,"r"); checkIfNull(source); FILE * destination = fopen64(inputFile,"r+"); checkIfNull(destination); unsigned long val; while(fread(&val, sz ,1,source)!=0){ fwrite(&val,sz,1,destination); fseeko64(source,sz,SEEK_CUR); } checkIfNotZero(fclose(source)); checkIfNotZero(fclose(destination)); remove(tempFile); }
void initElementNames(SMOutputAPI* smoapi) { int j, numNames; numNames = smoapi->Nsubcatch + smoapi->Nnodes + smoapi->Nlinks + smoapi->Npolluts; // allocate memory for array of idEntries smoapi->elementNames = (idEntry*)calloc(numNames, sizeof(idEntry)); // Position the file to the start of the ID entries fseeko64(smoapi->file, smoapi->IDPos, SEEK_SET); for(j=0;j<numNames;j++) { fread(&(smoapi->elementNames[j].length), RECORDSIZE, 1, smoapi->file); smoapi->elementNames[j].IDname = calloc(smoapi->elementNames[j].length + 1, sizeof(char)); fread(smoapi->elementNames[j].IDname, sizeof(char), smoapi->elementNames[j].length, smoapi->file); } }
int isLargeFile(const char* filename) { int largeFile = 0; ZPOS64_T pos = 0; FILE* pFile = fopen64(filename, "rb"); if (pFile != NULL) { int n = fseeko64(pFile, 0, SEEK_END); pos = ftello64(pFile); if (pos >= 0xffffffff) largeFile = 1; fclose(pFile); } return largeFile; }
void del_file_buffer(file_buffer *fb, int restore) { custom *cust = (custom *) fb->custom; munmap(cust->memmap, fb->size); if (restore == RESTORE_INITIAL) { /* XXX Is this necessary? Has the file position moved? */ /* No, it should not have moved... */ //fseeko64(fb->file, fb->initial_file_pos, SEEK_SET); } else if (restore == RESTORE_FINAL) { printf("del_file_buffer: current_pos = %lld\n", cust->current_pos); fseeko64(fb->file, cust->current_pos, SEEK_SET); } free(cust); free(fb); }
TEST(STDIO_TEST, seek_tell_family_smoke) { TemporaryFile tf; FILE* fp = fdopen(tf.fd, "w+"); // Initially we should be at 0. AssertFileOffsetAt(fp, 0); // Seek to offset 8192. ASSERT_EQ(0, fseek(fp, 8192, SEEK_SET)); AssertFileOffsetAt(fp, 8192); fpos_t eight_k_pos; ASSERT_EQ(0, fgetpos(fp, &eight_k_pos)); // Seek forward another 8192... ASSERT_EQ(0, fseek(fp, 8192, SEEK_CUR)); AssertFileOffsetAt(fp, 8192 + 8192); fpos64_t sixteen_k_pos64; ASSERT_EQ(0, fgetpos64(fp, &sixteen_k_pos64)); // Seek back 8192... ASSERT_EQ(0, fseek(fp, -8192, SEEK_CUR)); AssertFileOffsetAt(fp, 8192); // Since we haven't written anything, the end is also at 0. ASSERT_EQ(0, fseek(fp, 0, SEEK_END)); AssertFileOffsetAt(fp, 0); // Check that our fpos64_t from 16KiB works... ASSERT_EQ(0, fsetpos64(fp, &sixteen_k_pos64)); AssertFileOffsetAt(fp, 8192 + 8192); // ...as does our fpos_t from 8192. ASSERT_EQ(0, fsetpos(fp, &eight_k_pos)); AssertFileOffsetAt(fp, 8192); // Do fseeko and fseeko64 work too? ASSERT_EQ(0, fseeko(fp, 1234, SEEK_SET)); AssertFileOffsetAt(fp, 1234); ASSERT_EQ(0, fseeko64(fp, 5678, SEEK_SET)); AssertFileOffsetAt(fp, 5678); fclose(fp); }
size_t SUFFIX(CBedFile)::ReadLine( BYTE *pb, size_t idx ) { long long fpos = cbHeader + (idx*cbStride); #ifdef _WIN32 long long fposCur = _ftelli64( pFile ); #else long long fposCur = ftello64( pFile ); #endif if ( fpos != fposCur ) { #ifdef _WIN32 _fseeki64( pFile, fpos, SEEK_SET ); #else fseeko64( pFile, fpos, SEEK_SET ); #endif } size_t cbRead = Read( pb, cbStride ); return( cbRead ); }
// Implementation of Seek result_t CFile::Seek(int64_t offset, FileSeekOrigin origin, uint64_t* pcb) { #ifdef _MSC_VER if (_fseeki64(m_pFile, offset, origin)!=0) return ResultFromErrno(errno); if (pcb) *pcb=_ftelli64(m_pFile); #else if (fseeko64(m_pFile, offset, origin)!=0) return ResultFromErrno(errno); if (pcb) *pcb=ftello64(m_pFile); #endif return 0; }
void tik_process(tik_context* ctx, u32 actions) { if (ctx->size < sizeof(eticket)) { fprintf(stderr, "Error, ticket size too small\n"); goto clean; } fseeko64(ctx->file, ctx->offset, SEEK_SET); fread((u8*)&ctx->tik, 1, sizeof(eticket), ctx->file); tik_decrypt_titlekey(ctx, ctx->titlekey); if (actions & InfoFlag) { tik_print(ctx); } clean: return; }
int MyWidget::getpartscount(FILE *f) { u_int8_t read_data; int current = 0, count = 1; while (fread(&read_data, sizeof(uint8_t), 1, f) == 1) { if(read_data == 0x47) { if(current == 0) partstarts.push_back(ftello64(f) - 1); fseeko64(f, 187L, SEEK_CUR); if(++current == 100000) { count++; current = 0; } } } return count; }