mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Prints also the Windows GetLastError() in strerror().
This commit is contained in:
parent
9d4f988f95
commit
a85aa08276
4 changed files with 40 additions and 3 deletions
3
handle.c
3
handle.c
|
|
@ -220,7 +220,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
|
|||
#endif
|
||||
|
||||
if (read_ret < 0) {
|
||||
fprintf(out, "Error reading file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
|
||||
fprintf(out, "Error reading file '%s' at offset %"PRIu64" for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (read_ret == 0) {
|
||||
|
|
@ -230,7 +230,6 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
|
|||
|
||||
count += read_ret;
|
||||
} while (count < read_size);
|
||||
|
||||
|
||||
/* pad with 0 */
|
||||
if (read_size < block_size) {
|
||||
|
|
|
|||
32
mingw.c
32
mingw.c
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include "portable.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#ifdef __MINGW32__ /* Only for MingW */
|
||||
|
||||
/* Adds missing Windows declaration */
|
||||
|
|
@ -64,6 +66,11 @@ static BOOL (WINAPI* ptr_GetFileInformationByHandleEx)(HANDLE, DWORD, LPVOID, DW
|
|||
*/
|
||||
static BOOLEAN (WINAPI* ptr_CreateSymbolicLinkW)(LPWSTR, LPWSTR, DWORD);
|
||||
|
||||
/**
|
||||
* Description of the last error.
|
||||
*/
|
||||
static char* last_error;
|
||||
|
||||
void os_init(void)
|
||||
{
|
||||
HMODULE kernel32 = GetModuleHandle("KERNEL32.DLL");
|
||||
|
|
@ -85,10 +92,14 @@ void os_init(void)
|
|||
ptr_SetThreadExecutionState(WIN32_ES_CONTINUOUS | WIN32_ES_SYSTEM_REQUIRED);
|
||||
}
|
||||
}
|
||||
|
||||
last_error = 0;
|
||||
}
|
||||
|
||||
void os_done(void)
|
||||
{
|
||||
free(last_error);
|
||||
|
||||
/* restore the normal execution level */
|
||||
if (ptr_SetThreadExecutionState) {
|
||||
ptr_SetThreadExecutionState(WIN32_ES_CONTINUOUS);
|
||||
|
|
@ -1037,5 +1048,26 @@ int devuuid(uint64_t device, char* uuid, size_t uuid_size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#undef strerror
|
||||
|
||||
const char* windows_strerror(int err)
|
||||
{
|
||||
/* get the normal C error from the specified err */
|
||||
const char* str = strerror(err);
|
||||
size_t len = strlen(str);
|
||||
|
||||
/* adds space for GetLastError() */
|
||||
len += 32;
|
||||
|
||||
/* reallocate */
|
||||
free(last_error);
|
||||
last_error = malloc(len);
|
||||
if (!last_error)
|
||||
return str;
|
||||
|
||||
snprintf(last_error, len, "%s [%u]", str, (unsigned)GetLastError());
|
||||
return last_error;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
6
mingw.h
6
mingw.h
|
|
@ -68,6 +68,7 @@
|
|||
#define readlink windows_readlink
|
||||
#define symlink windows_symlink
|
||||
#define link windows_link
|
||||
#define strerror windows_strerror
|
||||
|
||||
/* We have nano second support */
|
||||
#define STAT_NSEC(st) (st)->st_mtimensec
|
||||
|
|
@ -250,6 +251,11 @@ int windows_symlink(const char* existing, const char* file);
|
|||
*/
|
||||
int windows_link(const char* existing, const char* file);
|
||||
|
||||
/**
|
||||
* Like strerror().
|
||||
*/
|
||||
const char* windows_strerror(int err);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
|||
2
parity.c
2
parity.c
|
|
@ -393,7 +393,7 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char*
|
|||
read_ret = read(parity->f, block_buffer + count, block_size - count);
|
||||
#endif
|
||||
if (read_ret < 0) {
|
||||
fprintf(out, "Error reading file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
|
||||
fprintf(out, "Error reading file '%s' at offset %"PRIu64" for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (read_ret == 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue