int fs_filelen(const struct fs_file *file, uint32_t *out_len)
Retrieves the current length of the specified open file.
Argument | Description |
---|---|
file | Pointer to the file to query |
out_len | On success, the number of bytes in the file gets written here |
#include "fs/fs.h"
int write_config(void) { struct fs_file *file; int rc; /* If the file doesn't exist, create it. If it does exist, truncate it to * zero bytes. */ rc = fs_open("/settings/config.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file); if (rc == 0) { /* Write 5 bytes of data to the file. */ rc = fs_write(file, "hello", 5); if (rc == 0) { /* The file should now contain exactly five bytes. */ assert(fs_filelen(file) == 5); } /* Close the file. */ fs_close(file); } return rc == 0 ? 0 : -1; }