2019-10-09 10:16:54 +08:00
|
|
|
|
## fs\_file\_t
|
|
|
|
|
### 概述
|
2019-11-14 17:55:31 +08:00
|
|
|
|
文件接口。
|
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
|
|
|
|
|
```c
|
|
|
|
|
int32_t ret = 0;
|
|
|
|
|
const char* file_name = "test.txt";
|
|
|
|
|
int32_t len = file_get_size(file_name);
|
|
|
|
|
uint8_t* buff = (uint8_t*)TKMEM_ALLOC(len + 1);
|
|
|
|
|
return_value_if_fail(buff != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
fs_file_t* fp = fs_open_file(os_fs(), file_name, "rb");
|
|
|
|
|
if (fp != NULL) {
|
|
|
|
|
ret = fs_file_read(fp, buff, len);
|
|
|
|
|
fs_file_close(fp);
|
|
|
|
|
}
|
|
|
|
|
```
|
2019-10-09 10:16:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------
|
|
|
|
|
### 函数
|
|
|
|
|
<p id="fs_file_t_methods">
|
|
|
|
|
|
|
|
|
|
| 函数名称 | 说明 |
|
|
|
|
|
| -------- | ------------ |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| <a href="#fs_file_t_fs_file_close">fs\_file\_close</a> | |
|
|
|
|
|
| <a href="#fs_file_t_fs_file_eof">fs\_file\_eof</a> | |
|
|
|
|
|
| <a href="#fs_file_t_fs_file_read">fs\_file\_read</a> | |
|
|
|
|
|
| <a href="#fs_file_t_fs_file_seek">fs\_file\_seek</a> | |
|
|
|
|
|
| <a href="#fs_file_t_fs_file_truncate">fs\_file\_truncate</a> | |
|
|
|
|
|
| <a href="#fs_file_t_fs_file_write">fs\_file\_write</a> | |
|
|
|
|
|
#### fs\_file\_close 函数
|
2019-11-14 15:54:03 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2019-11-14 17:55:31 +08:00
|
|
|
|
> <p id="fs_file_t_fs_file_close">
|
|
|
|
|
关闭文件。
|
2019-11-14 15:54:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2019-11-14 17:55:31 +08:00
|
|
|
|
ret_t fs_file_close (fs_file_t* file);
|
2019-10-09 10:16:54 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| file | fs\_file\_t* | 文件对象。 |
|
|
|
|
|
#### fs\_file\_eof 函数
|
2019-11-14 15:54:03 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2019-11-14 17:55:31 +08:00
|
|
|
|
> <p id="fs_file_t_fs_file_eof">
|
|
|
|
|
判断文件是否结束。
|
2019-11-14 15:54:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2019-11-14 17:55:31 +08:00
|
|
|
|
bool_t fs_file_eof (fs_file_t* file);
|
2019-11-14 15:54:03 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| 返回值 | bool\_t | 返回TRUE表示结束,否则表示没结束。 |
|
|
|
|
|
| file | fs\_file\_t* | 文件对象。 |
|
|
|
|
|
#### fs\_file\_read 函数
|
2019-11-14 15:54:03 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2019-11-14 17:55:31 +08:00
|
|
|
|
> <p id="fs_file_t_fs_file_read">
|
|
|
|
|
读取文件。
|
2019-11-14 15:54:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2019-11-14 17:55:31 +08:00
|
|
|
|
int32_t fs_file_read (fs_file_t* file, void* buffer, uint32_t size);
|
2019-11-14 15:54:03 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| 返回值 | int32\_t | 返回实际读取的字节数。 |
|
|
|
|
|
| file | fs\_file\_t* | 文件对象。 |
|
|
|
|
|
| buffer | void* | 用于返回数据的缓冲区。 |
|
|
|
|
|
| size | uint32\_t | 缓冲区大小。 |
|
|
|
|
|
#### fs\_file\_seek 函数
|
2019-11-14 15:54:03 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2019-11-14 17:55:31 +08:00
|
|
|
|
> <p id="fs_file_t_fs_file_seek">
|
|
|
|
|
定位读写指针到指定的位置。
|
2019-11-14 15:54:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2019-11-14 17:55:31 +08:00
|
|
|
|
ret_t fs_file_seek (fs_file_t* file, uint32_t offset);
|
2019-11-14 15:54:03 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| file | fs\_file\_t* | 文件对象。 |
|
|
|
|
|
| offset | uint32\_t | 数据长度。 |
|
|
|
|
|
#### fs\_file\_truncate 函数
|
2019-11-14 15:54:03 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2019-11-14 17:55:31 +08:00
|
|
|
|
> <p id="fs_file_t_fs_file_truncate">
|
|
|
|
|
清除文件内容。
|
2019-11-14 15:54:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2019-11-14 17:55:31 +08:00
|
|
|
|
ret_t fs_file_truncate (fs_file_t* file);
|
2019-11-14 15:54:03 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 |
|
|
|
|
|
| file | fs\_file\_t* | 文件对象。 |
|
|
|
|
|
#### fs\_file\_write 函数
|
2019-10-09 10:16:54 +08:00
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
* 函数功能:
|
|
|
|
|
|
2019-11-14 17:55:31 +08:00
|
|
|
|
> <p id="fs_file_t_fs_file_write">
|
|
|
|
|
写入文件。
|
2019-10-09 10:16:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 函数原型:
|
|
|
|
|
|
|
|
|
|
```
|
2019-11-14 17:55:31 +08:00
|
|
|
|
int32_t fs_file_write (fs_file_t* file, const void* buffer, uint32_t size);
|
2019-10-09 10:16:54 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 参数说明:
|
|
|
|
|
|
|
|
|
|
| 参数 | 类型 | 说明 |
|
|
|
|
|
| -------- | ----- | --------- |
|
2019-11-14 17:55:31 +08:00
|
|
|
|
| 返回值 | int32\_t | 返回实际写入的字节数。 |
|
|
|
|
|
| file | fs\_file\_t* | 文件对象。 |
|
|
|
|
|
| buffer | const void* | 数据缓冲区。 |
|
|
|
|
|
| size | uint32\_t | 数据长度。 |
|