FileSys::Write( const char *, int, Error * )
Attempt to write “len” bytes of data to the object referenced by the
file handle (returned by the Open()
method) from the
buffer pointed to by “buf”.
Virtual? |
Yes |
|
Class |
||
Arguments |
|
pointer to buffer containing data to be written |
|
length of data to write |
|
|
returned error status |
|
Returns |
|
Notes
The default implementation of Write()
is called every time
there is a need to write data to the file created by the Open()
call.
Your implementation must correctly report any system errors that may occur during I/O.
Example
To use Write()
to write an
error to a log file:
StrBuf m; m.Set( "Unknown user\r\n" ); FileSys *f = FileSys::Create( FST_ATEXT ); Error e; f->Set( "C:\\logfile.txt" ); f->Open( FOM_WRITE, &e ); f->Write( m.Text(), m.Length(), &e ); f->Close( &e );
To reimplement Write()
to
report errors with Error::Sys()
and provide debugging output:
void FileSysDemo::Write( const char *buf, int len, Error *e ) { int bytes; if ( ( bytes = write( fd, buf, len ) ) < 0 ) e->Sys( "write", Name() ); if ( DEBUG ) printf( "debug (Write): %d bytes\n", bytes ); }