Browse Source

Improve documentation

The Cosmo API documentation page is pretty good now
https://justine.lol/cosmopolitan/documentation.html
main
Justine Tunney 9 months ago
parent
commit
1bc3a25505
  1. 6
      Makefile
  2. 140
      ape/lib/pic.c
  3. 2
      build/definitions.mk
  4. 2
      dsp/core/scalevolume.c
  5. 2
      dsp/tty/ident.c
  6. 2
      dsp/tty/ttymove.c
  7. 2
      dsp/tty/ttyraster.c
  8. 2
      examples/cplusplus.cc
  9. 2
      examples/lstime.c
  10. 2
      examples/nesemu1.cc
  11. 8
      libc/alg/qsort.c
  12. 2
      libc/alg/replacestr.c
  13. 2
      libc/alg/replacestr16.c
  14. 2
      libc/bits/bits.h
  15. 2
      libc/bits/emptytonull.c
  16. 14
      libc/bits/mmintrin.internal.h
  17. 2
      libc/bits/nulltoempty.c
  18. 0
      libc/bits/safemacros.h
  19. 2
      libc/bits/unsignedsubtract.c
  20. 1
      libc/bits/xmmintrin.internal.h
  21. 1
      libc/calls/access.c
  22. 1
      libc/calls/chdir.c
  23. 13
      libc/calls/chmod.c
  24. 1
      libc/calls/chown.c
  25. 1
      libc/calls/clock.c
  26. 3
      libc/calls/clock_gettime.c
  27. 4
      libc/calls/close.c
  28. 2
      libc/calls/commandv.c
  29. 2
      libc/calls/copyfd.c
  30. 6
      libc/calls/creat.c
  31. 2
      libc/calls/dprintf.c
  32. 4
      libc/calls/dup-nt.c
  33. 1
      libc/calls/dup.c
  34. 1
      libc/calls/dup2.c
  35. 2
      libc/calls/dup3.c
  36. 1
      libc/calls/faccessat.c
  37. 1
      libc/calls/fadvise.c
  38. 1
      libc/calls/fallocate.c
  39. 1
      libc/calls/fchmod.c
  40. 1
      libc/calls/fchown.c
  41. 1
      libc/calls/fchownat.c
  42. 1
      libc/calls/fcntl.c
  43. 1
      libc/calls/fdatasync.c
  44. 2
      libc/calls/fstat-nt.c
  45. 4
      libc/calls/g_fds.c
  46. 6
      libc/calls/g_ntstartupinfo.c
  47. 6
      libc/calls/g_ntsysteminfo.c
  48. 2
      libc/calls/g_sighandrvas.c
  49. 2
      libc/calls/getenv.c
  50. 2
      libc/calls/hefty/filecmp.c
  51. 2
      libc/calls/hefty/get_current_dir_name.c
  52. 2
      libc/calls/hefty/ntspawn.c
  53. 2
      libc/calls/hefty/replaceuser.c
  54. 1
      libc/calls/internal.h
  55. 2
      libc/calls/isdebuggerpresent.c
  56. 2
      libc/calls/kemptyfd.c
  57. 4
      libc/calls/kntprioritycombos.c
  58. 4
      libc/calls/kntprioritycombos.internal.h
  59. 3
      libc/calls/mprotect.greg.c
  60. 2
      libc/calls/nice.c
  61. 2
      libc/calls/now.c
  62. 2
      libc/calls/ntmagicpaths.c
  63. 2
      libc/calls/ntmagicpaths.internal.h
  64. 16
      libc/calls/ntsetprivilege.c
  65. 2
      libc/calls/preadv.c
  66. 2
      libc/calls/pwritev.c
  67. 2
      libc/calls/sched_setaffinity.c
  68. 2
      libc/calls/setpriority-nt.c
  69. 2
      libc/calls/sysinfo.c
  70. 2
      libc/calls/termios.internal.h
  71. 2
      libc/calls/zygote.c
  72. 2
      libc/dns/dnsnamecmp.c
  73. 2
      libc/dns/getaddrinfo.c
  74. 2
      libc/dns/gethoststxt.c
  75. 2
      libc/elf/elf.h
  76. 2
      libc/fmt/kerrnonames.S
  77. 2
      libc/fmt/kmonthyearday.c
  78. 36
      libc/fmt/palandprintf.c
  79. 8
      libc/fmt/palandprintf.internal.h
  80. 2
      libc/fmt/strerror_r.c
  81. 2
      libc/fmt/vsnprintf.c
  82. 14
      libc/linux/mmap.h
  83. 25
      libc/log/asan.c
  84. 2
      libc/log/attachdebugger.c
  85. 2
      libc/log/backtrace2.c
  86. 6
      libc/log/cancolor.c
  87. 2
      libc/log/checkfail.c
  88. 2
      libc/log/commandvenv.c
  89. 4
      libc/log/die.c
  90. 8
      libc/log/gdb.h
  91. 2
      libc/log/gdbexec.c
  92. 2
      libc/log/gdbsync.c
  93. 2
      libc/log/getttysize.c
  94. 2
      libc/log/isterminalinarticulate.c
  95. 4
      libc/log/oncrash.c
  96. 13
      libc/math/fmax.c
  97. 13
      libc/math/fmaxf.c
  98. 20
      libc/math/fmaxl.c
  99. 13
      libc/math/fmin.c
  100. 13
      libc/math/fminf.c

