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

@ -22,6 +22,6 @@
/**
* Returns absolute value of x.
*/
int(abs)(int x) {
int abs(int x) {
return ABS(x);
}

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);
}
}

View file

@ -24,7 +24,7 @@
cosmopolitan § xnu's not unix » carnegie mellon mach microkernel
cosmopolitan § xnu's not unix! » carnegie mellon mach microkernel
*/
#define XNU_SYSCALL_MASK_MACH 0x1000000
@ -38,7 +38,12 @@
#define kXnuNtNsBase 0x060 /* uint64_t */
#define kXnuNtGeneration 0x068 /* uint32_t */
bool swtch(void);
bool swtch_pri(int pri);
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
bool swtch(void);
bool swtch_pri(int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_MACH_H_ */

View file

@ -1,22 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
unsigned hog(unsigned x) {
return (x & 0xf000000) | (x & 0x0fff000) >> 12;
}