X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Futils.c;h=e750450e8bc3cf203843378e99f123a7681f86f3;hb=19be9cf7150858311f7898fa3fb525d692d02f64;hp=cf46221280cd42113a265e2e17dcad2abf5bf61b;hpb=3fba80174dbe29bcfe0d121a2a1d2e61be5ee57b;p=meshlink diff --git a/src/utils.c b/src/utils.c index cf462212..e750450e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -137,15 +137,17 @@ int b64encode(const char *src, char *dst, int length) { #endif const char *winerror(int err) { - static char buf[1024], *newline; + static char buf[1024], *ptr; + + ptr = buf + sprintf(buf, "(%d) ", err); if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) { + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) { strncpy(buf, "(unable to format errormessage)", sizeof(buf)); }; - if((newline = strchr(buf, '\r'))) - *newline = '\0'; + if((ptr = strchr(buf, '\r'))) + *ptr = '\0'; return buf; }