diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-22 13:13:10 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-22 13:13:10 +0200 |
commit | 8566655b85f0a4e515d57f6686636db516116f95 (patch) | |
tree | d27ec314359a083210492a371b5fce1761e734ae /c/util.h | |
parent | ee1eafe1ed12c2c46ed31ad560daeae11ab1e027 (diff) | |
download | EpisodeBrowser-8566655b85f0a4e515d57f6686636db516116f95.tar.gz |
Improve Win32Error, add Min.
Diffstat (limited to 'c/util.h')
-rw-r--r-- | c/util.h | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1,13 +1,17 @@ #ifndef UTIL_H #define UTIL_H -#include <algorithm> #include <cstring> #include <memory> #include <string> #include <SWI-Prolog.h> #include <windows.h> +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 <typename T> struct Buf @@ -39,7 +43,7 @@ inline int Sprintf(Buf<char> buf, const char* const fmt, T... xs) /* Copy to static wide string buffer. */ inline wchar_t* Wcscpy(Buf<wchar_t> 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<wchar_t> dst, const wchar_t* const src) /* Copy to static narrow string buffer. */ inline char* Strcpy(Buf<char> 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; |