Corne' Cornelius said:
When you open a file for writing/appending with open() or fopen(), and
you have multiple applications that might want to write to the same file
at the same time, could that cause weirdness in the file ?
First of all, open() isn't a standard C function, so you won't get
an answer here about its behavior, the question can only be answered
in the context of your system that might or might not implement an
open() function. And for fopen() the answer is also simple: since
standard C doesn't doesn't know or care about other processes
running concurrently, there's no requirement that any kind of file
locking is implemented for fopen().
do i have to add manual file locking, or does open()/fopen() provide
file locking ?
Unless your implementation of the C standard library does file locking
for you (which I would rather doubt) you do have to do it yourself.
Otherwise, as you guess, you might end up with the output of the
different applications mixed up in the file in possibly completely
unpredictable ways - but that's of course again depending of how your
operating systems schedules the processes, which isn't something C
is (or should be) concerned with.
Probably it would also be quite a stupid idea to automatically do
file locking when a file is opened with fopen() because it would
keep you from implementing your own scheme - you might actually
want to have two applications write to the same file, using your
own method to keep the applications from writing in uncoordinated
ways to the file, e.g. in a situation where simple file locking
wouldn't be fine grained enough.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| (e-mail address removed)-berlin.de
_ | | | | | |
| |_| | | | | |
http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring