lwin
git clone https://github.com/libuv/libuv.git
https://cgit.freebsd.org/src/commit/
uint64_t _udiv128(
uint64_t highDividend,
uint64_t lowDividend,
uint64_t divisor,
uint64_t *remainder
);
; Windows 64-bit calling convention passes parameters as follows:
; RCX == first 64-bit integer parameter (high bits of dividend)
; RDX == second 64-bit integer parameter (low bits of dividend)
; R8 == third 64-bit integer parameter (divisor)
; R9 == fourth 64-bit integer parameter (pointer to remainder)
_udiv128 PROC
mov rax, rdx
mov rdx, rcx
div r8 ; 128-bit divide (RDX:RAX / R8)
mov [r9], rdx ; store remainder
ret ; return, with quotient in RDX:RAX
_udiv128 ENDP
int open(const char *name) {
HANDLE hFile = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return -1;
}
return hFile;
}
int close(int fd) {
HANDLE hFile = (HANDLE) fd;
CloseHandle(hFile);
return 0;
}
enum {
FILE_BEGIN,
FILE_CURRENT,
FILE_END
};
off_t lseek(int fd, off_t off, int whence) {
HANDLE hFile = (HANDLE) fd;
if (!SetFilePointerEx(hFile, off, &off, whence))
return -1;
return off;
}
ssize_t read(int fd, void *d, size_t n) {
HANDLE hFile = (HANDLE) fd;
if (!ReadFile(hFile, d, n, &n, 0))
return -1;
return n;
}
ssize_t write(int fd, const void *s, size_t n) {
HANDLE hFile = (HANDLE) fd;
if (!WriteFile(hFile, s, n, &n, 0))
return -1;
return n;
}