2014年01月12日 星期日 11:23
APR的file info模块能够处理文件的权限信息、基础信息、目录,文件路径等。
#include <stdio.h> #include <apr.h> #include <apr_pools.h> #include <apr_errno.h> #include <apr_strings.h> #include <apr_file_info.h> #include <apr_time.h> void apr_err(const char *s, apr_status_t rv) { char buf[120]; fprintf(stderr, "%s: %s (%d)\n", s, apr_strerror(rv, buf, sizeof buf), rv); } int main(int argc,char **argv) { apr_initialize(); apr_pool_t *pool; apr_pool_create(&pool,NULL); apr_status_t st; char *filename; if(argc > 1) { filename=argv[1]; } else { filename="apr_file_info.c"; } apr_finfo_t info; st=apr_stat(&info,filename,0,pool); if(st != APR_SUCCESS) { apr_err("apr_stat()",st); return st; } printf("size = %d\n",info.size); char *stime=apr_pcalloc(pool,1024); st=apr_ctime(stime,info.mtime); printf("mtime = %s\n",stime); apr_dir_t *dir; st=apr_dir_open(&dir,"/",pool); if(st != APR_SUCCESS) { apr_err("apr_dir_open()",st); return st; } while( (st = apr_dir_read(&info,0,dir)) == APR_SUCCESS) { printf("got file: %s\n",info.name); } apr_dir_close(dir); apr_pool_destroy(pool); apr_terminate(); return 0; }
参考资料:
http://apr.apache.org/docs/apr/1.3/group__apr__file__info.html
http://apr.apache.org/docs/apr/1.3/group__apr__file__stat.html
http://apr.apache.org/docs/apr/1.3/group__apr__dir.html
Zeuux © 2024
京ICP备05028076号