就简单给代码加上些注释,方便理解。第一次浏览,应该会有不正确的理解。后面会继续学习修改。

文件:clamscan\clamscan.c

代码如下:

  1. nt main(int argc, char **argv)
  2. {
  3. int ds, dms, ret;
  4. double mb;
  5. struct timeval t1, t2;
  6. #ifndef C_WINDOWS
  7. struct timezone tz;
  8. #endif
  9. struct optstruct *opt;
  10. const char *pt;
  11.  
  12. //pthread是一个通用的跨平台高性能线程库
  13. //暂时没发现加入的地方
  14. //在程序开始的时候要调用
  15. #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
  16. if(!pthread_win32_process_attach_np()) {
  17. mprintf("!Can't start the win32 pthreads layer\n");
  18. return 72;
  19. }
  20. #endif
  21.  
  22. //这里进行参数解析
  23. //具体规则待会查看下
  24. opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL);
  25. if(!opt) {
  26. mprintf("!Can't parse the command line\n");
  27. return 40;
  28. }
  29.  
  30. //以下开始进行命令判断
  31. if(opt_check(opt, "verbose")) {
  32. mprintf_verbose = 1;
  33. logg_verbose = 1;
  34. }
  35.  
  36. if(opt_check(opt, "quiet"))
  37. mprintf_quiet = 1;
  38.  
  39. if(opt_check(opt, "stdout"))
  40. mprintf_stdout = 1;
  41.  
  42. if(opt_check(opt, "debug")) {
  43. #if defined(C_LINUX)
  44. /* njh@bandsman.co.uk: create a dump if needed */
  45. struct rlimit rlim;
  46.  
  47. rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
  48. if(setrlimit(RLIMIT_CORE, &rlim) < 0)
  49. perror("setrlimit");
  50. #endif
  51. cl_debug(); /* enable debug messages */
  52. }
  53.  
  54. if(opt_check(opt, "version")) {
  55. print_version(opt_arg(opt, "database"));
  56. opt_free(opt);
  57. return 0;
  58. }
  59.  
  60. if(opt_check(opt, "help")) {
  61. opt_free(opt);
  62. help();
  63. return 0;
  64. }
  65.  
  66. if(opt_check(opt, "recursive"))
  67. recursion = 1;
  68.  
  69. if(opt_check(opt, "infected"))
  70. printinfected = 1;
  71.  
  72. if(opt_check(opt, "bell"))
  73. bell = 1;
  74.  
  75. if(opt_check(opt, "tempdir"))
  76. cl_settempdir(opt_arg(opt, "tempdir"), 0);
  77.  
  78. if(opt_check(opt, "leave-temps"))
  79. cl_settempdir(NULL, 1);
  80.  
  81. //日志初始化
  82. if(opt_check(opt, "log")) {
  83. logg_file = opt_arg(opt, "log");
  84. if(logg("#\n-------------------------------------------------------------------------------\n\n")) {
  85. mprintf("!Problem with internal logger.\n");
  86. opt_free(opt);
  87. return 62;
  88. }
  89. } else
  90. logg_file = NULL;
  91.  
  92. //一些数字参数合法化检验
  93.  
  94. if(opt_check(opt, "max-scansize")) {
  95. pt = opt_arg(opt, "max-scansize");
  96. if(!strchr(pt, 'M') && !strchr(pt, 'm')) {
  97. if(!cli_isnumber(pt)) {
  98. logg("!--max-scansize requires a natural number\n");
  99. opt_free(opt);
  100. return 40;
  101. }
  102. }
  103. }
  104.  
  105. if(opt_check(opt, "max-filesize")) {
  106. pt = opt_arg(opt, "max-filesize");
  107. if(!strchr(pt, 'M') && !strchr(pt, 'm')) {
  108. if(!cli_isnumber(pt)) {
  109. logg("!--max-filesize requires a natural number\n");
  110. opt_free(opt);
  111. return 40;
  112. }
  113. }
  114. }
  115.  
  116. if(opt_check(opt, "max-files")) {
  117. if(!cli_isnumber(opt_arg(opt, "max-files"))) {
  118. logg("!--max-files requires a natural number\n");
  119. opt_free(opt);
  120. return 40;
  121. }
  122. }
  123.  
  124. if(opt_check(opt, "max-recursion")) {
  125. if(!cli_isnumber(opt_arg(opt, "max-recursion"))) {
  126. logg("!--max-recursion requires a natural number\n");
  127. opt_free(opt);
  128. return 40;
  129. }
  130. }
  131.  
  132. if(opt_check(opt, "max-mail-recursion")) {
  133. if(!cli_isnumber(opt_arg(opt, "max-mail-recursion"))) {
  134. logg("!--max-mail-recursion requires a natural number\n");
  135. opt_free(opt);
  136. return 40;
  137. }
  138. }
  139.  
  140. if(opt_check(opt, "max-dir-recursion")) {
  141. if(!cli_isnumber(opt_arg(opt, "max-dir-recursion"))) {
  142. logg("!--max-dir-recursion requires a natural number\n");
  143. opt_free(opt);
  144. return 40;
  145. }
  146. }
  147.  
  148. if(opt_check(opt, "max-ratio")) {
  149. if(!cli_isnumber(opt_arg(opt, "max-ratio"))) {
  150. logg("!--max-ratio requires a natural number\n");
  151. opt_free(opt);
  152. return 40;
  153. }
  154. }
  155.  
  156. memset(&info, 0, sizeof(struct s_info));
  157.  
  158. //设置默认的文件I/O操作
  159. //Windows下二进制
  160. //DEBUG下设置报告方式?
  161. #ifdef C_WINDOWS
  162. _set_fmode(_O_BINARY);
  163. #ifdef CL_DEBUG
  164. {
  165. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  166. _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
  167. }
  168. #endif
  169. gettimeofday(&t1, NULL);
  170. #else
  171. gettimeofday(&t1, &tz);
  172. #endif
  173.  
  174. //这里就开始调用一个扫描的管理类方法来扫毒
  175. //返回的ret说明信息
  176. ret = scanmanager(opt);
  177.  
  178. //下面开始就是日志记录?
  179. if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) {
  180. #ifdef C_WINDOWS
  181. gettimeofday(&t2, NULL);
  182. #else
  183. gettimeofday(&t2, &tz);
  184. #endif
  185. ds = t2.tv_sec - t1.tv_sec;
  186. dms = t2.tv_usec - t1.tv_usec;
  187. ds -= (dms < 0) ? (1):(0);
  188. dms += (dms < 0) ? (1000000):(0);
  189. logg("\n----------- SCAN SUMMARY -----------\n");
  190. logg("Known viruses: %u\n", info.sigs);
  191. logg("Engine version: %s\n", cl_retver());
  192. logg("Scanned directories: %u\n", info.dirs);
  193. logg("Scanned files: %u\n", info.files);
  194. logg("Infected files: %u\n", info.ifiles);
  195. if(info.notremoved) {
  196. logg("Not removed: %u\n", info.notremoved);
  197. }
  198. if(info.notmoved) {
  199. logg("Not %s: %u\n", opt_check(opt, "copy") ? "moved" : "copied", info.notmoved);
  200. }
  201. mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
  202. logg("Data scanned: %2.2lf MB\n", mb);
  203. logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms/1000, ds/60, ds%60);
  204. }
  205.  
  206. opt_free(opt);
  207.  
  208. //对应于上面的pthread开始函数
  209. #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
  210. if(!pthread_win32_process_detach_np()) {
  211. logg("!Can't stop the win32 pthreads layer\n");
  212. return 72;
  213. }
  214. #endif
  215.  
  216. return ret;
  217. }

