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.
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.
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.
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.
File descriptors typically have non-negative integer values, with negative values being reserved to indicate "no value" or error conditions.
Just use:
position = lseek(fd, 0, SEEK_CUR);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With