blob: 96f2ef7c3f353d61691bf58ee4dc48a4887adc7e [file] [log] [blame] [raw]
#include <windows.h>
#include <nt.h>
#include <unistd.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) 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) 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 status ? -1 : position.CurrentByteOffset.QuadPart;
}