Example #1
0
///Gets a file length.
__int64 XTail::getFileLength(LPWSTR fileName)
{
	len = 0;

	filename = fileName;

	FILE *file;
	//file.open(fileName, ios::in | ios::binary);
	if (_wfopen_s(&file, fileName, L"rb") != 0)
	//if (file.bad() || file.fail())
		goto exit;

	//file.seekg(0, ios::beg);
	if (_fseeki64(file, 0, SEEK_SET) != 0)
		goto exit;
	//streamoff begin = file.tellg();
	__int64 begin = _ftelli64(file);

	//file.seekg(0, ios::end);
	if (_fseeki64(file, 0, SEEK_END) != 0)
		goto exit;
	//streamoff end = file.tellg();
	__int64 end = _ftelli64(file);

	len = end - begin;
	
exit:
	//if (file.is_open())
	//	file.close();
	if (file)
		fclose(file);

	return len;

}
Example #2
0
int set_scroll_pos(HWND hwnd,int ctrl,FILE *f)
{
	int result=FALSE;
	double p;
	__int64 size,offset;
	int pos;
	if(f==0)
		return result;
	offset=_ftelli64(f);
	_fseeki64(f,0,SEEK_END);
	size=_ftelli64(f);
	if(size==0){
		SendDlgItemMessage(hwnd,ctrl,SBM_SETPOS,0,TRUE);
		return result;
	}
	_fseeki64(f,offset,SEEK_SET);
	p=(double)offset/(double)size;
	p*=10000;
	pos=(int)floor(p);
	if(pos>10000)
		pos=10000;
	scroll_pos=pos;
	SendDlgItemMessage(hwnd,ctrl,SBM_SETPOS,pos,TRUE);
	result=TRUE;
	return result;
}
Example #3
0
//---------------------------------------------------------------------
size_t TFile::Size()
{
	if (m_stream==NULL) return -1;
	switch(m_StorageType){
	case 0:
		{
			LONG_PTR pos,size;
#ifdef WIN64
			pos = _ftelli64(static_cast<FILE*>(m_stream));
			_fseeki64(static_cast<FILE*>(m_stream),0,SEEK_END);
			size = _ftelli64(static_cast<FILE*>(m_stream));
			_fseeki64(static_cast<FILE*>(m_stream),pos,SEEK_SET);
#else
			pos = ftell(static_cast<FILE*>(m_stream));
			fseek(static_cast<FILE*>(m_stream),0,SEEK_END);
			size = ftell(static_cast<FILE*>(m_stream));
			fseek(static_cast<FILE*>(m_stream),pos,SEEK_SET);
#endif
			return static_cast<size_t>(size);
		}
	case 1:
		return m_Size;
	}
	return -1;
}
Example #4
0
int process_cut_chunk_data( FILE * fin, FILE * fout, int chunk_index,
	uint32_t chunkfrom, uint32_t sync_chunkTo,uint32_t sampleFrom, 
	uint32_t sync_to_chunk_offset, uint32_t sync_to,int num ,CMp4_root_box root) 
{
	int i=0;
	if (chunk_index+1==chunkfrom)
	{
		uint32_t sample_num_in_cur_chunk_
			= get_sample_num_in_cur_chunk(root.sc[num], chunk_index+1);  //@a mark获取chunk中sample的数目
		uint32_t sample_index_
			= get_sample_index(root.sc[num], chunk_index+1);//chunk中第一个sample的序号
		_fseeki64(fin,root.co[num].chunk_offset_from_file_begin[chunk_index],SEEK_SET);
		unsigned int sam_off=_ftelli64(fin);
		for (int a=sample_index_;a<sampleFrom;a++)
		{
			uint32_t sample_size_ = get_sample_size(root.sz[num], a);//获取当前sample的大小
			//int buf=sample_size_+4;
			_fseeki64(fin,sam_off,SEEK_SET);
			char *ptr1=new char [sample_size_];
			fread(ptr1, sample_size_, 1, fin);
			fwrite(ptr1, sample_size_, 1, fout);
			delete [] ptr1;
			sam_off+=sample_size_;
		}
	}
	if (chunk_index+1==sync_chunkTo&&sync_chunkTo!=root.co[num].chunk_offset_amount)
	{
		uint32_t sample_num_in_cur_chunk_
			= get_sample_num_in_cur_chunk(root.sc[num], chunk_index+1);  //@a mark获取chunk中sample的数目
		uint32_t sample_index_
			= get_sample_index(root.sc[num], chunk_index+1);//chunk中第一个sample的序号
		_fseeki64(fin,sync_to_chunk_offset,SEEK_SET);
		unsigned int to_off=_ftelli64(fin);
		if (sync_to!=root.sz[num].table_size)
		{
			for (int a=sync_to;a<sample_index_+sample_num_in_cur_chunk_;a++)
			{
				uint32_t sample_size_ = get_sample_size(root.sz[num], a);//获取当前sample的大小
				_fseeki64(fin,to_off,SEEK_SET);
				char *ptr1=new char [sample_size_];
				fread(ptr1, sample_size_, 1, fin);
				fwrite(ptr1, sample_size_, 1, fout);
				delete [] ptr1; 
				to_off+=sample_size_;
			}
		}

		i=1;
	}
	return i;
}
Example #5
0
bool MkvReader::GetFileSize() {
  if (m_file == NULL)
    return false;
#ifdef _MSC_VER
  int status = _fseeki64(m_file, 0L, SEEK_END);

  if (status)
    return false;  // error

  m_length = _ftelli64(m_file);
#else
  fseek(m_file, 0L, SEEK_END);
  m_length = ftell(m_file);
#endif
  assert(m_length >= 0);

  if (m_length < 0)
    return false;

#ifdef _MSC_VER
  status = _fseeki64(m_file, 0L, SEEK_SET);

  if (status)
    return false;  // error
#else
  fseek(m_file, 0L, SEEK_SET);
#endif

  return true;
}
Example #6
0
static opus_int64 op_ftell(void *_stream){
#if defined(_MSC_VER)
  return _ftelli64((FILE *)_stream);
#else
  return ftello((FILE *)_stream);
#endif
}
Example #7
0
static void* read_image(const char* src, size_t* size)
{
	int success = 0;
	void* a = NULL;
	INT64 src_size;
	FILE* fsrc = fopen(src, "rb");

	if (!fsrc)
	{
		fprintf(stderr, "Failed to open file %s\n", src);
		goto cleanup;
	}

	if (_fseeki64(fsrc, 0, SEEK_END))
	{
		fprintf(stderr, "Failed to seek to file end\n");
		goto cleanup;
	}

	src_size = _ftelli64(fsrc);
	if (src_size < 0)
	{
		fprintf(stderr, "Invalid file position %"PRId64"\n", src_size);
		goto cleanup;
	}
	if (_fseeki64(fsrc, 0, SEEK_SET))
	{
		fprintf(stderr, "Failed to seek to SEEK_SET\n");
		goto cleanup;
	}

	a = malloc((size_t)src_size);

	if (!a)
	{
		fprintf(stderr, "Failed malloc %"PRId64" bytes\n", src_size);
		goto cleanup;
	}

	if (fread(a, sizeof(char), (size_t)src_size, fsrc) != (size_t)src_size)
	{
		fprintf(stderr, "Failed read %"PRId64" bytes\n", src_size);
		goto cleanup;
	}

	success = 1;
	*size = src_size;
cleanup:

	if (a && !success)
	{
		free(a);
		a = NULL;
	}

	if (fsrc)
		fclose(fsrc);

	return a;
}
Example #8
0
// FileIO_Std::Tell()
off_t FileIO_Std::Tell() {
#ifdef _MSC_VER
	return _ftelli64(fp_);
#else
  return ftello(fp_);
#endif
}
Example #9
0
CMp4_trak_box CMp4_trak_box::mp4_read_trak_box(FILE *f, int size)
{
	printf("\t+%s\n", "trak");
	CMp4_trak_box trak;
	//trak  = new struct mp4_trak_box;
	trak.size= size;
	trak.type= ('t' | 'r'<<8 | 'a'<<16 | 'k'<<24);
	int k = 0;                                  \
	unsigned char p[5];                         \
	int inner_size = 0;

	int box_size= 0;
	unsigned int cur_pos= _ftelli64(f) ;
	do{
		_fseeki64(f, cur_pos, SEEK_SET);

		box_size= read_uint32_lit(f);
		fread(p, 4, 1, f);
		p[4]= 0;
		std::string name= (char*)p;
		if(name == "tkhd") {
			CMp4_tkhd_box tkhd;
			trak.tkhd= tkhd.mp4_read_tkhd_box(f, box_size);
		}
		else if(name == "mdia"){
			CMp4_mdia_box mdia;
			trak.mdia= mdia.mp4_read_mdia_box(f, box_size);
		} 
		cur_pos    += box_size;
		inner_size += box_size;
	} while(inner_size+8 < size);

	return trak;
}
Example #10
0
  bool PreprocessPBF::GetPos(FILE* file,
                             FileOffset& pos) const
  {
#if defined(__WIN32__) || defined(WIN32)
    const __int64 filepos=_ftelli64(file);

    if (filepos==-1) {
      return false;
    }
    else {
      pos=(FileOffset)filepos;
    }
#elif defined(HAVE_FSEEKO)
    off_t filepos=ftello(file);

    if (filepos==-1) {
      return false;
    }
    else {
      pos=(FileOffset)filepos;
    }
#else
    long filepos=ftell(file);

    if (filepos==-1) {
      return false;
    }
    else {
      pos=(FileOffset)filepos;
    }
#endif

    return true;
  }
