SaveFile

Saves a file to NVRAM.

Synopsis

Err SaveFile (char *filename, void *buffer, int32 bufsize, int32 extrabytes)

Description

Stores the contents of a buffer to the named file. Currently the file has to be in NVRAM-that is, the filename must start with /NRVRAM/-but if other writable filesystems become available this function will work with them too.

If the file doesn't already exist, it is created. If it does exist, its contents is completely replaced by the contents of the specified buffer. When the file is created it is pre-sized to bufsize+extrabytes. If the file exists but needs to be expanded to hold the output, it is expanded to the size needed+extrabytes.

By specifying a non-zero extrabytes parameter you can ensure that the file will grow enough to handle a few more slightly-growing outputs before an expansion has to be done again. This is useful because expanding a file is relatively expensive. If the nature of the data you're saving is that it never grows, use an extrabytes value of zero. Remember that NVRAM is a very limited resource; don't needlessly use large extrabytes values.

Arguments

filename
Name of the file to save.
buffer
Pointer to a buffer full of data to be saved.
bufsize
Size of the data in the buffer.
extrabytes
Amount of extra space to allocate if and when the file is expanded.

Return Value

Returns zero on success or a negative error code.

Implementation

Library call implemented in lib3do.lib.

Associated Files

lib3do.lib, blockfile.h

See Also

LoadFile