Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2025.1

# 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 | `FileSys` |
Arguments | `const char *buf` | pointer to buffer containing data to be written
| `int len` | length of data to write
| `Error *error` | returned error status
Returns | `void` |

## 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 might occur during I/O.

## Example

To use `Write()` to write an error to a log file:

Copy

    StrBuf m;
    m.Set( "Unknown user\r\n" );
    FileSys *f = FileSys::Create( FST_ATEXT );
    Error e;

    f-&gt;Set( "C:\\logfile.txt" );
    f-&gt;Open( FOM_WRITE, &amp;e );
    f-&gt;Write( m.Text(), m.Length(), &amp;e );
    f-&gt;Close( &amp;e );

To reimplement `Write()` to report errors with `Error::Sys()` and provide debugging output:

Copy

    void FileSysDemo::Write( const char *buf, int len, Error *e )
    {
        int bytes;

        if ( ( bytes = write( fd, buf, len ) ) &lt; 0 )
            e-&gt;Sys( "write", Name() );

        if ( DEBUG )
            printf( "debug (Write): %d bytes\n", bytes );
    }

Your search for returned results