-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstat_sample.c
More file actions
37 lines (36 loc) · 1022 Bytes
/
stat_sample.c
File metadata and controls
37 lines (36 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*
*/
/*
* 程序清单:取得状态
*
* 程序会创建一个操作文件的函数并导出到msh命令列表
* 在函数中调用 stat() 函数
* int stat(const char *file_name, struct stat *buf);
* stat()函数用来将参数file_name 所指向的文件状态,
* 复制到buf 指针所指的结构中(struct stat)。
*/
#include <rtthread.h>
#if RT_VER_NUM >= 0x40100
#include <fcntl.h> /* 当需要使用文件操作时,需要包含这个头文件 */
#else
#include <dfs_posix.h>
#endif /*RT_VER_NUM >= 0x40100*/
static void stat_sample(void)
{
int ret;
struct stat buf;
ret = stat("/text.txt", &buf);
if (ret == 0)
rt_kprintf("text.txt file size = %d\n", buf.st_size);
else
rt_kprintf("text.txt file not fonud\n");
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(stat_sample, show text.txt stat sample);