SWRU368C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
This operation enables writing to an existing file. The purpose of the offset is mainly to allow random access write without using the fseek method as in "standard" file system. Using this method you can access any location in the file with a single API call.
For write purposes, user can write the file in chunks without taking care of the order of the chunks as long as the same location if not repeated twice while the file is opened.
_i32 sl_FsWrite(_i32 FileHandle,
_u32 Offset,
_u8* pData,
_u32 Len);
Type | Parameter | In/Out | Description |
---|---|---|---|
_u32 | FileHandle | In | Handle to an existing file (returned on sl_FsOpen()) |
_u32 | Offset | In | Offset within a file |
_u32* | pData | In | Pointer to the written data |
_i32* | Len | in | Length of the written data |
On success, zero is returned. On error, an error code is returned.
_u8 DeviceFileName[] = "MyFile.txt";
_i32 DeviceFileHandle = -1;
_i32 RetVal;
_u32 Offset;
Offset = 0;
RetVal = sl_FsOpen(DeviceFileName,
FS_MODE_OPEN_WRITE,
NULL,
&DeviceFileHandle);
RetVal = sl_FsWrite( DeviceFileHandle,
Offset,
(_u8 *)"Hello World.",
strlen("Hello World."));
Offset = strlen("HelloWorld.");
RetVal = sl_FsWrite( DeviceFileHandle,
Offset,
(_u8 *)"This is a test.",
strlen("This is a test."));
RetVal = sl_FsClose(DeviceFileHandle,
NULL,
NULL,
NULL );
File appending is not embedded into the file system. Appending can be achieved by read-modify-write implementation in the host.