fsutil_write_file

int fsutil_write_file(const char *path, const void *data, uint32_t len)

Calls fs_open(), fs_write(), and fs_close() to open a file at the specified path, write the supplied data to the current offset of the specified file handle, and close the file and invalidate the file handle. If the specified file already exists, it is truncated and overwritten with the specified data.

Arguments

ArgumentDescription
pathPointer to the file to write to
dataThe data to write
lenThe number of bytes to write

Returned values

Header file

#include "fs/fsutil.h"

Example

This example creates a 4-byte file.

int
write_id(void)
{
    int rc;

    /* Create the parent directory. */
    rc = fs_mkdir("/cfg");
    if (rc != 0 && rc != FS_EALREADY) {
        return -1;
    }

    /* Create a file and write four bytes to it. */
    rc = fsutil_write_file("/cfg/id.txt", "1234", 4);
    if (rc != 0) {
        return -1;
    }

    return 0;
}