6
Makefile

@ -140,7 +140,6 @@ include net/http/http.mk #─┘
include third_party/lemon/lemon.mk
include third_party/duktape/duktape.mk
include third_party/regex/regex.mk
include third_party/avir/avir.mk
include third_party/ctags/ctags.mk
include third_party/third_party.mk
include libc/testlib/testlib.mk
@ -313,9 +312,8 @@ o/cosmopolitan.h: \
$(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))
@ACTION=ROLLUP TARGET=$@ build/do $^ >$@
o/cosmopolitan.html: \
o//third_party/chibicc/chibicc.com.dbg
o//third_party/chibicc/chibicc.com.dbg -J -fno-common -include libc/integral/normalize.inc -o $@ $(filter %.c,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS)))
o/cosmopolitan.html: o/$(MODE)/third_party/chibicc/chibicc.com.dbg
o/$(MODE)/third_party/chibicc/chibicc.com.dbg -J -fno-common -include libc/integral/normalize.inc -o $@ $(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS)))
# UNSPECIFIED PREREQUISITES TUTORIAL
#

140
ape/lib/pic.c

@ -1,140 +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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/lib/pc.h"
#define ICW1_ICW4 0x01 /* ICW4 (not) needed */
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
#define ICW1_INIT 0x10 /* Initialization - required! */
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
static inline void io_wait(void) {
/* Magic technique from Linux, according to:
* wiki.osdev.org/index.php?title=Inline_Assembly/Examples&oldid=23541
*/
outb(0x80, 0);
}
void PIC_sendEOI(unsigned char irq) {
if (irq >= 8) outb(PIC2_CMD, PIC_EOI);
outb(PIC1_CMD, PIC_EOI);
}
bool AreInterruptsEnabled() {
return (eflags() & kInterruptFlag) == kInterruptFlag;
}
nodiscard forceinline unsigned long irqdisable(void) {
unsigned long eflags;
asm("pushf\n\t"
"cli\n\t"
"pop\t%0"
: "=r"(eflags)
: /* no inputs */
: "cc");
return eflags;
}
forceinline void irqrestore(unsigned long eflags) {
asm volatile(
"push\t%0\n\t"
"popf"
: /* no outputs */
: "rm"(eflags)
: "cc");
}
/**
* @param offset1 is vector offset for master PIC
* vectors on the master become offset1..offset1+7
* @param offset2 is same for slave PIC: offset2..offset2+7
**/
void PIC_remap(int offset1, int offset2) {
unsigned char a1, a2;
a1 = inb(PIC1_DATA); // save masks
a2 = inb(PIC2_DATA);
outb(PIC1_CMD,
ICW1_INIT |
ICW1_ICW4); // starts the initialization sequence (in cascade mode)
io_wait();
outb(PIC2_CMD, ICW1_INIT | ICW1_ICW4);
io_wait();
outb(PIC1_DATA, offset1); // ICW2: Master PIC vector offset
io_wait();
outb(PIC2_DATA, offset2); // ICW2: Slave PIC vector offset
io_wait();
outb(PIC1_DATA, 4); // ICW3: tell Master PIC that there is a slave PIC at
// IRQ2 (0000 0100)
io_wait();
outb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
io_wait();
outb(PIC1_DATA, ICW4_8086);
io_wait();
outb(PIC2_DATA, ICW4_8086);
io_wait();
outb(PIC1_DATA, a1); // restore saved masks.
outb(PIC2_DATA, a2);
}
void IRQ_set_mask(unsigned char IRQline) {
uint16_t port;
uint8_t value;
if (IRQline < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
IRQline -= 8;
}
value = inb(port) | (1 << IRQline);
outb(port, value);
}
void IRQ_clear_mask(unsigned char IRQline) {
uint16_t port;
uint8_t value;
if (IRQline < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
IRQline -= 8;
}
value = inb(port) & ~(1 << IRQline);
outb(port, value);
}
static uint16_t __pic_get_irq_reg(int ocw3) {
/* OCW3 to PIC CMD to get the register values. PIC2 is chained, and
* represents IRQs 8-15. PIC1 is IRQs 0-7, with 2 being the chain */
outb(PIC1_CMD, ocw3);
outb(PIC2_CMD, ocw3);
return (inb(PIC2_CMD) << 8) | inb(PIC1_CMD);
}
/* Returns the combined value of the cascaded PICs irq request register */
uint16_t pic_get_irr(void) { return __pic_get_irq_reg(PIC_READ_IRR); }
/* Returns the combined value of the cascaded PICs in-service register */
uint16_t pic_get_isr(void) { return __pic_get_irq_reg(PIC_READ_ISR); }

