Add platform functions for reporting file errors.

Windows socket error numbers are not reported using errno, but with
WSAGetLastError(). _getdns_errnostr() and friends as implemented on
Windows don't work for errors resulting from file open/close/read/write
etc.

So add a parallel set of functions specifically for file errors.
This commit is contained in:
Jim Hague 2020-12-11 16:08:02 +00:00
parent 7fe308f718
commit 6439b0407a
3 changed files with 18 additions and 9 deletions

View File

@ -4889,7 +4889,7 @@ FILE *_getdns_context_get_priv_fp(
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_INFO
, "Error opening \"%s\": %s\n"
, path, _getdns_errnostr());
, path, _getdns_fileerrnostr());
return f;
}
@ -4968,31 +4968,31 @@ int _getdns_context_write_priv_file(getdns_context *context,
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_INFO
, "Could not create temporary file \"%s\": %s\n"
, tmpfn, _getdns_errnostr());
, tmpfn, _getdns_fileerrnostr());
else if (!(f = fdopen(fd, "w")))
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
, "Error opening temporary file \"%s\": %s\n"
, tmpfn, _getdns_errnostr());
, tmpfn, _getdns_fileerrnostr());
else if (fwrite(content->data, 1, content->size, f) < content->size)
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
, "Error writing to temporary file \"%s\": %s\n"
, tmpfn, _getdns_errnostr());
, tmpfn, _getdns_fileerrnostr());
else if (fclose(f) < 0)
else if (fclose(f))
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
, "Error closing temporary file \"%s\": %s\n"
, tmpfn, _getdns_errnostr());
, "Error closing temporary file \"%s\": %s (%p)\n"
, tmpfn, _getdns_fileerrnostr(), f);
else if (rename(tmpfn, path) < 0)
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
, "Error renaming temporary file \"%s\" to \"%s\""
": %s\n", tmpfn, path, _getdns_errnostr());
": %s\n", tmpfn, path, _getdns_fileerrnostr());
else {
context->can_write_appdata = PROP_ABLE;
return 1;
@ -5045,7 +5045,7 @@ int _getdns_context_can_write_appdata(getdns_context *context)
_getdns_log(&context->log
, GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
, "Error unlinking write test file: \"%s\": %s\n"
, path, _getdns_errnostr());
, path, _getdns_fileerrnostr());
return 1;
}

View File

@ -166,6 +166,11 @@ const char *_getdns_strerror(DWORD errnum)
}
}
const char *_getdns_filestrerror(int errnum)
{
return strerror(errnum);
}
#else
void _getdns_perror(const char *str)

View File

@ -60,6 +60,7 @@ typedef u_short sa_family_t;
#define _getdns_socketerror() (WSAGetLastError())
const char *_getdns_strerror(DWORD errnum);
const char *_getdns_filestrerror(int errnum);
#else /* USE_WINSOCK */
#ifndef HAVE_SYS_POLL_H
@ -132,10 +133,13 @@ const char *_getdns_strerror(DWORD errnum);
#define _getdns_socketerror() (errno)
const char *_getdns_strerror(int errnum);
#define _getdns_filestrerror(errnum) (_getdns_strerror(errnum))
#endif
void _getdns_perror(const char *str);
#define _getdns_fileerror() (errno)
#define _getdns_fileerrnostr() (_getdns_filestrerror(_getdns_fileerror()))
#define _getdns_errnostr() (_getdns_strerror(_getdns_socketerror()))
#define _getdns_error_wants_retry(X) ( (X) != 0 \
&& ( (X) == _getdns_EINTR \