rt-thread-official/examples/file/seekdir.c

50 lines
1.1 KiB
C
Raw Normal View History

2013-01-08 21:05:02 +08:00
/*
2021-03-07 08:34:04 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-01-08 21:05:02 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-01-08 21:05:02 +08:00
*
* Change Logs:
* Date Author Notes
* 2011-06-02 Bernard first version
* 2020-04-12 Jianjia Ma add msh cmd
2013-01-08 21:05:02 +08:00
*/
#include <dfs_posix.h>
void seekdir_test(void)
{
2021-03-07 08:34:04 +08:00
DIR * dirp;
long save3 = 0;
int i = 0;
struct dirent *dp;
2013-01-08 21:05:02 +08:00
2021-03-07 08:34:04 +08:00
dirp = opendir ("/");
save3 = telldir(dirp);
for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp))
{
rt_kprintf("direntry: %s\n", dp->d_name);
2013-01-08 21:05:02 +08:00
2021-03-07 08:34:04 +08:00
/* save the pointer of the third directory */
if (i++ == 3)
{
save3 = telldir(dirp);
}
}
2013-01-08 21:05:02 +08:00
2021-03-07 08:34:04 +08:00
/* get back to the third directory */
seekdir (dirp, save3);
rt_kprintf("seek dientry to: %d\n", save3);
for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp))
{
rt_kprintf("direntry: %s\n", dp->d_name);
}
2013-01-08 21:05:02 +08:00
2021-03-07 08:34:04 +08:00
/* close the directory */
closedir (dirp);
}
2013-01-08 21:05:02 +08:00
#ifdef RT_USING_FINSH
2013-01-08 21:05:02 +08:00
#include <finsh.h>
FINSH_FUNCTION_EXPORT(seekdir_test, perform directory seek test);
MSH_CMD_EXPORT(seekdir_test, perform directory seek test);
#endif /* RT_USING_FINSH */