mystab.c

最終更新:2009/12/5

mystab.c

001: /* APR を使ったコードのスタブ */
002: 
003: #include "apr_general.h"
004: #include "apr_file_io.h"
005: 
006: #include "mystab.h"
007: 
008: int main (int ac, char const * const *av, char const * const *env) {
009:   apr_status_t rv;
010:   apr_pool_t * pool = NULL;
011:   apr_file_t * apr_stdout = NULL;
012:   apr_file_t * apr_stdin = NULL;
013:   apr_file_t * apr_stderr = NULL;
014:   char error_buf[256];
015:   int result=0;
016: 
017: /* 前処理。APR の初期化、メモリプール作成、標準入力・標準出力・標準エラーの準備 */
018: 
019:   if (APR_SUCCESS != (rv=apr_app_initialize(&ac, &av, &env))) {
020:     fprintf(stderr, 
021:       "ERROR: apr_initialize: %s\n", 
022:       apr_strerror(rv, error_buf, sizeof(error_buf)));
023:     return 1;
024:   }
025: 
026:   if (APR_SUCCESS != (rv=apr_pool_create(&pool, NULL))) {
027:     fprintf(stderr, 
028:       "ERROR: apr_pool_create_core: %s\n", 
029:       apr_strerror(rv, error_buf, sizeof(error_buf)));
030:     result = 1;
031:     goto _FINALLY_;
032:   }
033: 
034:   if (APR_SUCCESS != (rv = apr_file_open_stderr(&apr_stderr, pool))) {
035:     fprintf(stderr, 
036:       "ERROR: apr_file_open_stderr: %s\n", 
037:       apr_strerror(rv, error_buf, sizeof(error_buf)));
038:     result = 1;
039:     goto _FINALLY_;
040:   }
041: 
042:   if (APR_SUCCESS != (rv = apr_file_open_stdout(&apr_stdout, pool))) {
043:     apr_file_printf(apr_stderr, 
044:       "ERROR: apr_file_open_stdout: %s\n", 
045:       apr_strerror(rv, error_buf, sizeof(error_buf)));
046:     result = 1;
047:     goto _FINALLY_;
048:   }
049: 
050:   if (APR_SUCCESS != (rv = apr_file_open_stdin(&apr_stdin, pool))) {
051:     apr_file_printf(apr_stderr, 
052:       "ERROR: apr_file_open_stdin: %s\n", 
053:       apr_strerror(rv, error_buf, sizeof(error_buf)));
054:     result = 1;
055:     goto _FINALLY_;
056:   }
057: 
058: /* apr_my_main の処理 */
059: 
060:   if (0 != apr_my_main(ac, (char**)av, apr_stdin, apr_stdout, apr_stderr, pool)) {
061:     result = 1; /* エラー */
062:   }
063: 
064:   _FINALLY_:
065: 
066:   if (apr_stdin) {
067:     apr_file_close(apr_stdin);
068:     apr_stdin = NULL;
069:   }
070:   if (apr_stdout) {
071:     apr_file_close(apr_stdout);
072:     apr_stdout = NULL;
073:   }
074:   if (apr_stderr) {
075:     apr_file_close(apr_stderr);
076:     apr_stderr = NULL;
077:   }
078:   if (pool) {
079:     apr_pool_destroy(pool);
080:     pool = NULL;
081:   }
082:   apr_terminate();
083: 
084:   return result;
085: 
086: }
Copyright (C) KAKU PROJECT (2009)KAKU PROJECT (2009)