How do C and C ++ standard library functions find the end of a file?

How do fseek(myFILEptr, 0, SEEK_END)

and work myifstream.seekg(0, std::ios::end)

?

Do they need to check each character and is the time complexity linear with the file size? Is it more reasonable? What information does the standard file system provide?

Which parts of this are covered by locales and which are not? For parts that are not standard, are there de facto standards?

I have grouped C and C ++ together because I expect the answer for each to be nearly identical, or even that C ++ functions can and often can be implemented in terms of C functions. Is that correct?

+3


source to share


1 answer


In practice, language implementations rely on the OS to solve this problem (which in turn depends on the filesystem). For example, POSIX provides lseek

syscall.



Thus, they cannot make any guarantees of complexity; they are OS / hardware implementation dependent.

+5


source







All Articles