Hans Leidekker hans@it.vu.nl writes:
int _chsize(int fd, long size) {
- FIXME("(fd=%d, size=%ld): stub\n", fd, size);
- return -1;
- DWORD cur, pos;
- HANDLE handle;
- BOOL ret = FALSE;
- TRACE("(fd=%d, size=%ld)\n", fd, size);
- LOCK_FILES();
- handle = msvcrt_fdtoh(fd);
- if (handle != INVALID_HANDLE_VALUE)
- {
/* save the current file pointer */
cur = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
if (cur != INVALID_SET_FILE_POINTER)
{
pos = SetFilePointer(handle, size, NULL, FILE_BEGIN);
if (pos != INVALID_SET_FILE_POINTER)
ret = SetEndOfFile(handle);
/* restore the file pointer */
pos = SetFilePointer(handle, cur, NULL, FILE_BEGIN);
}
- }
- UNLOCK_FILES();
- return ret ? 0 : -1;
}
SetFilePointer can return INVALID_SET_FILE_POINTER on success if the current pointer is 0xffffffff, you have to check last error in that case. Also you need to set errno on failure. It may be easier to use _lseek instead of SetFilePointer as it takes care of all that already.