aboutsummaryrefslogtreecommitdiff
path: root/c/util.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-22 13:13:10 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-22 13:13:10 +0200
commit8566655b85f0a4e515d57f6686636db516116f95 (patch)
treed27ec314359a083210492a371b5fce1761e734ae /c/util.h
parentee1eafe1ed12c2c46ed31ad560daeae11ab1e027 (diff)
downloadEpisodeBrowser-8566655b85f0a4e515d57f6686636db516116f95.tar.gz
Improve Win32Error, add Min.
Diffstat (limited to 'c/util.h')
-rw-r--r--c/util.h10
1 files changed, 7 insertions, 3 deletions
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 <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;