Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions stl/src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,19 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Rename(const wchar_t* _Fname1, const wchar_
}

_FS_DLL int __CLRCALL_PURE_OR_CDECL _Resize(const wchar_t* _Fname, uintmax_t _Newsize) { // change file size
bool _Ok = false;

HANDLE _Handle = _FilesysOpenFile(_Fname, FILE_GENERIC_WRITE, 0);

if (_Handle != INVALID_HANDLE_VALUE) { // set file pointer to new size and trim
LARGE_INTEGER _Large;
_Large.QuadPart = _Newsize;
_Ok = SetFilePointerEx(_Handle, _Large, nullptr, FILE_BEGIN) != 0 && SetEndOfFile(_Handle) != 0;
CloseHandle(_Handle);
if (_Handle == INVALID_HANDLE_VALUE) {
return GetLastError();
}

FILE_END_OF_FILE_INFO _File_info;
_File_info.EndOfFile.QuadPart = static_cast<LONGLONG>(_Newsize);
Comment thread
StephanTLavavej marked this conversation as resolved.

const auto _Ok = SetFileInformationByHandle(_Handle, FileEndOfFileInfo, &_File_info, sizeof(_File_info));

CloseHandle(_Handle);
return _Ok ? 0 : GetLastError();
}

Expand Down
11 changes: 6 additions & 5 deletions stl/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,14 @@ _Success_(return == __std_win_error::_Success) __std_win_error
return _Err;
}

LARGE_INTEGER _Large;
_Large.QuadPart = _New_size;
if (SetFilePointerEx(_Handle._Get(), _Large, nullptr, FILE_BEGIN) == 0 || SetEndOfFile(_Handle._Get()) == 0) {
return __std_win_error{GetLastError()};
FILE_END_OF_FILE_INFO _File_info;
_File_info.EndOfFile.QuadPart = static_cast<LONGLONG>(_New_size);

if (SetFileInformationByHandle(_Handle._Get(), FileEndOfFileInfo, &_File_info, sizeof(_File_info))) {
return __std_win_error::_Success;
}

return __std_win_error::_Success;
return __std_win_error{GetLastError()};
}

[[nodiscard]] __std_win_error __stdcall __std_fs_space(_In_z_ const wchar_t* const _Target,
Expand Down