[util] Add strlcpy helper

strncpy is not safe.
This commit is contained in:
Joshua Ashton 2022-04-18 00:52:22 +01:00 committed by Joshie
parent 9ee0f51870
commit dc6b7fa4a7
1 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
@ -39,5 +40,11 @@ namespace dxvk::str {
format1(stream, args...);
return stream.str();
}
inline void strlcpy(char* dst, const char* src, size_t count) {
std::strncpy(dst, src, count);
if (count > 0)
dst[count - 1] = '\0';
}
}