Fix POSIX error

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6846 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2017-04-13 14:42:47 +00:00
parent c7a74bbaba
commit 264fc910aa
3 changed files with 17 additions and 2 deletions

View file

@ -276,6 +276,15 @@ FILE* my_fopen(const TCHAR *path, const char *mode);
// assumption: T is an int type
template <class T> inline T align_to_512(const T x) { return (x+511) & ~511; }
template<class T> inline T read_ptr_as(const void*p)
{
#if defined(_MSC_VER) && (_MSC_VER-0 < 1400) // TODO: Figure out which versions are able to optimize the memcpy
return *(T*)(p);
#else
T t; memcpy(&t, p, sizeof(T)); return t;
#endif
}
// some values need to be truncated from size_t to [unsigned] int, using this function is better than a plain cast
template<class R, class T> inline R internaltruncate_cast(T t) {
assert((~((T)0)) > T(0)); // Only unsigned types supported right now