Example #11
0
CMp4_stss_box CMp4_stss_box::mp4_read_stss_box(FILE *f, int size)  //level 8  关键帧列表
{
    CMp4_stss_box box_ss;
    printf("\t\t\t\t\t+%s\n", "stss");
    box_ss.size= size;
    box_ss.type= 's'|'t'<<8|'s'<<16|'s'<<24;
    box_ss.version= read_uint8(f);
    fread(box_ss.flags, sizeof(box_ss.flags), 1, f);
    box_ss.number_of_entries = read_uint32_lit(f);//关键帧的数目

    printf("\t\t\t\t\t\t\tflags: %u\n",
           box_ss.flags[0]|box_ss.flags[1]|box_ss.flags[2]);
    printf("number of entries: %u\n",box_ss.number_of_entries);

    printf("entries:\n");
    box_ss.sync_sample_table = new uint32_t[box_ss.number_of_entries];
    unsigned int cur_pos=_ftelli64(f);
    for(int i =0; i < box_ss.number_of_entries; ++i) {
        _fseeki64(f,cur_pos,SEEK_SET);
        box_ss.sync_sample_table[i] = read_uint32_lit(f);//关键帧的序号
        /*	if (i<10)*/
        //{
        printf("%6u ", box_ss.sync_sample_table[i]);
        if( (i)%10 == 0)printf("\n");
        //}

        cur_pos+=4;
    }
    printf("\n");

    return box_ss;
}
Example #12
0
size_t xiFile::GetPos() const {
#if defined( __WIN_API__ ) && defined ( __X64__ )
	return _ftelli64( ( FILE * )file );
#else
	return ftell( ( FILE * )file );
#endif
}
Example #13
0
/*--------------------------------------------------------------------------*/
void C2F(mtell) (int *fd, double *offset, int *err)
{     
	FILE *fa= GetFileOpenedInScilab(*fd);
	if ( fa == (FILE *) 0 ) 
	{
		char *filename = GetFileNameOpenedInScilab(*fd);
		if (filename)
		{
			sciprint(_("%s: Error while opening, reading or writing '%s'.\n"),"mtell",filename);
		}
		else
		{
			sciprint(_("%s: Error while opening, reading or writing.\n"),"mtell");
		}
		
		*err=1;
		return;
	}
	*err = 0;
	#ifdef _MSC_VER
		#if _WIN64 
			*offset = (double) _ftelli64(fa) ;
		#else
			*offset = (double) ftell(fa) ;
		#endif
	#else
	*offset = (double) ftell(fa) ;
	#endif
}
Example #14
0
void copy_chunk_data(FILE *fin,
	const uint32_t chunk_index,  //[0, end) 标识为第几个Chunk
	FILE *fout,  
	int num,
	CMp4_root_box root
	)
{
	_fseeki64(fin, root.co[num].chunk_offset_from_file_begin[chunk_index],
		SEEK_SET);

	//获取当前chunk中有多少个sample
	uint32_t sample_num_in_cur_chunk_ = get_sample_num_in_cur_chunk(root.sc[num], chunk_index+1);  //@a mark获取chunk中sample的数目
	uint32_t sample_index_ =  get_sample_index(root.sc[num], chunk_index+1);//chunk中第一个sample的序号
	unsigned int cur=_ftelli64(fin);
	for(int i = 0; i < sample_num_in_cur_chunk_; i++)
	{
		uint32_t sample_size_ = get_sample_size(root.sz[num], sample_index_+i);//获取当前sample的大小
		_fseeki64(fin,cur,SEEK_SET);
		char *ptr=new char [sample_size_];
		fread(ptr, sample_size_, 1, fin);
		fwrite(ptr, sample_size_, 1, fout);
		delete [] ptr;
		cur+=sample_size_;
	}
}
Example #15
0
CMp4_stco_box CMp4_stco_box::mp4_read_stco_box(FILE *f, int size)//定义了每个thunk在媒体流中的位置
{
	CMp4_stco_box box_co;
	printf("\t\t\t\t\t+%s\n", "stco");  
	box_co.size=size;
	box_co.type= 's'|'t'<<8|'c'<<16|'o'<<24;
	box_co.version= read_uint8(f);
	fread(box_co.flags, sizeof(box_co.flags), 1, f);
	box_co.chunk_offset_amount= read_uint32_lit(f);
	printf("chunk offest amount: %u\n",
		box_co.chunk_offset_amount);
	printf("chunk offset:\n");
	box_co.chunk_offset_from_file_begin = new uint32_t[box_co.chunk_offset_amount];
	unsigned int cur_pos=_ftelli64(f);
	for(int i = 0 ; i < box_co.chunk_offset_amount; i++){
		_fseeki64(f,cur_pos,SEEK_SET);
		box_co.chunk_offset_from_file_begin[i] = read_uint32_lit(f);
		cur_pos+=4;
	}
	for (int i=0;i<30;i++)
	{
		std::cout<<box_co.chunk_offset_from_file_begin[i]<<"  ";
		if((i+1) % 10 == 0) printf("\n");
	}
	return box_co;
}
Example #16
0
		int64_t CoreIOReader::Position()
		{
			CoreAssert(this != NULL);
			CoreAssert(IsOpen());
#ifdef HAS_FPOS64
			fpos64_t lastpos;
#if defined(TARGET_COMPILER_VC) || defined(TARGET_COMPILER_BORLAND) || \
	(defined(TARGET_COMPILER_ICC) && defined(TARGET_OS_WINDOWS))
			lastpos = _ftelli64(m_fileInputPointer);
			return lastpos;
#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);
			return lastpos;
#else
			fgetpos64(m_fileInputPointer, &lastpos);
			return lastpos.__pos;
#endif
#else
			fpos_t lastpos;
			lastpos = ftell(m_fileInputPointer);
			return lastpos;
#endif
		}
