/* kfinfo.c * ファイル情報のサンプル * apr_stat の挙動を確認するプログラム */ #define USAGE "Usage: kfinfo " #include "apr_general.h" #include "apr_errno.h" #include "apr_strings.h" #include "apr_file_info.h" #include "mystab.h" int apr_my_main (int ac, char **av, apr_file_t * astdin, apr_file_t * astdout, apr_file_t * astderr, apr_pool_t * pool) { int error_flag = 0; apr_status_t rv = APR_SUCCESS; char *path = NULL; apr_finfo_t finfo; if (ac < 2) { apr_file_printf(astderr, "%s\n", USAGE); error_flag = 1; goto _FINALLY_; } path = av[1]; rv = apr_stat(&finfo, path, APR_FINFO_MIN, pool); if (rv != APR_SUCCESS) { error_flag = 1; goto _FINALLY_; } { char *filetype_str=NULL; switch(finfo.filetype) { case APR_NOFILE: filetype_str="no file type determined"; break; case APR_REG: filetype_str="APR_REG / a regular file"; break; case APR_DIR: filetype_str="APR_DIR / a directory"; break; case APR_CHR: filetype_str="APR_CHR / a character device"; break; case APR_BLK: filetype_str="APR_BLK / a block device"; break; case APR_PIPE: filetype_str="APR_PIPE / a FIFO / pipe"; break; case APR_LNK: filetype_str="APR_LNK / a symbolic link"; break; case APR_SOCK: filetype_str="APR_SOCK / a [unix domain] socket"; break; case APR_UNKFILE: filetype_str="APR_UNKFILE / a file of some other unknown type"; } apr_file_printf(astdout, "filetype=[%s]\n", filetype_str); } apr_file_printf(astdout, "size=[%d]bytes\n", (int)finfo.size); #define XPRINTTIME(XSTR,X) {char tbuf[30]; apr_rfc822_date(tbuf, finfo.X); apr_file_printf(astdout, "%s=[%s]\n", XSTR, tbuf);} XPRINTTIME("atime", atime); XPRINTTIME("mtime", mtime); XPRINTTIME("ctime", ctime); { const char *rootpath=NULL; const char *filepath = apr_pstrdup(pool, path); rv = apr_filepath_root(&rootpath, &filepath, APR_FILEPATH_TRUENAME /*APR_FILEPATH_NATIVE*/, pool); if (rv != APR_SUCCESS) { error_flag = 1; goto _FINALLY_; } apr_file_printf(astdout, "rootpath=[%s], filepath=[%s]\n", rootpath, filepath); } _FINALLY_: if (error_flag) { if (rv != APR_SUCCESS) { char error_buf[256]; apr_file_printf(astderr, "%s\n", apr_strerror(rv, error_buf, sizeof(error_buf))); } apr_file_printf(astderr, "failed!\n"); return 1; /* 異常終了 */ } apr_file_printf(astdout, "\ndone.\n"); return 0; /* 正常終了 */ } /* end of main */