| #include <windows.h> |
| #include <nt.h> |
| #include <unistd.h> |
| #include <errno.h> |
| |
| off_t lseek(int fd, off_t offset, int whence) { |
| IO_STATUS_BLOCK io_status; |
| FILE_POSITION_INFORMATION position; |
| FILE_STANDARD_INFORMATION standard; |
| long int status = NtQueryInformationFile((void *)fd, &io_status, &position, sizeof position, FilePositionInformation); |
| //if(status < 0) return -1; |
| if(ntstatus_to_errno(status)) return -1; |
| switch(whence) { |
| case SEEK_SET: |
| position.CurrentByteOffset.QuadPart = offset; |
| break; |
| case SEEK_CUR: |
| position.CurrentByteOffset.QuadPart += offset; |
| break; |
| case SEEK_END: |
| status = NtQueryInformationFile((void *)fd, &io_status, &standard, sizeof standard, FileStandardInformation); |
| //if(status < 0) return -1; |
| if(ntstatus_to_errno(status)) return -1; |
| position.CurrentByteOffset.QuadPart = standard.EndOfFile.QuadPart + offset; |
| break; |
| default: |
| errno = EINVAL; |
| return -1; |
| } |
| status = NtSetInformationFile((void *)fd, &io_status, &position, sizeof position, FilePositionInformation); |
| return ntstatus_to_errno(status) ? -1 : position.CurrentByteOffset.QuadPart; |
| } |