Listing 1: The full cat program
#include "apr_pools.h" #include "apr_file_io.h" #define STR_LEN 256 int main(int argc, const char * const argv[]) { apr_pool_t *pool; apr_file_t *thefile = NULL; apr_file_t *out = NULL; char str[STR_LEN]; apr_app_initialize(&argc, &argv, NULL); atexit(apr_terminate); apr_pool_create(&pool, NULL); apr_file_open_stdout(&out, pool); if (apr_file_open(&thefile, argv[1], APR_READ | APR_CREATE, APR_UREAD | APR_UWRITE | APR_GREAD, pool) != APR_SUCCESS) { apr_file_printf(out, "Could not open file %s\n", argv[1]); } while (apr_file_eof(thefile) != APR_EOF) { apr_size_t bytes; apr_file_gets(str, STR_LEN, thefile); bytes = strlen(str); apr_file_write(out, str, &bytes); } apr_pool_destroy(pool); }