Questions tagged [ftell]

ftell is a standard C library function which returns the current offset in a file or stream in relation to the first byte.

70 questions
46
votes
1 answer

ftell on a file descriptor?

Is there a way to do what ftell() does (return the current position in the file) on a raw file descriptor instead of a FILE*? I think there ought to be, since you can seek on a raw file descriptor using lseek(). I know I could use fdopen() to create…
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
20
votes
4 answers

Why is fwrite writing more than I tell it to?

FILE *out=fopen64("text.txt","w+"); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf("%i\n",ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf("%i\n",write); printf("%i\n",ftello64(out)); output: 0 25755 25868 what…
zacaj
  • 1,987
  • 1
  • 19
  • 39
18
votes
4 answers

the output of ftell in php function

Here is my code:
showkey
  • 482
  • 42
  • 140
  • 295
14
votes
4 answers

ftell at a position past 2GB

On a 32-bit system, what does ftell return if the current position indicator of a file opened in binary mode is past the 2GB point? In the C99 standard, is this undefined behavior since ftell must return a long int (maximum value being 2**31-1)?
Vilhelm Gray
  • 11,516
  • 10
  • 61
  • 114
14
votes
1 answer

ftello/fseeko vs fgetpos/fsetpos

What is the difference between ftello/fseeko and fgetpos/fsetpos? Both seem to be file pointer getting/setting functions that use opaque offset types to sometimes allow 64 bit offsets. Are they supported on different platforms or by different…
Jeremy Salwen
  • 8,061
  • 5
  • 50
  • 73
8
votes
1 answer

why ftell( stdin ) causes illegal seek error

The following code outputs "Illegal seek": #include #include #include int main() { errno = 0; getchar(); getchar(); getchar(); ftell( stdin ); printf( "%s\n", strerror(errno) ); } This occurs…
Jim
  • 83
  • 1
  • 3
8
votes
4 answers

End of FILE* pointer is not equal to size of written data

Very simply put, I have the following code snippet: FILE* test = fopen("C:\\core.u", "w"); printf("Filepointer at: %d\n", ftell(test)); fwrite(data, size, 1, test); printf("Written: %d bytes.\n", size); fseek(test, 0, SEEK_END); printf("Filepointer…
Daniel
6
votes
0 answers

Streaming HTML5 large (>2GB) videos with PHP

Ok, so basically I'm working on a project where I need to stream MP4 videos from a hidden source. As most of people in this forum with this problem, I've used a solution derived from:…
Inigo EC
  • 2,178
  • 3
  • 22
  • 31
5
votes
4 answers

Are there cases where fseek/ftell can give the wrong file size?

In C or C++, the following can be used to return a file size: const unsigned long long at_beg = (unsigned long long) ftell(filePtr); fseek(filePtr, 0, SEEK_END); const unsigned long long at_end = (unsigned long long) ftell(filePtr); const unsigned…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
5
votes
2 answers

ftello() and fseeko() android build errors

I am trying to build Android L for 64-bit architecture. My code goes like: #if (HAS_LARGE_FILE_SUPPORT) #define _FILE_OFFSET_BITS 64 //Defined in header file /*Some File operations*/ #if HAS_LARGE_FILE_SUPPORT return fseeko(iFile, offset,…
4
votes
2 answers

initial value of file pointer position returned by ftell() in append mode

I was looking at SO post fseek does not work when file is opened in "a" (append) mode and I got a doubt regarding initial value of file pointer returned by ftell() when we open the file in "a" mode. I tried below code with file1.txt containing data…
Rajesh
  • 1,085
  • 1
  • 12
  • 25
4
votes
1 answer

Why does ftell skips some positions in the file?

I have a text file named myfile.txt which reads: line 1 l My code: #include int main(){ FILE *f = fopen("myfile.txt","r"); if(f==NULL){ FILE *fp=fopen("myfile.txt","w"); fclose(fp); f =…
4
votes
1 answer

Get position for file descriptor in Python

Say, I have a raw numeric file descriptor and I need to get the current position in file based on it. import os, psutil # some code that works with file lp = lib.open('/path/to/file') p = psutil.Process(os.getpid()) fd = p.get_open_files()[0].fd …
VisioN
  • 143,310
  • 32
  • 282
  • 281
3
votes
2 answers

ftell/fseek fail when near end of file

Reading a text file (which happens to be a PDS Member FB 80) hFile = fopen(filename,"r"); and have reached up to the point in the file where there is only an empty line left. FilePos = ftell(hFile); Then read the last line, which only contains a…
Morag Hughson
  • 7,255
  • 15
  • 44
3
votes
1 answer

'correct' semantics for ftell() when used on a memory stream

Can anyone explain the 'correct' semantics for ftell() when used on a memory stream. Given the following program: #include #include #include int main(void) { puts (gnu_get_libc_version ()); size_t…
Bruce Adams
  • 4,953
  • 4
  • 48
  • 111
1
2 3 4 5