axmol/core/base/posix_io.cpp

23 lines
501 B
C++
Raw Normal View History

2023-09-01 10:31:34 +08:00
#include "posix_io.h"
#if defined(_WIN32)
extern "C" int _ftruncate(int fd, int64_t size)
{
auto handle = (HANDLE)_get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE)
return -1;
LARGE_INTEGER offset;
offset.QuadPart = size;
do
{
if (!::SetFilePointerEx(handle, offset, nullptr, FILE_BEGIN))
break;
if (!::SetEndOfFile(handle))
break;
return 0;
} while (false);
errno = GetLastError();
return -1;
}
#endif