mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-15 07:19:18 +00:00
Improve docs of more system calls
This change also found a few POSIX compliance bugs with errnos. Another bug was discovered where, on Windows, pread() and pwrite() could modify the file position in cases where ReadFile() returned an error e.g. when seeking past the end of file. We also have more tests!
This commit is contained in:
parent
af24c19db3
commit
ccbae7799e
39 changed files with 589 additions and 175 deletions
|
@ -38,6 +38,7 @@
|
|||
|
||||
static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
|
||||
ssize_t offset) {
|
||||
bool32 ok;
|
||||
int64_t h, p;
|
||||
uint32_t err, sent;
|
||||
struct NtOverlapped overlap;
|
||||
|
@ -49,11 +50,15 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
|
|||
_npassert(SetFilePointerEx(h, 0, &p, SEEK_CUR));
|
||||
}
|
||||
|
||||
if (WriteFile(h, data, _clampio(size), &sent,
|
||||
_offset2overlap(h, offset, &overlap))) {
|
||||
if (offset != -1) {
|
||||
_npassert(SetFilePointerEx(h, p, 0, SEEK_SET));
|
||||
}
|
||||
ok = WriteFile(h, data, _clampio(size), &sent,
|
||||
_offset2overlap(h, offset, &overlap));
|
||||
|
||||
if (offset != -1) {
|
||||
// windows clobbers file pointer even on error
|
||||
_npassert(SetFilePointerEx(h, p, 0, SEEK_SET));
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
@ -72,7 +77,7 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
|
|||
_Exitr(128 + EPIPE);
|
||||
}
|
||||
case kNtErrorAccessDenied: // write doesn't return EACCESS
|
||||
return ebadf(); //
|
||||
return ebadf();
|
||||
default:
|
||||
return __winerr();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue