I thought all files were seekable, but I’m going through a codebase that handles cases where a file is not seekable.
Why is that necessary?
In what scenarios would a file be unseekable, and why?
I thought all files were seekable, but I’m going through a codebase that handles cases where a file is not seekable.
Why is that necessary?
In what scenarios would a file be unseekable, and why?
In Unix, almost everything that you do data exchange with is treated like a file, but not everything is a file.
If you are handed an open file descriptor, it might be:
All but the last two can be opened and treated almost like a regular file, until you try to seek on it. (The last two use a function call other than open() that is specific to their type)
All of the non-seekable types above are basically character streams that are consumable rather than repeatable, so seeking on them makes no sense.
S_ISREG(mode) is true, then they are generally seekable, but you can find special filesystems (I've seen some fuse based ones) where they may not be.