Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Oct 8 Previous

Rise like a POSIX from the ashes

Which function do use when you want to set the file pointer to the end of an open file:

A: fpos()
B: feof()
C: fseek()
D: fstat()

Answer

A bit if history here: this question has a lot to do with POSIX which is some sort of API. I know what your thinking: I know all API's but I never heard of POSIX. I understand, I doubt you were even born. POSIX stands for "Portable Operating System Interface" and was first released in 1988.

What has this to do with this question you'll say. Well, POSIX was and still is a big thing in UNIX/C-programming world. Those guys still use these naming conventions and they didn't camelCase back in the eighties (case insenitivity) and under_scores were a waste of space back then (8 character file names: evil tongues suggest that Windows still uses them).

Those days are gone but the legacy continues. All those PHP functions with names like strlen(), fpos(), sprintf(), sscanf() got their names from their underlying POSIX compatible ANSI C counterparts (that's a mouthfull indeed). So that's where those weird function names came from.

But that was then, now back to now and the question. Let's translate 88 IT lingo to nowadays camelCase:

fpos() ≡ getFilePosition feof() ≡ isEndOfFile fseek() ≡ setFilePosition fstat() ≡ getFileStatistics

That solves the question, right? fseek() is the only function that lets you set the file position and therefore must be the right answer.

fseek() also has some magic arguments that let you skip to the beginning or end of the file.