Sujet : Re: avoiding strdup()
De : already5chosen (at) *nospam* yahoo.com (Michael S)
Groupes : comp.lang.cDate : 11. Mar 2024, 19:29:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240311202914.00005cab@yahoo.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
An application that cares will fsync(2) the file descriptor before
closing it with close(2) and will check the fsync return value and
take appropriate action if it fails.
While I personally eschew fopen/fclose and their ilk due to
performance overhead generally, were I to use it for data which
is required to be valid, I'd always check the results of fflush
before closing with fclose().
Last I looked at it, and it was several years ago, so can misremember,
fflush() is only slightly better, if at all better, than fclose(). It
also does not guarantee that my data propagated beyond filesystem write
cache.
For fsync() there are problems as well.
(1) - it is not part of C Standard.
(2) - even on systems where it is implemented, like Linux, BSD and
Mac, it is likely to not do the same things.
(3) - if done in UI thread, it's likely to negatively affect
responsiveness of UI. If not done in UI thread, it's too much of
error-prone code to write.
It really depends on the application and the importance of the
data (ephemeral data, e.g. terminal output from ps(1), may not
require the same level of scrutiny as a database, for example).