Convert a number of fprintf() calls.
#include "curlx.h"
#include "tool_dirhie.h"
+#include "tool_msgs.h"
#include "memdebug.h" /* keep this as LAST include */
# endif
#endif
-static void show_dir_errno(FILE *errors, const char *name)
+static void show_dir_errno(struct GlobalConfig *global, const char *name)
{
switch(errno) {
#ifdef EACCES
case EACCES:
- fprintf(errors, "You don't have permission to create %s.\n", name);
+ errorf(global, "You don't have permission to create %s", name);
break;
#endif
#ifdef ENAMETOOLONG
case ENAMETOOLONG:
- fprintf(errors, "The directory name %s is too long.\n", name);
+ errorf(global, "The directory name %s is too long", name);
break;
#endif
#ifdef EROFS
case EROFS:
- fprintf(errors, "%s resides on a read-only file system.\n", name);
+ errorf(global, "%s resides on a read-only file system", name);
break;
#endif
#ifdef ENOSPC
case ENOSPC:
- fprintf(errors, "No space left on the file system that will "
- "contain the directory %s.\n", name);
+ errorf(global, "No space left on the file system that will "
+ "contain the directory %s", name);
break;
#endif
#ifdef EDQUOT
case EDQUOT:
- fprintf(errors, "Cannot create directory %s because you "
- "exceeded your quota.\n", name);
+ errorf(global, "Cannot create directory %s because you "
+ "exceeded your quota", name);
break;
#endif
default:
- fprintf(errors, "Error creating directory %s.\n", name);
+ errorf(global, "Error creating directory %s", name);
break;
}
}
#endif
-CURLcode create_dir_hierarchy(const char *outfile, FILE *errors)
+CURLcode create_dir_hierarchy(const char *outfile, struct GlobalConfig *global)
{
char *tempdir;
char *tempdir2;
/* Create directory. Ignore access denied error to allow traversal. */
if(!skip && (-1 == mkdir(dirbuildup, (mode_t)0000750)) &&
(errno != EACCES) && (errno != EEXIST)) {
- show_dir_errno(errors, dirbuildup);
+ show_dir_errno(global, dirbuildup);
result = CURLE_WRITE_ERROR;
break; /* get out of loop */
}
*
***************************************************************************/
#include "tool_setup.h"
+#include "tool_cfgable.h"
-CURLcode create_dir_hierarchy(const char *outfile, FILE *errors);
+CURLcode create_dir_hierarchy(const char *outfile,
+ struct GlobalConfig *global);
#endif /* HEADER_CURL_TOOL_DIRHIE_H */
if(hdrlen) {
hdrbuf[hdrlen] = '\0';
if(slist_append(pheaders, hdrbuf)) {
- fprintf(stderr, "Out of memory for field headers!\n");
+ errorf(config->global, "Out of memory for field headers");
return -1;
}
hdrlen = 0;
switch(c) {
case EOF:
if(ferror(fp)) {
- fprintf(stderr, "Header file %s read error: %s\n", filename,
- strerror(errno));
+ errorf(config->global, "Header file %s read error: %s", filename,
+ strerror(errno));
return -1;
}
return 0; /* Done. */
sep = *p;
*endpos = '\0';
if(slist_append(&headers, hdr)) {
- fprintf(stderr, "Out of memory for field header!\n");
+ errorf(config->global, "Out of memory for field header!");
curl_slist_free_all(headers);
return -1;
}
break;
case 'v': /* --stderr */
- tool_set_stderr_file(nextarg);
+ tool_set_stderr_file(global, nextarg);
break;
case 'w': /* --interface */
/* interface */
/* win32_init must be called before other init routines. */
result = win32_init();
if(result) {
- fprintf(stderr, "curl: (%d) Windows-specific init failed.\n", result);
+ errorf(&global, "(%d) Windows-specific init failed", result);
return result;
}
#endif
if(main_checkfds()) {
- fprintf(stderr, "curl: out of file descriptors\n");
+ errorf(&global, "out of file descriptors");
return CURLE_FAILED_INIT;
}
*/
void errorf(struct GlobalConfig *config, const char *fmt, ...)
{
- if(!config->silent) {
+ if(!config->silent || config->showerror) {
va_list ap;
va_start(ap, fmt);
voutf(config, ERROR_PREFIX, fmt, ap);
*
***************************************************************************/
#include "tool_setup.h"
+#include "tool_cfgable.h"
void warnf(struct GlobalConfig *config, const char *fmt, ...);
void notef(struct GlobalConfig *config, const char *fmt, ...);
struct OutStruct *outs = &per->outs;
CURL *curl = per->curl;
struct OperationConfig *config = per->config;
+ int rc;
if(!curl || !config)
return result;
}
/* Set file extended attributes */
if(!result && config->xattr && outs->fopened && outs->stream) {
- int rc = fwrite_xattr(curl, per->this_url, fileno(outs->stream));
+ rc = fwrite_xattr(curl, per->this_url, fileno(outs->stream));
if(rc)
warnf(config->global, "Error setting extended attributes on '%s': %s",
outs->filename, strerror(errno));
if(!outs->s_isreg && outs->stream) {
/* Dump standard stream buffered data */
- int rc = fflush(outs->stream);
+ rc = fflush(outs->stream);
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
- if(!global->silent || global->showerror)
- fprintf(stderr, "curl: (%d) Failed writing body\n", result);
+ errorf(global, "Failed writing body");
}
}
per->retry_sleep = RETRY_SLEEP_MAX;
}
if(outs->bytes && outs->filename && outs->stream) {
- int rc;
/* We have written data to an output file, we truncate file
*/
notef(config->global,
if(ftruncate(fileno(outs->stream), outs->init)) {
/* when truncate fails, we can't just append as then we'll
create something strange, bail out */
- if(!global->silent || global->showerror)
- fprintf(stderr, "curl: (23) Failed to truncate file\n");
+ errorf(config->global, "Failed to truncate file");
return CURLE_WRITE_ERROR;
}
/* now seek to the end of the file, the position where we
rc = fseek(outs->stream, (long)outs->init, SEEK_SET);
#endif
if(rc) {
- if(!global->silent || global->showerror)
- fprintf(stderr, "curl: (23) Failed seeking to end of file\n");
+ errorf(config->global, "Failed seeking to end of file");
return CURLE_WRITE_ERROR;
}
outs->bytes = 0; /* clear for next round */
/* Close the outs file */
if(outs->fopened && outs->stream) {
- int rc = fclose(outs->stream);
+ rc = fclose(outs->stream);
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
- if(!global->silent || global->showerror)
- fprintf(stderr, "curl: (%d) Failed writing body\n", result);
+ errorf(config->global, "curl: (%d) Failed writing body", result);
}
if(result && config->rm_partial) {
notef(global, "Removing output file: %s", outs->filename);
file output call */
if(config->create_dirs) {
- result = create_dir_hierarchy(per->outfile, stderr);
+ result = create_dir_hierarchy(per->outfile, global);
/* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */
if(result)
break;
#define CURL_DO_NOT_OVERRIDE_STDERR
#include "tool_setup.h"
-
#include "tool_stderr.h"
+#include "tool_msgs.h"
#include "memdebug.h" /* keep this as LAST include */
tool_stderr = stderr;
}
-void tool_set_stderr_file(char *filename)
+void tool_set_stderr_file(struct GlobalConfig *global, char *filename)
{
FILE *fp;
subsequent freopen will fail. */
fp = fopen(filename, FOPEN_WRITETEXT);
if(!fp) {
- fprintf(tool_stderr, "Warning: Failed to open %s!\n", filename);
+ warnf(global, "Warning: Failed to open %s", filename);
return;
}
fclose(fp);
*
***************************************************************************/
#include "tool_setup.h"
+#include "tool_cfgable.h"
void tool_init_stderr(void);
-void tool_set_stderr_file(char *filename);
+void tool_set_stderr_file(struct GlobalConfig *global, char *filename);
#endif /* HEADER_CURL_TOOL_STDERR_H */