原文:http://blog.csdn.net/betabin/article/details/7421910

ClamAV学习【2】——clamscan入口函数浏览的更多相关文章

  1. C++学习--入口函数

    在学习第一个C++程序的时候发现控制台程序的入口函数是int _tmain而不是main,查了资料才发现_tmain()是为了支持unicode所使用的main一个别名,宏定义在<stdafx. ...

  2. JQuery学习:事件绑定&入口函数&样式控制

    1.基础语法学习: 1.事件绑定 2.入口函数 3.样式控制 <!DOCTYPE html> <html lang="en"> <head> & ...

  3. Egret 学习之 入口函数 及开始编写程序(三)

    1,Egret的程序入口: C和java是以一个main函数作为入口,但egret类似于ActionScript 是以一个文档类作为入口,确切的说是以这个文档类的构造函数作为入口: 2,文档类的构造函 ...

  4. Qt Windows下链接子系统与入口函数(终结版)(可同时存在main和WinMain函数)

    Qt Windows下链接子系统与入口函数(终结版) 转载自:http://blog.csdn.net/dbzhang800/article/details/6358996 能力所限,本讨论仅局限于M ...

  5. C++的入口函数

    我们最开始学习c++时,就知道要写一个main()函数,并且知道这是整个函数的入口,但是c++不只有main()函数这一个入口. 一.对于不同的程序函数入口是不同的. main()是WINDOWS的控 ...

  6. 2、jQuery的基本概念-必看-版本-入口函数- jq对象和dom对象区别

    1.4. jQuery的版本 官网下载地址:http://jquery.com/download/ jQuery版本有很多,分为1.x 2.x 3.x 大版本分类: 1.x版本:能够兼容IE678浏览 ...

  7. 01-老马jQuery教程-jQuery入口函数及选择器

    前言 这套jQuery教程是老马专门为寒门子弟而录制,希望大家看到后能转发给更多的寒门子弟.视频都是免费,请参考课程地址:https://chuanke.baidu.com/s5508922.html ...

  8. u-boot-1.1.6第2阶段入口函数start_armboot分析

    学习目标: 1.分析u-boot-1.1.6第2阶段入口函数void start_armboot (void),熟悉该函数所实现的功能 2.为后面能够掌握u-boot-1.1.6如何启动内核过程打下基 ...

  9. [C#] 了解过入口函数 Main() 吗?带你用批处理玩转 Main 函数

    了解过入口函数 Main() 吗?带你用批处理玩转 Main 函数 目录 简介 特点 方法的参数 方法的返回值 与批处理交互的一个示例 简介 我们知道,新建一个控制台应用程序的时候,IDE 会同时创建 ...

随机推荐

  1. 关于rand 与 randn

    rand:0-1均匀分布.均值m=(a+b)/2; 方差=(b-a).^2/12;   randn:0均值,方差1.     只有当rand和randn生成较大的数据时,均值和方差才会成立.比如N&g ...

  2. VMware CentOS Device eth0 does not seem to be present

    在VMware里克隆出来的CentOS Linux.. ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting ...

  3. 为何在JDK安装路径下存在两个JRE?

    "两个jre"和"三个lib"的功能简单扼要的解释 安装JDK后,Java目录下有jdk和jre两个文件夹,但jdk下还有一个jre文件夹,而且这个jre比前面 ...

  4. 5月23日Google就宣布了Chrome 36 beta

    对于开发人员来说,本次更新的重点还有element.animate().HTML Imports.Object.observe()的引入,以及一个改进后的throttled async touchmo ...

  5. tfrecord

    制作自己的TFRecord数据集,读取,显示及代码详解 http://blog.csdn.net/miaomiaoyuan/article/details/56865361

  6. js 正则积累

    //1.验证非空 if (v[j] == "notNull" && $.trim(f.value) == "") { alert(input.a ...

  7. 高分辨率下firefox字体和界面自动放大的问题

    电脑是高分屏的情况下,如果我们将DPI调成100%,屏幕字体太小,所以我们经常将DPI设置成125%或者其它,这样屏幕看起来会舒服些.但随之而来的是火狐浏览器的字体界面也会放大, 这也会直接导致我们在 ...

  8. 数据库 alert.log 日志中出现 "[Oracle][ODBC SQL Server Wire Protocol driver][SQL Server] 'RECOVER'"报错信息

    现象描述: (1).数据库通过调用透明网络实现分布式事务,但透明网关停用后,失败的分布式事务并未清理. (2).数据库 alert 日志 Thu Sep 06 06:53:00 2018 Errors ...

  9. Docker简介及基本应用

    Docker 前言 1.虚拟化 在计算机中,虚拟化(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源,如服务器.网络.内存及存储等,予以抽象.转换后呈现出来,打破实体结 ...

  10. 【bzoj1911】[Apio2010]特别行动队

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4048  Solved: 1913[Submit][Statu ...