

|
 |
| Programming > C Moderated > [comp.lang.c.mo... |
|
| << Topic |
< Post |
Post 8 of 10 Topic 1071 of 1145
|
Post > |
Topic >> |
[comp.lang.c.moderated] Re: Behavior of fwrite(), fseek(), fflush() if the file gets deleted after being opened.
by Val <Valery_Creux@[EMAIL PROTECTED]
>
Apr 4, 2008 at 10:35 AM
| On Apr 1, 7:16 pm, Aditya <adityagupta...@[EMAIL PROTECTED]
> wrote:
> Hi
> I am using Red Hat linux 9 and gcc 3.4.
> I am writing an application in C with file handling. The application
> opens a file(creates it at run time) using fopen() in binary write
> mode. The file is open until the application exits.
>
> The application starts and opens(creates) a file, and waits for an
> input to be written to the file.
> I delete the file using rm -f <filename> as soon as the application
> starts before I give it an input to the application(just to clarify, I
> delete it from a different terminal, without stopping the application
> to wait for an input).
> Now I give the input and debug through the application, I find that
> the fseek(), fwrite(), fflush() calls in the application for writing
> to the file do not throw error even though the file is not existant.
> I cannot understand, where is that data written. If it is wriiten to
> the buffer, then fflush() should have re****ted error. But it also
> succeeds.
> Please, help me in clarifying the point where I am incorrect.
>
> Thanks
> Aditya
> --
> comp.lang.c.moderated - moderation address: c...@[EMAIL PROTECTED]
-- you
must
> have an appropriate newsgroups line in your header for your mail to be
seen,
> or the newsgroup name in square brackets in the subject line. Sorry.
This is a standard unix-like behaviour.
The contents of a file (that could be read and written) is removed
only when the associated reference-counter is zero.
Opening a file increments the counter.
So before deleting (rm -f) the reference was 2 (1 from the directory
structure, 1 from application that has opened the file).
rm -f remove the link from the directory structure, so the file is no
more visible but the counter is 1 so you can still read and write to
it.
When the applicaiton close the file, the couinter is decremented, is
zero and the content is remove from the filesystem.
This behaviour has been used by many application thsat needed some
storage but wanted to keep it invisible from a (non experienced) user.
Incidently, it is the reason why the command (and the same for the C
API) is "rm" i.e. remove link and not delete.
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|
10 Posts in Topic:
|
Aditya <adityagupta.18 |
2008-04-01 12:16:56 |
|
gordonb.hzgc0@[EMAIL PROT |
2008-04-04 10:34:02 |
|
Kenneth Brody <kenbrod |
2008-04-04 10:34:07 |
|
=?ISO-8859-1?Q?Hans-Bernh |
2008-04-04 10:34:14 |
|
Mark Bessey <mark_bess |
2008-04-04 10:34:19 |
|
Keith Thompson <kst-u@ |
2008-04-04 10:34:21 |
|
Jack Klein <jackklein@ |
2008-04-04 10:34:29 |
|
Val <Valery_Creux@[EMA |
2008-04-04 10:35:23 |
|
Barry Schwarz <schwarz |
2008-04-04 10:35:06 |
|
Ivan Chernetsky <ivan_ |
2008-04-04 10:35:11 |
|
Post A Reply:

|
|
|
|