From: Christophe Jaillet Date: Thu, 4 Apr 2013 18:44:02 +0000 (+0000) Subject: Use apr_file_printf(... "%pm"...) instead of explicit call to apr_strerror X-Git-Tag: 2.5.0-alpha~5623 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b2015379ba6ceb8c784718eef12a51d70b52954;p=apache Use apr_file_printf(... "%pm"...) instead of explicit call to apr_strerror + add some spaces to improve formatting git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1464674 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/support/firehose.c b/support/firehose.c index a8325c5792..392080c7ab 100644 --- a/support/firehose.c +++ b/support/firehose.c @@ -233,7 +233,6 @@ static apr_status_t finalise_body(file_rec *file, header_rec *header) apr_status_t status; char *nfrom, *nto, *from, *to; apr_pool_t *pool; - char errbuf[HUGE_STRING_LEN]; apr_pool_create(&pool, file->pool); @@ -251,31 +250,27 @@ static apr_status_t finalise_body(file_rec *file, header_rec *header) if (APR_SUCCESS != (status = apr_file_rename(nfrom, nto, pool))) { apr_file_printf( file->file_err, - "Could not rename file '%s' to '%s' for fragment write: %s\n", - nfrom, nto, - apr_strerror(status, errbuf, sizeof(errbuf))); + "Could not rename file '%s' to '%s' for fragment write: %pm\n", + nfrom, nto, &status); } } else { apr_file_printf( file->file_err, - "Could not set mtime on file '%s' to '%" APR_TIME_T_FMT "' for fragment write: %s\n", - nfrom, file->end, - apr_strerror(status, errbuf, sizeof(errbuf))); + "Could not set mtime on file '%s' to '%" APR_TIME_T_FMT "' for fragment write: %pm\n", + nfrom, file->end, &status); } } else { apr_file_printf(file->file_err, - "Could not merge directory '%s' with file '%s': %s\n", - file->directory, to, apr_strerror(status, errbuf, - sizeof(errbuf))); + "Could not merge directory '%s' with file '%s': %pm\n", + file->directory, to, &status); } } else { apr_file_printf(file->file_err, - "Could not merge directory '%s' with file '%s': %s\n", - file->directory, from, apr_strerror(status, errbuf, - sizeof(errbuf))); + "Could not merge directory '%s' with file '%s': %pm\n", + file->directory, from, &status); } apr_pool_destroy(pool); @@ -328,7 +323,6 @@ static apr_status_t process_body(file_rec *file, header_rec *header, char *native, *name; apr_pool_t *pool; apr_file_t *handle; - char errbuf[HUGE_STRING_LEN]; if (!file->start) { file->start = header->timestamp; @@ -350,21 +344,20 @@ static apr_status_t process_body(file_rec *file, header_rec *header, if (APR_SUCCESS != (status = apr_file_write_full(handle, str, len, &len))) { apr_file_printf(file->file_err, - "Could not write fragment body to file '%s': %s\n", - native, apr_strerror(status, errbuf, sizeof(errbuf))); + "Could not write fragment body to file '%s': %pm\n", + native, &status); } } else { apr_file_printf(file->file_err, - "Could not open file '%s' for fragment write: %s\n", - native, apr_strerror(status, errbuf, sizeof(errbuf))); + "Could not open file '%s' for fragment write: %pm\n", + native, &status); } } else { apr_file_printf(file->file_err, - "Could not merge directory '%s' with file '%s': %s\n", - file->directory, name, apr_strerror(status, errbuf, - sizeof(errbuf))); + "Could not merge directory '%s' with file '%s': %pm\n", + file->directory, name, &status); } apr_pool_destroy(pool); @@ -506,7 +499,6 @@ static apr_status_t process_header(file_rec *file, header_rec *header, */ static apr_status_t demux(file_rec *file) { - char errbuf[HUGE_STRING_LEN]; apr_size_t len = 0; apr_status_t status = APR_SUCCESS; apr_bucket *b, *e; @@ -598,8 +590,7 @@ static apr_status_t demux(file_rec *file) header.len, &e))) { apr_file_printf( file->file_err, - "Could not read fragment body from input file: %s\n", - apr_strerror(status, errbuf, sizeof(errbuf))); + "Could not read fragment body from input file: %pm\n", &status); break; } while ((b = APR_BRIGADE_FIRST(bb)) && e != b) { @@ -644,8 +635,7 @@ static apr_status_t demux(file_rec *file) } else { apr_file_printf(file->file_err, - "Could not read fragment header from input file: %s\n", - apr_strerror(status, errbuf, sizeof(errbuf))); + "Could not read fragment header from input file: %pm\n", &status); break; } @@ -704,8 +694,7 @@ int main(int argc, const char * const argv[]) APR_OS_DEFAULT, pool); if (status != APR_SUCCESS) { apr_file_printf(file->file_err, - "Could not open file '%s' for read: %s\n", optarg, - apr_strerror(status, errmsg, sizeof errmsg)); + "Could not open file '%s' for read: %pm\n", optarg, &status); return 1; } break; @@ -715,8 +704,7 @@ int main(int argc, const char * const argv[]) status = apr_stat(&finfo, optarg, APR_FINFO_TYPE, pool); if (status != APR_SUCCESS) { apr_file_printf(file->file_err, - "Directory '%s' could not be found: %s\n", optarg, - apr_strerror(status, errmsg, sizeof errmsg)); + "Directory '%s' could not be found: %pm\n", optarg, &status); return 1; } if (finfo.filetype != APR_DIR) { diff --git a/support/htcacheclean.c b/support/htcacheclean.c index 4150936fbb..2644251f97 100644 --- a/support/htcacheclean.c +++ b/support/htcacheclean.c @@ -1087,9 +1087,8 @@ static apr_status_t remove_directory(apr_pool_t *pool, const char *dir) return rv; } if (rv != APR_SUCCESS) { - char errmsg[120]; - apr_file_printf(errfile, "Could not open directory %s: %s" APR_EOL_STR, - dir, apr_strerror(rv, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not open directory %s: %pm" APR_EOL_STR, + dir, &rv); return rv; } @@ -1110,10 +1109,9 @@ static apr_status_t remove_directory(apr_pool_t *pool, const char *dir) const char *file = apr_pstrcat(pool, dir, "/", dirent.name, NULL); rv = apr_file_remove(file, pool); if (APR_SUCCESS != rv) { - char errmsg[120]; apr_file_printf(errfile, - "Could not remove file '%s': %s" APR_EOL_STR, file, - apr_strerror(rv, errmsg, sizeof errmsg)); + "Could not remove file '%s': %pm" APR_EOL_STR, file, + &rv); break; } } @@ -1127,9 +1125,8 @@ static apr_status_t remove_directory(apr_pool_t *pool, const char *dir) rv = APR_SUCCESS; } if (rv != APR_SUCCESS) { - char errmsg[120]; - apr_file_printf(errfile, "Could not remove directory %s: %s" APR_EOL_STR, - dir, apr_strerror(rv, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not remove directory %s: %pm" APR_EOL_STR, + dir, &rv); } } @@ -1151,9 +1148,8 @@ static apr_status_t find_directory(apr_pool_t *pool, const char *base, rv = apr_dir_open(&dirp, base, pool); if (rv != APR_SUCCESS) { - char errmsg[120]; - apr_file_printf(errfile, "Could not open directory %s: %s" APR_EOL_STR, - base, apr_strerror(rv, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not open directory %s: %pm" APR_EOL_STR, + base, &rv); return rv; } @@ -1194,18 +1190,16 @@ static apr_status_t find_directory(apr_pool_t *pool, const char *base, remove = apr_pstrcat(pool, base, "/", header, NULL); status = apr_file_remove(remove, pool); if (status != APR_SUCCESS && !APR_STATUS_IS_ENOENT(status)) { - char errmsg[120]; - apr_file_printf(errfile, "Could not remove file %s: %s" APR_EOL_STR, - remove, apr_strerror(status, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not remove file %s: %pm" APR_EOL_STR, + remove, &status); rv = status; } remove = apr_pstrcat(pool, base, "/", data, NULL); status = apr_file_remove(remove, pool); if (status != APR_SUCCESS && !APR_STATUS_IS_ENOENT(status)) { - char errmsg[120]; - apr_file_printf(errfile, "Could not remove file %s: %s" APR_EOL_STR, - remove, apr_strerror(status, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not remove file %s: %pm" APR_EOL_STR, + remove, &status); rv = status; } @@ -1357,7 +1351,6 @@ static void usage_repeated_arg(apr_pool_t *pool, char option) { static void log_pid(apr_pool_t *pool, const char *pidfilename, apr_file_t **pidfile) { apr_status_t status; - char errmsg[120]; pid_t mypid = getpid(); if (APR_SUCCESS == (status = apr_file_open(pidfile, pidfilename, @@ -1369,9 +1362,8 @@ static void log_pid(apr_pool_t *pool, const char *pidfilename, apr_file_t **pidf else { if (errfile) { apr_file_printf(errfile, - "Could not write the pid file '%s': %s" APR_EOL_STR, - pidfilename, - apr_strerror(status, errmsg, sizeof errmsg)); + "Could not write the pid file '%s': %pm" APR_EOL_STR, + pidfilename, &status); } exit(1); } @@ -1579,8 +1571,8 @@ int main(int argc, const char * const argv[]) } proxypath = apr_pstrdup(pool, arg); if ((status = apr_filepath_set(proxypath, pool)) != APR_SUCCESS) { - usage(apr_psprintf(pool, "Could not set filepath to '%s': %s", - proxypath, apr_strerror(status, errmsg, sizeof errmsg))); + usage(apr_psprintf(pool, "Could not set filepath to '%s': %pm", + proxypath, &status)); } break; @@ -1680,8 +1672,7 @@ int main(int argc, const char * const argv[]) } if (apr_filepath_get(&path, 0, pool) != APR_SUCCESS) { - usage(apr_psprintf(pool, "Could not get the filepath: %s", - apr_strerror(status, errmsg, sizeof errmsg))); + usage(apr_psprintf(pool, "Could not get the filepath: %pm", &status)); } baselen = strlen(path);