/* APR を使ったコードのスタブ */ #include "apr_general.h" #include "apr_file_io.h" #include "mystab.h" int main (int ac, char const * const *av, char const * const *env) { apr_status_t rv; apr_pool_t * pool = NULL; apr_file_t * apr_stdout = NULL; apr_file_t * apr_stdin = NULL; apr_file_t * apr_stderr = NULL; char error_buf[256]; int result=0; /* 前処理。APR の初期化、メモリプール作成、標準入力・標準出力・標準エラーの準備 */ if (APR_SUCCESS != (rv=apr_app_initialize(&ac, &av, &env))) { fprintf(stderr, "ERROR: apr_initialize: %s\n", apr_strerror(rv, error_buf, sizeof(error_buf))); return 1; } if (APR_SUCCESS != (rv=apr_pool_create(&pool, NULL))) { fprintf(stderr, "ERROR: apr_pool_create_core: %s\n", apr_strerror(rv, error_buf, sizeof(error_buf))); result = 1; goto _FINALLY_; } if (APR_SUCCESS != (rv = apr_file_open_stderr(&apr_stderr, pool))) { fprintf(stderr, "ERROR: apr_file_open_stderr: %s\n", apr_strerror(rv, error_buf, sizeof(error_buf))); result = 1; goto _FINALLY_; } if (APR_SUCCESS != (rv = apr_file_open_stdout(&apr_stdout, pool))) { apr_file_printf(apr_stderr, "ERROR: apr_file_open_stdout: %s\n", apr_strerror(rv, error_buf, sizeof(error_buf))); result = 1; goto _FINALLY_; } if (APR_SUCCESS != (rv = apr_file_open_stdin(&apr_stdin, pool))) { apr_file_printf(apr_stderr, "ERROR: apr_file_open_stdin: %s\n", apr_strerror(rv, error_buf, sizeof(error_buf))); result = 1; goto _FINALLY_; } /* apr_my_main の処理 */ if (0 != apr_my_main(ac, (char**)av, apr_stdin, apr_stdout, apr_stderr, pool)) { result = 1; /* エラー */ } _FINALLY_: if (apr_stdin) { apr_file_close(apr_stdin); apr_stdin = NULL; } if (apr_stdout) { apr_file_close(apr_stdout); apr_stdout = NULL; } if (apr_stderr) { apr_file_close(apr_stderr); apr_stderr = NULL; } if (pool) { apr_pool_destroy(pool); pool = NULL; } apr_terminate(); return result; }