| 16 | #include <sys/statfs.h> |
| 17 | |
| 18 | void list_dir(const char* path) |
| 19 | { |
| 20 | char * fullpath = RT_NULL; |
| 21 | DIR *dir; |
| 22 | |
| 23 | dir = opendir(path); |
| 24 | if (dir != RT_NULL) |
| 25 | { |
| 26 | struct dirent* dirent; |
| 27 | struct stat s; |
| 28 | |
| 29 | fullpath = rt_malloc(256); |
| 30 | if (fullpath == RT_NULL) |
| 31 | { |
| 32 | closedir(dir); |
| 33 | rt_kprintf("no memory\n"); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | do |
| 38 | { |
| 39 | dirent = readdir(dir); |
| 40 | if (dirent == RT_NULL) break; |
| 41 | rt_memset(&s, 0, sizeof(struct stat)); |
| 42 | |
| 43 | /* build full path for each file */ |
| 44 | rt_sprintf(fullpath, "%s/%s", path, dirent->d_name); |
| 45 | |
| 46 | stat(fullpath, &s); |
| 47 | if ( s.st_mode & S_IFDIR ) |
| 48 | { |
| 49 | rt_kprintf("%s\t\t<DIR>\n", dirent->d_name); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | rt_kprintf("%s\t\t%lu\n", dirent->d_name, s.st_size); |
| 54 | } |
| 55 | } while (dirent != RT_NULL); |
| 56 | |
| 57 | closedir(dir); |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | rt_kprintf("open %s directory failed\n", path); |
| 62 | } |
| 63 | |
| 64 | if (RT_NULL != fullpath) |
| 65 | { |
| 66 | rt_free(fullpath); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | #ifdef RT_USING_FINSH |
| 71 | #include <finsh.h> |
no test coverage detected