Example #17
0
CMp4_stsc_box CMp4_stsc_box::mp4_read_stsc_box(FILE *f, int size)  //level 8
{
	CMp4_stsc_box box_sc;
	box_sc.size=size;
	box_sc.type= 's'|'t'<<8|'s'<<16|'c'<<24;
    printf("\t\t\t\t\t+%s\n", "stsc");
	box_sc.version    = read_uint8(f);
    fread(&box_sc.flags, sizeof(box_sc.flags), 1, f);
    box_sc.map_amount = read_uint32_lit(f);//sample-to-chunk 的数目
   
    printf("map-amount: %u\n", box_sc.map_amount);
    
    box_sc.scmap= new mp4_list_t[box_sc.map_amount];
    printf("first chunk:\tsamples-per-chunk:\tsample-description-ID\n");
	/*这个表类似于行程编码,第一个first chunk 减去第二个first chunk 就是一共有多少个trunk
	包含相同的sample 数目,这样通过不断的叠加,就可以得到一共有多少个chunk,每个chunk 包含多
	少个sample,以及每个chunk 对应的description。*/
	unsigned int cur_pos=_ftelli64(f);
	for(int i = 0; i < box_sc.map_amount; ++i){
		_fseeki64(f,cur_pos,SEEK_SET);
        box_sc.scmap[i].first_chunk_num = read_uint32_lit(f);
        box_sc.scmap[i].sample_amount_in_cur_table = read_uint32_lit(f);
        box_sc.scmap[i].sample_description_id = read_uint32_lit(f);
		cur_pos+=12;
    }
	for (int i=0;i<10;i++)
	{
         printf("%13d", box_sc.scmap[i].first_chunk_num);
         printf("\t%13d", box_sc.scmap[i].sample_amount_in_cur_table);
         printf("\t%13d\n", box_sc.scmap[i].sample_description_id);
	}
	std::cout<<"stsc:chunk_num="<<box_sc.scmap[box_sc.map_amount-1].first_chunk_num<<std::endl;
    return box_sc;
}
Example #18
0
__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;
}
Example #19
0
void LMGraph::loadFromFiles(const char *graphFileName, const char *offsetsFileName, const int h) {

	unLoad();

	// read graph file
	FILE *f = fopen(graphFileName, "rb");
	if(f == NULL) {
		printf("Couldn't open %s for reading.\n", graphFileName);
		return;
	}
	_fseeki64(f, 0, SEEK_END);
	graphPos = graphSize = (unsigned int)_ftelli64(f);
	rewind(f);
	graphBuffer = new unsigned char [ graphSize ];
	if(graphBuffer == NULL) {
		fclose(f);
		return;
	}
	fread(graphBuffer, 1, graphSize, f);
	fclose(f);

	// read offsets file
	f = fopen(offsetsFileName, "rb");
	if(f == NULL) {
		printf("Couldn't open %s for reading.\n", offsetsFileName);
		return;
	}
	_fseeki64(f, 0, SEEK_END);
	int fSize = (int)_ftelli64(f);
	rewind(f);
	offsetsCnt = (fSize - 16) >> 2;
	if(offsetsCnt < 2) {
		delete[] graphBuffer;
		fclose(f);
		return;
	}
	offsets = new unsigned int [offsetsCnt];
	fread(&numNodes, 4, 1, f);
	fread(&maxSuccListLength, 4, 1, f);
	fread(&maxResidListLength, 4, 1, f);
	fread(&maxUncomprSize, 4, 1, f);
	fread(offsets, 4, offsetsCnt, f);

	this->h = h;

	loaded = true;
}
Example #20
0
long long WRT_ftelli64(WRT_FILE * _File)
{
	if (!_File || _File->sig != _SIGNATURE) return _ftelli64((FILE*)_File);

	CriticalSection cs(_File->cs);
	unsigned long long pos;
	return SUCCEEDED(_File->stream->Seek(liZero, STREAM_SEEK_CUR, (PULARGE_INTEGER)&pos)) ? pos : -1;
}
Example #21
0
a_int64 my_ftelli64(FILE *stream)
{
#ifdef _WIN32
	return _ftelli64(stream);
#else
	return ftell(stream);
#endif
}
Example #22
0
off_t ftello(FILE *stream)
{
#if _FILE_OFFSET_BITS == 64
	return _ftelli64(stream);
#else
	return ftell(stream);
#endif /* _FILE_OFFSET_BITS == 64 */
}
inline I64 ByteStreamInFile::tell() const
{
#ifdef _WIN32
  return _ftelli64(file);
#else
  return (I64)ftello(file);
#endif
}
Example #24
0
int64_t os_ftelli64(FILE *file)
{
#ifdef _MSC_VER
	return _ftelli64(file);
#else
	return ftello(file);
#endif
}
Example #25
0
uint64_t GetFileSize(FILE *f) 
{
    uint64_t size;
    _fseeki64(f, 0, SEEK_END);
    size = _ftelli64(f);
    _fseeki64(f, 0, SEEK_SET);
    return size;
}
Example #26
0
		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
		}
Example #27
0
portable_off_t portable_ftell(FILE *f)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
  return _ftelli64(f);
#else
  return ftello(f);
#endif
}
int main(int argc, const char **argv)
{
	// _fseeki64() and _ftelli64() use __int64.
	// NOTE: __int64 is an MSVC-proprietary type.
	__int64 offset = _ftelli64(NULL);
	_fseeki64(NULL, offset, SEEK_SET);
	return 0;
}
Example #29
0
int64_t file_tell(FILE * file)
{
#ifdef _WIN32
	return _ftelli64(file);
#else
	return ftell(file);
#endif
}
Example #30
0
static int64_t _file_tell(BD_FILE_H *file)
{
#if defined(__MINGW32__)
    return ftello64((FILE *)file->internal);
#else
    return _ftelli64((FILE *)file->internal);
#endif
}