Question

Is It possible to have multiple FILE * s point to the same file with different access modes? For example

lets say i had fopen("File1.bin","wb",fp1) and i perform write operations and WITHOUT closing the file using fclose i call fopen("File1.bin","rb",fp2) and try to use write operations on it. this should fail. but fp2 still writes content to it when i use a different access mode. Why?

Was it helpful?

Solution

fopen() opens a file stream, which is an abstraction of a file. Sure, a file handle is opened underneath but it is perfectly acceptable to have concurrent access to the same file through different handles (which may even be in different processes).

A file is a shared resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top