From 2267758153d1f4d4c9a20c9cf7514ddff8eded55 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 4 May 2011 00:26:30 +0200 Subject: [PATCH] oio_strerror for windows --- oio-win.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/oio-win.c b/oio-win.c index c26071f1..e9f1f54a 100644 --- a/oio-win.c +++ b/oio-win.c @@ -161,6 +161,8 @@ static HANDLE oio_iocp_; static const oio_err oio_ok_ = { OIO_OK, ERROR_SUCCESS }; static oio_err oio_last_error_ = { OIO_OK, ERROR_SUCCESS }; +/* Error message string */ +static char* oio_err_str_ = NULL; /* Global alloc function */ oio_alloc_cb oio_alloc_ = NULL; @@ -217,6 +219,23 @@ oio_err oio_last_error() { } +char* oio_strerror(oio_err err) { + if (oio_err_str_ != NULL) { + LocalFree((void*) oio_err_str_); + } + + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err.sys_errno_, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&oio_err_str_, 0, NULL); + + if (oio_err_str_) { + return oio_err_str_; + } else { + return "Unknown error"; + } +} + + static oio_err_code oio_translate_sys_error(int sys_errno) { switch (sys_errno) { case ERROR_SUCCESS: return OIO_OK;