Perform some minor fixups

This commit is contained in:
Justine Tunney 2021-03-16 22:19:51 -07:00
parent ca88ce5026
commit 4e93750afd
9 changed files with 24 additions and 50 deletions

View file

@ -21,15 +21,14 @@
#include "libc/nt/files.h"
#include "libc/sysv/errfuns.h"
textwindows int sys_ftruncate_nt(int fd, uint64_t length) {
textwindows int sys_ftruncate_nt(int64_t handle, uint64_t length) {
bool32 ok;
int64_t tell;
if (!__isfdkind(fd, kFdFile)) return ebadf();
tell = -1;
if (SetFilePointerEx(g_fds.p[fd].handle, 0, &tell, kNtFileCurrent)) {
ok = SetFilePointerEx(g_fds.p[fd].handle, length, NULL, kNtFileBegin) &&
SetEndOfFile(g_fds.p[fd].handle);
SetFilePointerEx(g_fds.p[fd].handle, tell, NULL, kNtFileBegin);
if (SetFilePointerEx(handle, 0, &tell, kNtFileCurrent)) {
ok = SetFilePointerEx(handle, length, NULL, kNtFileBegin) &&
SetEndOfFile(handle);
SetFilePointerEx(handle, tell, NULL, kNtFileBegin);
return ok ? 0 : __winerr();
} else {
return __winerr();

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"
#include "libc/sysv/errfuns.h"
/**
* Changes size of file.
@ -31,9 +32,11 @@
* @asyncsignalsafe
*/
int ftruncate(int fd, int64_t length) {
if (fd < 0) return einval();
if (!IsWindows()) {
return sys_ftruncate(fd, length, length);
} else {
return sys_ftruncate_nt(fd, length);
if (fd >= g_fds.n) return ebadf();
return sys_ftruncate_nt(g_fds.p[fd].handle, length);
}
}

View file

@ -243,7 +243,7 @@ int sys_flock_nt(int, int) hidden;
int sys_fork_nt(void) hidden;
int sys_fstat_nt(i64, struct stat *) hidden;
int sys_fstatat_nt(int, const char *, struct stat *, uint32_t) hidden;
int sys_ftruncate_nt(int, u64) hidden;
int sys_ftruncate_nt(i64, u64) hidden;
int sys_getppid_nt(void) hidden;
int sys_getpriority_nt(int) hidden;
int sys_getrusage_nt(int, struct rusage *) hidden;

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/sysinfo.h"
@ -41,8 +40,8 @@ int sysinfo(struct sysinfo *info) {
} else {
rc = sys_sysinfo_nt(info);
}
info->procs = max(1, info->procs);
info->mem_unit = max(1, info->mem_unit);
info->totalram = max((8 * 1024 * 1024) / info->mem_unit, info->totalram);
info->procs = MAX(1, info->procs);
info->mem_unit = MAX(1, info->mem_unit);
info->totalram = MAX((8 * 1024 * 1024) / info->mem_unit, info->totalram);
return rc;
}

View file

@ -32,9 +32,5 @@
* @asyncsignalsafe
*/
int wait3(int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) {
if (!IsWindows()) {
return sys_wait4(-1, opt_out_wstatus, options, opt_out_rusage);
} else {
return enosys(); /* TODO(jart) */
}
return wait4(-1, opt_out_wstatus, options, opt_out_rusage);
}

View file

@ -54,14 +54,8 @@ textwindows ssize_t sys_write_nt(struct Fd *fd, const struct iovec *iov,
if (opt_offset != -1) opt_offset += rc;
if (rc < iov[i].iov_len) break;
}
if (!total) assert(!__iovec_size(iov, iovlen));
return total;
} else {
if (WriteFile(fd->handle, NULL, 0, &wrote,
offset2overlap(opt_offset, &overlap))) {
return 0;
} else {
return __winerr();
}
return sys_write_nt_impl(fd, NULL, 0, opt_offset);
}
}