From 8566655b85f0a4e515d57f6686636db516116f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 22 Aug 2022 13:13:10 +0200 Subject: Improve Win32Error, add Min. --- c/util.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'c/util.h') diff --git a/c/util.h b/c/util.h index 698ce10..8281fc9 100644 --- a/c/util.h +++ b/c/util.h @@ -1,13 +1,17 @@ #ifndef UTIL_H #define UTIL_H -#include #include #include #include #include #include +inline size_t Min(size_t a, size_t b) +{ + return a < b? a: b; +} + /* Buf is a span-like structure of a buffer and its size. */ template struct Buf @@ -39,7 +43,7 @@ inline int Sprintf(Buf buf, const char* const fmt, T... xs) /* Copy to static wide string buffer. */ inline wchar_t* Wcscpy(Buf dst, const wchar_t* const src) { - const size_t len = std::min(dst.size, wcslen(src)+1); + const size_t len = Min(dst.size, wcslen(src)+1); memcpy(dst, src, len*sizeof(wchar_t)); dst[len-1] = 0; return dst; @@ -48,7 +52,7 @@ inline wchar_t* Wcscpy(Buf dst, const wchar_t* const src) /* Copy to static narrow string buffer. */ inline char* Strcpy(Buf dst, const char* const src) { - const size_t len = std::min(dst.size, strlen(src)+1); + const size_t len = Min(dst.size, strlen(src)+1); memcpy(dst, src, len); dst[len-1] = 0; return dst; -- cgit v1.2.3