2
build/definitions.mk

@ -126,7 +126,6 @@ TRADITIONAL = \
DEFAULT_CCFLAGS = \
-Wall \
-Werror \
-fmerge-all-constants \
-fdebug-prefix-map="$(PWD)"= \
-frecord-gcc-switches
@ -142,7 +141,6 @@ DEFAULT_COPTS = \
-fno-ident \
-fno-common \
-fno-gnu-unique \
-fmerge-constants \
-fstrict-aliasing \
-fstrict-overflow \
-fno-omit-frame-pointer \

2
dsp/core/scalevolume.c

@ -19,7 +19,7 @@
*/
#include "dsp/core/core.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/limits.h"
/**

2
dsp/tty/ident.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "dsp/tty/tty.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/termios.h"

2
dsp/tty/ttymove.c

@ -19,7 +19,7 @@
*/
#include "dsp/tty/itoa8.h"
#include "dsp/tty/tty.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/limits.h"
#include "libc/log/check.h"

2
dsp/tty/ttyraster.c

@ -24,7 +24,7 @@
#include "dsp/tty/windex.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"

2
examples/cplusplus.cc

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

2
examples/lstime.c

@ -9,7 +9,7 @@
#endif
#include "libc/alg/alg.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/stat.h"

2
examples/nesemu1.cc

@ -13,7 +13,7 @@
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/itimerval.h"

8
libc/alg/qsort.c

