| /* A part of the Native C Library for Windows NT |
| Copyright 2007-2015 PC GO Ld. |
| |
| This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| */ |
| |
| #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(__set_errno_from_ntstatus(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(__set_errno_from_ntstatus(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 __set_errno_from_ntstatus(status) ? -1 : position.CurrentByteOffset.QuadPart; |
| } |