]> git.meshlink.io Git - meshlink/blobdiff - src/utils.c
Merge branch 'master' of git://tinc-vpn.org/tinc into 1.1
[meshlink] / src / utils.c
index cf46221280cd42113a265e2e17dcad2abf5bf61b..e750450e8bc3cf203843378e99f123a7681f86f3 100644 (file)
@@ -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;
 }