mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-28 06:27:06 +08:00
fix compiling warning; optimize ls function.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1186 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
f8397a1693
commit
83bb6a11bb
@ -74,7 +74,10 @@ void dfs_lock()
|
|||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
|
|
||||||
result = rt_mutex_take(&fslock, RT_WAITING_FOREVER);
|
result = rt_mutex_take(&fslock, RT_WAITING_FOREVER);
|
||||||
RT_ASSERT(result == RT_EOK);
|
if (result != RT_EOK)
|
||||||
|
{
|
||||||
|
RT_ASSERT(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -350,6 +353,11 @@ up_one:
|
|||||||
}
|
}
|
||||||
|
|
||||||
*dst = '\0';
|
*dst = '\0';
|
||||||
|
|
||||||
|
/* remove '/' in the end of path if exist */
|
||||||
|
dst --;
|
||||||
|
if ((dst != fullpath) && (*dst == '/')) *dst = '\0';
|
||||||
|
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
@ -444,14 +444,28 @@ void ls(const char* pathname)
|
|||||||
{
|
{
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
int length;
|
int length;
|
||||||
char* fullpath;
|
char *fullpath, *path;
|
||||||
|
|
||||||
fullpath = rt_malloc(DFS_PATH_MAX + 1);
|
fullpath = RT_NULL;
|
||||||
if (fullpath == RT_NULL) return; /* out of memory */
|
if (pathname == RT_NULL)
|
||||||
/* list directory */
|
|
||||||
if ( dfs_file_open(&fd, pathname, DFS_O_DIRECTORY) == 0 )
|
|
||||||
{
|
{
|
||||||
rt_kprintf("Directory %s:\n", pathname);
|
#ifdef DFS_USING_WORKDIR
|
||||||
|
/* open current working directory */
|
||||||
|
path = rt_strdup(working_directory);
|
||||||
|
#else
|
||||||
|
path = rt_strdup("/");
|
||||||
|
#endif
|
||||||
|
if (path == RT_NULL) return ; /* out of memory */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path = (char*)pathname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* list directory */
|
||||||
|
if ( dfs_file_open(&fd, path, DFS_O_DIRECTORY) == 0 )
|
||||||
|
{
|
||||||
|
rt_kprintf("Directory %s:\n", path);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
rt_memset(&dirent, 0, sizeof(struct dirent));
|
rt_memset(&dirent, 0, sizeof(struct dirent));
|
||||||
@ -461,25 +475,24 @@ void ls(const char* pathname)
|
|||||||
rt_memset(&stat, 0, sizeof(struct stat));
|
rt_memset(&stat, 0, sizeof(struct stat));
|
||||||
|
|
||||||
/* build full path for each file */
|
/* build full path for each file */
|
||||||
if (pathname[strlen(pathname) - 1] != '/')
|
fullpath = dfs_normalize_path(path, dirent.d_name);
|
||||||
rt_snprintf(fullpath, DFS_PATH_MAX + 1, "%s%c%s", pathname, '/', dirent.d_name);
|
if (fullpath == RT_NULL) break;
|
||||||
else
|
|
||||||
rt_snprintf(fullpath, DFS_PATH_MAX + 1, "%s%s", pathname, dirent.d_name);
|
|
||||||
|
|
||||||
if (dfs_file_stat(fullpath, &stat) == 0)
|
if (dfs_file_stat(fullpath, &stat) == 0)
|
||||||
{
|
{
|
||||||
|
rt_kprintf("%-20s", dirent.d_name);
|
||||||
if ( DFS_S_ISDIR(stat.st_mode))
|
if ( DFS_S_ISDIR(stat.st_mode))
|
||||||
{
|
{
|
||||||
rt_kprintf("%s\t\t<DIR>\n", dirent.d_name);
|
rt_kprintf("%-25s\n", "<DIR>");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_kprintf("%s\t\t%lu\n", dirent.d_name, stat.st_size);
|
rt_kprintf("%-25lu\n", stat.st_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rt_kprintf("BAD file: %s\n", dirent.d_name);
|
rt_kprintf("BAD file: %s\n", dirent.d_name);
|
||||||
|
rt_free(fullpath);
|
||||||
}
|
}
|
||||||
}while(length > 0);
|
}while(length > 0);
|
||||||
|
|
||||||
@ -489,7 +502,7 @@ void ls(const char* pathname)
|
|||||||
{
|
{
|
||||||
rt_kprintf("No such directory\n");
|
rt_kprintf("No such directory\n");
|
||||||
}
|
}
|
||||||
rt_free(fullpath);
|
if (pathname == RT_NULL) rt_free(path);
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(ls, list directory contents)
|
FINSH_FUNCTION_EXPORT(ls, list directory contents)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user