Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 a FILE* corresponding to the file descriptor, but I'd rather not do that.

like image 535
HighCommander4 Avatar asked Aug 03 '10 17:08

HighCommander4


People also ask

What does Ftell do?

ftell() in C In C language, ftell() returns the current file position of the specified stream with respect to the starting of the file. This function is used to get the total size of file after moving the file pointer at the end of the file.

What are the 3 standard file descriptors?

Stdin, stdout, and stderr On a Unix-like operating system, the first three file descriptors, by default, are STDIN (standard input), STDOUT (standard output), and STDERR (standard error). The default data stream for input, for example in a command pipeline.

Is PID a file descriptor?

A PID file descriptor can be used as the argument of process_madvise(2) in order to provide advice on the memory usage patterns of the process referred to by the file descriptor. The pidfd_open() system call is the preferred way of obtaining a PID file descriptor for an already existing process.

Can a file descriptor be negative?

File descriptors typically have non-negative integer values, with negative values being reserved to indicate "no value" or error conditions.


1 Answers

Just use:

position = lseek(fd, 0, SEEK_CUR); 
like image 174
Darron Avatar answered Sep 22 '22 05:09

Darron