mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-09 22:00:39 +01:00
replace fwrite etc with write so fsync can be added before close.
This commit is contained in:
parent
bcf767d66e
commit
553bee4956
1 changed files with 10 additions and 6 deletions
|
@ -105,7 +105,7 @@ void
|
||||||
writeToFile( XWStreamCtxt* stream, void* closure )
|
writeToFile( XWStreamCtxt* stream, void* closure )
|
||||||
{
|
{
|
||||||
void* buf;
|
void* buf;
|
||||||
FILE* file;
|
int fd;
|
||||||
XP_U16 len;
|
XP_U16 len;
|
||||||
CommonGlobals* cGlobals = (CommonGlobals*)closure;
|
CommonGlobals* cGlobals = (CommonGlobals*)closure;
|
||||||
|
|
||||||
|
@ -113,17 +113,21 @@ writeToFile( XWStreamCtxt* stream, void* closure )
|
||||||
buf = malloc( len );
|
buf = malloc( len );
|
||||||
stream_getBytes( stream, buf, len );
|
stream_getBytes( stream, buf, len );
|
||||||
|
|
||||||
file = fopen( cGlobals->params->fileName, "w" );
|
fd = open( cGlobals->params->fileName, O_CREAT|O_TRUNC|O_WRONLY,
|
||||||
if ( !file ) {
|
S_IRUSR|S_IWUSR );
|
||||||
XP_LOGF( "%s: fopen => %d (%s)", __func__, errno, strerror(errno) );
|
if ( fd < 0 ) {
|
||||||
|
XP_LOGF( "%s: open => %d (%s)", __func__, errno, strerror(errno) );
|
||||||
} else {
|
} else {
|
||||||
if ( 1 == fwrite( buf, len, 1, file ) ) {
|
ssize_t nWritten = write( fd, buf, len );
|
||||||
|
if ( len == nWritten ) {
|
||||||
XP_LOGF( "%s: wrote %d bytes to %s", __func__, len,
|
XP_LOGF( "%s: wrote %d bytes to %s", __func__, len,
|
||||||
cGlobals->params->fileName );
|
cGlobals->params->fileName );
|
||||||
} else {
|
} else {
|
||||||
|
XP_LOGF( "%s: write => %s", __func__, strerror(errno) );
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
}
|
}
|
||||||
fclose( file );
|
fsync( fd );
|
||||||
|
close( fd );
|
||||||
}
|
}
|
||||||
|
|
||||||
free( buf );
|
free( buf );
|
||||||
|
|
Loading…
Add table
Reference in a new issue