linux中ls源码简单分析
来源:互联网 发布:天猫魔盒如何下载软件 编辑:程序博客网 时间:2024/06/10 04:34
经过简单分析ls的源码,可以大致总结出ls源码的思路和结构如下(其他函数未仔细分析,还有防止环路的措施没有写出)
int main(int argc, char **argv){ //初始化 //设置权限 //设置颜色 //将当前命令行输入文件加到文件表中 //文件表排序 //打印当前文件表 //如果有待输出目录,调用print_dir()输出待输出目录,这里的循环起到递归的作用 while (pending_dirs){ thispend = pending_dirs; ... print_dir(thispend->name, thispend->realname, thispend->command_line_arg); }}
/* Read directory NAME, and list the files in it. If REALNAME is nonzero, print its name instead of NAME; this is used for symbolic links to directories. COMMAND_LINE_ARG means this directory was mentioned on the command line. */print_dir (char const *name, char const *realname, bool command_line_arg){ DIR *dirp; //print_dir使用opendir打开目录 dirp = opendir (name); ... while (1) { //读取目录下目录项 next = readdir (dirp); if (next){ //判断文件是否显示 if (! file_ignored (next->d_name)) { ... //gobble_file()将文件加入当前文件表中并返回文件所占块数 total_blocks += gobble_file (next->d_name, type, RELIABLE_D_INO (next), false, name); } } } //对文件表排序 sort_files (); ... //如果要递归输出子目录,将当前子目录从文件表删除,加入待输出目录列表 if (recursive) extract_dirs_from_files (name, command_line_arg); ... //如果文件项不为空,输出当前目录 if (cwd_n_used) print_current_files ();}
0 0
- linux中ls源码简单分析
- Linux ls源码分析
- Linux命令分析: ls
- ls 底层源码简单实现
- linux中目录信息查询ls命令的简单使用方法
- Linux 中ls命令
- Linux命令简单实现 -- ls
- ls命令的简单实现源码
- linux中ls命令详解
- Linux中ls命令详解
- linux中ls命令详解
- linux中ls命令详解
- linux中ls命令详解
- linux中ls命令详解
- linux中ls命令详解
- linux中ls命令详解
- Linux中ls和cd
- Linux中ls命令详解
- ios之Xcode工程中添加文件常用快捷键
- ubuntu Unable to locate package libXp
- Unreal 入门-顶点变形
- Unreal 入门-Montage Root Motion 功能代码说明。
- 杭电2004成绩转换
- linux中ls源码简单分析
- Win64 驱动内核编程-20.UnHook SSDT
- Unreal 入门-EQS
- Spring之IoC
- 数据平台
- 在CakePHP项目中集成EasyWeChat
- python 网络爬虫入门(四)— 破解pexels高清原图
- Hibernate常用API
- Source Insight-常用快捷键