@ -226,6 +226,7 @@ static noinline void smoothsort(
* @param width is the size of each item
* @param cmp is a callback returning <0, 0, or >0
* @param arg will optionally be passed as the third argument to cmp
* @see qsort()
*/
void qsort_r(void *base, size_t count, size_t width, cmpfun cmp, void *arg) {
unsigned lp[12 * sizeof(unsigned)];
@ -235,7 +236,12 @@ void qsort_r(void *base, size_t count, size_t width, cmpfun cmp, void *arg) {
/**
* Sorts array.
* @see qsort_r() for further details
*
* @param base points to an array to sort in-place
* @param count is the item count
* @param width is the size of each item
* @param cmp is a callback returning <0, 0, or >0
* @see qsort_r()
*/
void qsort(void *base, size_t count, size_t width,
int cmp(const void *, const void *)) {

2
libc/alg/replacestr.c

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"

2
libc/alg/replacestr16.c

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"

2
libc/bits/bits.h

@ -166,7 +166,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
cosmopolitan § bits » some assembly required
*/
/**
/*
* Constraints for virtual machine flags.
* @note we beseech clang devs for flag constraints
*/

2
libc/bits/emptytonull.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
/**
* Returns string where empty string is made null.

14
libc/bits/mmintrin.internal.h

@ -1,14 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_BITS_MMINTRIN_H_
#define COSMOPOLITAN_LIBC_BITS_MMINTRIN_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
typedef long long __m64 _Vector_size(8);
typedef float __v2sf _Vector_size(8);
typedef int __v2si _Vector_size(8);
typedef short __v4hi _Vector_size(8);
typedef char __v8qi _Vector_size(8);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_MMINTRIN_H_ */

2
libc/bits/nulltoempty.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
/**
* Returns 𝑠 converting null to empty string.

0
libc/bits/safemacros.internal.h → libc/bits/safemacros.h

2
libc/bits/unsignedsubtract.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
/**
* Subtracts unsigned integers w/ wraparound.

1
libc/bits/xmmintrin.internal.h

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
#define COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
#include "libc/bits/emmintrin.internal.h"
#include "libc/bits/mmintrin.internal.h"
#include "libc/bits/progn.internal.h"
#include "libc/dce.h"

1
libc/calls/access.c

@ -30,6 +30,7 @@
* @param mode can be R_OK, W_OK, X_OK, F_OK
* @return 0 if ok, or -1 and sets errno
* @asyncsignalsafe
* @syscall
*/
int access(const char *path, int mode) {
char16_t path16[PATH_MAX];

1
libc/calls/chdir.c

@ -25,6 +25,7 @@
/**
* Sets current directory.
* @asyncsignalsafe
* @syscall
*/
int chdir(const char *path) {
if (!path) return efault();

13
libc/calls/chmod.c

@ -26,15 +26,15 @@
/**
* Changes permissions on file, e.g.:
*
* CHECK_NE(-1, chmod("foo/bar.txt", 0644));
* CHECK_NE(-1, chmod("o/default/program.com", 0755));
* CHECK_NE(-1, chmod("privatefolder/", 0700));
* CHECK_NE(-1, chmod("foo/bar.txt", 0644));
* CHECK_NE(-1, chmod("o/default/program.com", 0755));
* CHECK_NE(-1, chmod("privatefolder/", 0700));
*
* The esoteric bits generally available on System Five are:
*
* CHECK_NE(-1, chmod("/opt/", 01000)); // sticky bit
* CHECK_NE(-1, chmod("/usr/bin/sudo", 04755)); // setuid bit
* CHECK_NE(-1, chmod("/usr/bin/wall", 02755)); // setgid bit
* CHECK_NE(-1, chmod("/opt/", 01000)); // sticky bit
* CHECK_NE(-1, chmod("/usr/bin/sudo", 04755)); // setuid bit
* CHECK_NE(-1, chmod("/usr/bin/wall", 02755)); // setgid bit
*
* This works on Windows NT if you ignore the error ;-)
*
@ -43,6 +43,7 @@
* @errors ENOENT, ENOTDIR, ENOSYS
* @asyncsignalsafe
* @see fchmod()
* @syscall
*/
int chmod(const char *pathname, uint32_t mode) {
if (!pathname) return efault();

1
libc/calls/chown.c

@ -33,6 +33,7 @@
* @see /etc/passwd for user ids
* @see /etc/group for group ids
* @asyncsignalsafe
* @syscall
*/
int chown(const char *pathname, uint32_t uid, uint32_t gid) {
if (!pathname) return efault();

1
libc/calls/clock.c

@ -25,6 +25,7 @@
* Returns how much CPU program has consumed on time-sharing system.
*
* @return value that can be divided by CLOCKS_PER_SEC, or -1 w/ errno
* @see clock_gettime()
*/
int64_t clock(void) {
struct timespec ts;

3
libc/calls/clock_gettime.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/timespec.h"
@ -51,6 +51,7 @@
* errno isn't restored to its original value, to detect prec. loss
* @see strftime(), gettimeofday()
* @asyncsignalsafe
* @syscall
*/
int clock_gettime(int clockid, struct timespec *out_ts) {
/* TODO(jart): Just ignore O/S for MONOTONIC and measure RDTSC on start */

4
libc/calls/close.c

@ -28,8 +28,12 @@
/**
* Closes file descriptor.
*
* This function may be used for file descriptors returned by socket,
* accept, epoll_create, and zipos file descriptors too.
*
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
* @syscall
*/
int close(int fd) {
int rc;

2
libc/calls/commandv.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/progn.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"

2
libc/calls/copyfd.c

@ -19,7 +19,7 @@
*/
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/errno.h"

6
libc/calls/creat.c

@ -23,12 +23,16 @@
/**
* Creates new file, returning open()'d file descriptor.
*
* This function is shorthand for:
*
* open(file, O_CREAT | O_WRONLY | O_TRUNC, mode)
*
* @param file is a UTF-8 string, which is truncated if it exists
* @param mode is an octal user/group/other permission, e.g. 0755
* @return a number registered with the system to track the open file,
* which must be stored using a 64-bit type in order to support both
* System V and Windows, and must be closed later on using close()
* @see touch()
* @see open(), touch()
* @asyncsignalsafe
*/
nodiscard int creat(const char *file, uint32_t mode) {

2
libc/calls/dprintf.c

@ -20,7 +20,7 @@
#include "libc/calls/calls.h"
/**
* Formats string directly to system i/o device.
* Formats string directly to file descriptor.
*/
int(dprintf)(int fd, const char *fmt, ...) {
int rc;

4
libc/calls/dup-nt.c

@ -43,8 +43,8 @@ textwindows int dup$nt(int oldfd, int newfd, int flags) {
return -1;
}
if (DuplicateHandle(GetCurrentProcess(), g_fds.p[oldfd].handle,
GetCurrentProcess(), &g_fds.p[newfd].handle, 0,
flags & O_CLOEXEC, kNtDuplicateSameAccess)) {
GetCurrentProcess(), &g_fds.p[newfd].handle, 0, true,
kNtDuplicateSameAccess)) {
g_fds.p[newfd].kind = g_fds.p[oldfd].kind;
g_fds.p[newfd].flags = flags;
return newfd;

1
libc/calls/dup.c

@ -27,6 +27,7 @@
* @param fd remains open afterwards
* @return some arbitrary new number for fd
* @asyncsignalsafe
* @syscall
*/
nodiscard int dup(int fd) {
if (!IsWindows()) {

1
libc/calls/dup2.c

@ -29,6 +29,7 @@
* unless it's equal to oldfd, in which case dup2() is a no-op
* @return new file descriptor, or -1 w/ errno
* @asyncsignalsafe
* @syscall
*/
int dup2(int oldfd, int newfd) {
if (oldfd == newfd) return newfd;

2
libc/calls/dup3.c

@ -33,6 +33,8 @@
* @param newfd if already assigned, is silently closed beforehand;
* unless it's equal to oldfd, in which case dup2() is a no-op
* @flags can have O_CLOEXEC
* @see dup(), dup2()
* @syscall
*/
int dup3(int oldfd, int newfd, int flags) {
if (oldfd == newfd) return einval();

1
libc/calls/faccessat.c

@ -32,6 +32,7 @@
* @param flags can be R_OK, W_OK, X_OK, F_OK
* @return 0 if ok, or -1 and sets errno
* @asyncsignalsafe
* @syscall
*/
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
if (!path) return efault();

1
libc/calls/fadvise.c

@ -30,6 +30,7 @@
* @param len 0 means til end of file
* @param advice can be MADV_SEQUENTIAL, MADV_RANDOM, etc.
* @return -1 on error
* @syscall
*/
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
if (!IsWindows()) {

1
libc/calls/fallocate.c

@ -38,6 +38,7 @@
* @param length is how much physical space to reserve / commit
* @return 0 on success, or -1 w/ errno
* @see ftruncate()
* @syscall
*/
int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
int rc;

1
libc/calls/fchmod.c

@ -41,6 +41,7 @@
* @errors ENOSYS
* @asyncsignalsafe
* @see chmod()
* @syscall
*/
int fchmod(int fd, uint32_t mode) {
/* TODO(jart): Windows */

1
libc/calls/fchown.c

@ -29,6 +29,7 @@
* @return 0 on success, or -1 w/ errno
* @see /etc/passwd for user ids
* @see /etc/group for group ids
* @syscall
*/
int fchown(int fd, uint32_t uid, uint32_t gid) {
/* TODO(jart): Windows? */

1
libc/calls/fchownat.c

@ -32,6 +32,7 @@
* @see /etc/passwd for user ids
* @see /etc/group for group ids
* @asyncsignalsafe
* @syscall
*/
int fchownat(int dirfd, const char *pathname, uint32_t uid, uint32_t gid,
uint32_t flags) {

1
libc/calls/fcntl.c

@ -30,6 +30,7 @@
* @param arg can be FD_CLOEXEC, etc. depending
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
* @syscall
*/
int fcntl(int fd, int cmd, ...) {
va_list va;

1
libc/calls/fdatasync.c

@ -27,6 +27,7 @@
* @return 0 on success, or -1 w/ errno
* @see fsync(), sync_file_range()
* @asyncsignalsafe
* @syscall
*/
int fdatasync(int fd) {
if (!IsWindows()) {

2
libc/calls/fstat-nt.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/fmt/conv.h"

4
libc/calls/g_fds.c

@ -25,9 +25,9 @@
STATIC_YOINK("_init_g_fds");
struct Fds g_fds;
hidden struct Fds g_fds;
void InitializeFileDescriptors(void) {
hidden void InitializeFileDescriptors(void) {
struct Fds *fds;
fds = VEIL("r", &g_fds);
pushmov(&fds->f, 3ul);

6
libc/calls/g_ntstartupinfo.c

@ -21,10 +21,6 @@
#include "libc/nt/startupinfo.h"
#include "libc/nt/struct/startupinfo.h"
/**
* GetStartupInfo() singleton.
* @see libc/runtime/winmain.c
*/
struct NtStartupInfo g_ntstartupinfo;
hidden struct NtStartupInfo g_ntstartupinfo;
STATIC_YOINK("_init_g_ntstartupinfo");

6
libc/calls/g_ntsysteminfo.c

@ -21,10 +21,6 @@
#include "libc/nt/struct/systeminfo.h"
#include "libc/nt/systeminfo.h"
/**
* GetSystemInfo() singleton.
* @see libc/runtime/winmain.c
*/
struct NtSystemInfo g_ntsysteminfo;
hidden struct NtSystemInfo g_ntsysteminfo;
STATIC_YOINK("_init_g_ntsysteminfo");

2
libc/calls/g_sighandrvas.c

@ -19,4 +19,4 @@
*/
#include "libc/calls/internal.h"
int g_sighandrvas[NSIG];
hidden int g_sighandrvas[NSIG];

2
libc/calls/getenv.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

2
libc/calls/hefty/filecmp.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/str/str.h"

2
libc/calls/hefty/get_current_dir_name.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"

2
libc/calls/hefty/ntspawn.c

@ -20,7 +20,7 @@
#include "libc/alg/alg.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/ntspawn.h"
#include "libc/calls/internal.h"

2
libc/calls/hefty/replaceuser.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"

1
libc/calls/internal.h

@ -68,7 +68,6 @@ hidden extern const struct NtSecurityAttributes kNtIsInheritable;
ssize_t __getemptyfd(void) hidden;
int __ensurefds(int) hidden;
void __removefd(int) hidden;
enum FdKind fdkind(int) hidden nosideeffect;
bool __isfdopen(int) hidden nosideeffect;
bool __isfdkind(int, enum FdKind) hidden nosideeffect;

2
libc/calls/isdebuggerpresent.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"

2
libc/calls/kemptyfd.c

@ -19,4 +19,4 @@
*/
#include "libc/calls/internal.h"
const struct Fd kEmptyFd;
hidden const struct Fd kEmptyFd;

4
libc/calls/kntprioritycombos.c

@ -25,7 +25,7 @@
#include "libc/nt/enum/processcreationflags.h"
#include "libc/nt/enum/threadpriority.h"
const struct NtPriorityCombo kNtPriorityCombos[] = {
hidden const struct NtPriorityCombo kNtPriorityCombos[] = {
{-20, ffs(kNtHighPriorityClass), kNtThreadPriorityHighest, 15},
{-18, ffs(kNtHighPriorityClass), kNtThreadPriorityTimeCritical, 15},
{-17, ffs(kNtNormalPriorityClass), kNtThreadPriorityTimeCritical, 15},
@ -54,4 +54,4 @@ const struct NtPriorityCombo kNtPriorityCombos[] = {
{19, ffs(kNtIdlePriorityClass), kNtThreadPriorityIdle, 1},
};
const unsigned kNtPriorityCombosLen = ARRAYLEN(kNtPriorityCombos);
hidden const unsigned kNtPriorityCombosLen = ARRAYLEN(kNtPriorityCombos);

4
libc/calls/kntprioritycombos.internal.h

@ -10,8 +10,8 @@ struct NtPriorityCombo {
int8_t prio;
};
extern const unsigned kNtPriorityCombosLen;
extern const struct NtPriorityCombo kNtPriorityCombos[];
hidden extern const unsigned kNtPriorityCombosLen;
hidden extern const struct NtPriorityCombo kNtPriorityCombos[];
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

3
libc/calls/mprotect.greg.c

@ -26,6 +26,8 @@
#include "libc/nt/thunk/msabi.h"
#include "libc/sysv/consts/nr.h"
extern __msabi typeof(VirtualProtect) *const __imp_VirtualProtect;
/**
* Modifies restrictions on virtual memory address range.
*
@ -34,7 +36,6 @@
* @see mmap()
*/
int mprotect(void *addr, uint64_t len, int prot) {
extern __msabi typeof(VirtualProtect) *const __imp_VirtualProtect;
bool cf;
int64_t rc;
uint32_t oldprot;

2
libc/calls/nice.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/fmt/conv.h"
#include "libc/sysv/consts/prio.h"

2
libc/calls/now.c

@ -19,7 +19,7 @@
*/
#include "libc/bits/bits.h"
#include "libc/bits/initializer.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/nexgen32e/rdtsc.h"

2
libc/calls/ntmagicpaths.c

@ -19,7 +19,7 @@
*/
#include "libc/calls/ntmagicpaths.internal.h"
const struct NtMagicPaths kNtMagicPaths = {
hidden const struct NtMagicPaths kNtMagicPaths = {
#define TAB(NAME, STRING) STRING,
#include "libc/calls/ntmagicpaths.inc"
#undef TAB

2
libc/calls/ntmagicpaths.internal.h

@ -9,7 +9,7 @@ struct NtMagicPaths {
#undef TAB
};
extern const struct NtMagicPaths kNtMagicPaths;
hidden extern const struct NtMagicPaths kNtMagicPaths;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

16
libc/calls/ntsetprivilege.c

@ -17,19 +17,21 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/nt/privilege.h"
#include "libc/nt/struct/tokenprivileges.h"
#include "libc/calls/internal.h"
/**
* Sets NT permission thing, e.g.
*
* int64_t htoken;
* if (OpenProcessToken(GetCurrentProcess(),
* kNtTokenAdjustPrivileges | kNtTokenQuery, &htoken)) {
* ntsetprivilege(htoken, u"SeManageVolumePrivilege", kNtSePrivilegeEnabled);
* CloseHandle(htoken);
* }
* int64_t htoken;
* if (OpenProcessToken(GetCurrentProcess(),
* kNtTokenAdjustPrivileges | kNtTokenQuery,
* &htoken)) {
* ntsetprivilege(htoken, u"SeManageVolumePrivilege",
* kNtSePrivilegeEnabled);
* CloseHandle(htoken);
* }
*/
textwindows bool32 ntsetprivilege(int64_t token, const char16_t *name,
uint32_t attrs) {

2
libc/calls/preadv.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"

2
libc/calls/pwritev.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"

2
libc/calls/sched_setaffinity.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"

2
libc/calls/setpriority-nt.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/internal.h"
#include "libc/calls/kntprioritycombos.internal.h"
#include "libc/nt/process.h"

2
libc/calls/sysinfo.c

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/sysinfo.h"

2
libc/calls/termios.internal.h

@ -1,7 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#ifndef __STRICT_ANSI__
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/struct/termios.h"
#include "libc/str/str.h"

2
libc/calls/zygote.c

@ -20,7 +20,7 @@
#include "libc/calls/internal.h"
#include "libc/nt/struct/securityattributes.h"
const struct NtSecurityAttributes kNtIsInheritable = {
hidden const struct NtSecurityAttributes kNtIsInheritable = {
sizeof(struct NtSecurityAttributes),
NULL,
true,

2
libc/dns/dnsnamecmp.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/dns/dns.h"
#include "libc/str/str.h"

2
libc/dns/getaddrinfo.c

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/dns/dns.h"
#include "libc/dns/hoststxt.h"

2
libc/dns/gethoststxt.c

@ -19,7 +19,7 @@
*/
#include "libc/bits/bits.h"
#include "libc/bits/pushpop.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/dce.h"
#include "libc/dns/hoststxt.h"
#include "libc/fmt/fmt.h"

2
libc/elf/elf.h

@ -4,7 +4,7 @@
#include "libc/elf/struct/phdr.h"
#include "libc/elf/struct/shdr.h"
#include "libc/elf/struct/sym.h"
#include "libc/runtime/ezmap.h"
#include "libc/runtime/ezmap.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

2
libc/fmt/kerrnonames.S

@ -22,8 +22,6 @@
.source __FILE__
/ Embeds ASCII names for errno constants into binary.
/
/ @see libc/sysv/consts.sh
.section .rodata,"aS",@progbits
kErrnoNames:
/ <SORTED-ORDER-C>

2
libc/fmt/kmonthyearday.c

@ -19,7 +19,7 @@
*/
#include "libc/time/time.h"
const unsigned short kMonthYearDay[2][12] = {
hidden const unsigned short kMonthYearDay[2][12] = {
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335},
};

36
libc/fmt/palandprintf.c

@ -91,27 +91,27 @@ static int ppatoi(const char **str) {
*
* Precision Modifiers
*
* - `%.8s` supplied byte length (obeys nul terminator)
* - `%.*s` supplied byte length argument (obeys nul terminator)
* - `%`.*s` supplied byte length argument c escaped (ignores nul terminator)
* - `%#.*s` supplied byte length argument visualized (ignores nul terminator)
* - `%.*hs` supplied char16_t length argument (obeys nul terminator)
* - `%.*ls` supplied wchar_t length argument (obeys nul terminator)
* - `%.8s` supplied byte length (obeys nul terminator)
* - `%.*s` supplied byte length argument (obeys nul terminator)
* - ``%`.*s`` supplied byte length argument c escaped (ignores nul term)
* - `%#.*s` supplied byte length argument visualized (ignores nul term)
* - `%.*hs` supplied char16_t length argument (obeys nul terminator)
* - `%.*ls` supplied wchar_t length argument (obeys nul terminator)
*
* Formatting Modifiers
*
* - `%,d` thousands separators
* - `%'s` escaped c string literal
* - `%`c` c escaped character
* - `%`'<