mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Apply some touchups
This commit is contained in:
parent
9f149e1de3
commit
2f3bd90216
139 changed files with 1188 additions and 1154 deletions
2
Makefile
2
Makefile
|
@ -52,7 +52,7 @@
|
|||
#
|
||||
# TROUBLESHOOTING
|
||||
#
|
||||
# make -j8 -O SILENT=0 o//examples/hello.com
|
||||
# make -j8 -O V=1 o//examples/hello.com
|
||||
# make o//examples/life.elf -pn |& less
|
||||
# etc.
|
||||
#
|
||||
|
|
15
README.md
15
README.md
|
@ -18,21 +18,20 @@ libc](https://justine.lol/cosmopolitan/index.html) website. We also have
|
|||
|
||||
## Getting Started
|
||||
|
||||
Here's how to get started with the freestanding hermetically-sealed
|
||||
monolithic source repository:
|
||||
Cosmopolitan can be compiled from source on any Linux distro.
|
||||
|
||||
```sh
|
||||
tar xf cosmopolitan-0.1.2.tar.gz # see our releases page
|
||||
cd cosmo
|
||||
make -j12
|
||||
tar xf cosmopolitan-0.1.2.tar.gz # see releases page
|
||||
cd cosmopolitan-0.1.2
|
||||
make -j16
|
||||
o//examples/hello.com
|
||||
find o -name \*.com | xargs ls -rShal | less
|
||||
```
|
||||
|
||||
Here's how to get started with the amalgamated binaries, which let you
|
||||
bring your own build system:
|
||||
Alternatively you can use the release binaries:
|
||||
|
||||
```sh
|
||||
unzip cosmopolitan-amalgamated-0.1.2.zip # see our releases page
|
||||
unzip cosmopolitan-amalgamated-0.1.2.zip # see releases page
|
||||
echo 'main() { printf("hello world\n"); }' >hello.c
|
||||
gcc -g -O -static -fno-pie -no-pie -mno-red-zone -nostdlib -nostdinc \
|
||||
-o hello.com.dbg hello.c -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -fuse-ld=bfd \
|
||||
|
|
|
@ -28,15 +28,15 @@ set -- o/build/bootstrap/ar.com "$@"
|
|||
OUT=$3
|
||||
|
||||
printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# if [ "$SILENT" = "0" ]; then
|
||||
# if [ "$V" = "0" ]; then
|
||||
# printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# else
|
||||
# # some of these windows nt archives are quite huge
|
||||
# COLUMNS=${COLUMNS:-80}
|
||||
# COLUMNS=$((COLUMNS - 4))
|
||||
# printf "%s\n" "$*" |
|
||||
# /usr/bin/fold -s -w $COLUMNS |
|
||||
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
||||
# else
|
||||
# printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# fi
|
||||
|
||||
REASON=failed
|
||||
|
|
|
@ -23,13 +23,12 @@ if [ ! -d o/third_party/gcc ]; then
|
|||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
export LC_ALL=C
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "%s\n" "$*" >&2
|
||||
else
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-OBJECTIFY.s}" "$TARGET" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
if [ "$TARGET" ]; then
|
||||
|
|
BIN
build/bootstrap/compile.com
Executable file
BIN
build/bootstrap/compile.com
Executable file
Binary file not shown.
|
@ -33,7 +33,6 @@ if [ "$1" = "clang++-10" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
export LC_ALL=C
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
GZME=
|
||||
|
@ -270,10 +269,10 @@ fi
|
|||
|
||||
set -- "$@" -no-canonical-prefixes $FDIAGNOSTIC_COLOR $ASAN $UBSAN $COUNTERMAND
|
||||
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "%s\n" "$*" >&2
|
||||
else
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-COMPILE}" "${TARGET:-$OUT}" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
OUTDIR="${OUT%/*}"
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
#
|
||||
# When tuning the variables below, please note they're interpreted in
|
||||
# the strictest sense. For example, we don't pass CFLAGS to gcc if we
|
||||
# know it's compiling a .S file. This allows our `make SILENT=0` logs
|
||||
# to be succinct and informative, at the cost of being less forgiving.
|
||||
# know it's compiling a .S file. This enables our `make V=0` logging
|
||||
# to be succinct and informative at the cost of being less forgiving.
|
||||
#
|
||||
# Further note that link order is equally unforgiving in repositories
|
||||
# of this scale. We approach that by over-specifying dependencies, in
|
||||
|
@ -42,6 +42,10 @@
|
|||
# ASFLAGS assembler flags (don't use -Wa, frontend prefix)
|
||||
# TARGET_ARCH microarchitecture flags (e.g. -march=native)
|
||||
|
||||
V ?= 1
|
||||
LC_ALL = C.UTF-8
|
||||
SOURCE_DATE_EPOCH = 0
|
||||
|
||||
DD ?= /bin/dd
|
||||
CP ?= /bin/cp -f
|
||||
RM ?= /bin/rm -f
|
||||
|
@ -49,7 +53,6 @@ SED ?= /bin/sed
|
|||
MKDIR ?= /bin/mkdir -p
|
||||
TAGS ?= /usr/bin/ctags # emacs source builds or something breaks it
|
||||
ARFLAGS = rcsD
|
||||
SILENT ?= 0
|
||||
ZFLAGS ?=
|
||||
XARGS ?= xargs -P4 -rs8000
|
||||
NICE ?= build/actuallynice
|
||||
|
@ -77,36 +80,51 @@ PWD := $(shell pwd)
|
|||
IMAGE_BASE_VIRTUAL ?= 0x400000
|
||||
TMPDIR := $(shell build/findtmp)
|
||||
LOGFMT := $(shell build/getlogfmt)
|
||||
COMPILE := $(shell build/getcompile)
|
||||
CCNAME := $(shell build/getccname $(CC))
|
||||
CCVERSION := $(shell build/getccversion $(CC))
|
||||
BLAH1 := $(shell build/zipobj 2>/dev/null)
|
||||
BLAH2 := $(shell build/package 2>/dev/null)
|
||||
|
||||
export ADDR2LINE
|
||||
export OBJDUMP
|
||||
export CCNAME
|
||||
export CCVERSION
|
||||
export CP
|
||||
export DD
|
||||
export GZ
|
||||
export IMAGE_BASE_VIRTUAL
|
||||
export LC_ALL
|
||||
export LOGFMT
|
||||
export MKDIR
|
||||
export MODE
|
||||
export OBJDUMP
|
||||
export RM
|
||||
export SED
|
||||
export SILENT
|
||||
export SOURCE_DATE_EPOCH
|
||||
export TMPDIR
|
||||
export V
|
||||
export ZFLAGS
|
||||
|
||||
unexport COMPILER_PATH
|
||||
unexport CPATH
|
||||
unexport CPLUS_INCLUDE_PATH
|
||||
unexport C_INCLUDE_PATH
|
||||
unexport DEPENDENCIES_OUTPUT
|
||||
unexport GCC_COMPARE_DEBUG
|
||||
unexport GCC_EXEC_PREFIX
|
||||
unexport LANG
|
||||
unexport LC_CTYPE
|
||||
unexport LC_MESSAGES
|
||||
unexport LIBRARY_PATH
|
||||
unexport OBJC_INCLUDE_PATH
|
||||
unexport SUNPRO_DEPENDENCIES
|
||||
|
||||
FTRACE = \
|
||||
-pg
|
||||
|
||||
SANITIZER = \
|
||||
-fsanitize=leak \
|
||||
-fsanitize=address \
|
||||
-fsanitize=implicit-signed-integer-truncation \
|
||||
-fsanitize=implicit-integer-sign-change
|
||||
-fsanitize=address
|
||||
|
||||
NO_MAGIC = \
|
||||
-mno-fentry \
|
||||
|
@ -154,8 +172,7 @@ MATHEMATICAL = \
|
|||
DEFAULT_CPPFLAGS = \
|
||||
-DIMAGE_BASE_VIRTUAL=$(IMAGE_BASE_VIRTUAL) \
|
||||
-nostdinc \
|
||||
-iquote - \
|
||||
-iquote .
|
||||
-iquote.
|
||||
|
||||
DEFAULT_CFLAGS = \
|
||||
-std=gnu2x
|
||||
|
|
6
build/do
6
build/do
|
@ -46,10 +46,10 @@ if [ "$OUT" ]; then
|
|||
fi
|
||||
|
||||
# Log command.
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "%s\n" "$*" >&2
|
||||
else
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-BUILD}" "$TARGET" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
|
|
|
@ -13,7 +13,5 @@
|
|||
# environment variable. Many programs use it under the hood, e.g. gcc,
|
||||
# so it grants many small performance improvements.
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
$MKDIR o/tmp
|
||||
mkdir -p o/tmp
|
||||
echo o/tmp
|
||||
|
|
12
build/getcompile
Executable file
12
build/getcompile
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
if ! [ o/build/bootstrap/compile.com -nt build/bootstrap/compile.com ]; then
|
||||
mkdir -p o/build/bootstrap/
|
||||
cp -f build/bootstrap/compile.com o/build/bootstrap/compile.$$.com
|
||||
o/build/bootstrap/compile.$$.com --do-nothing
|
||||
mv -f o/build/bootstrap/compile.$$.com o/build/bootstrap/compile.com
|
||||
fi
|
||||
|
||||
echo o/build/bootstrap/compile.com
|
|
@ -11,23 +11,19 @@
|
|||
# This program is invoked once by build/definitions.mk to choose the
|
||||
# most appropriate format string when logging command invocations.
|
||||
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "''"
|
||||
else
|
||||
W1=15
|
||||
if [ "$TERM" = "dumb" ]; then # e.g. emacs' dismal tty
|
||||
if [ "$COLUMNS" = "" ]; then
|
||||
if TPUT=$(command -v tput); then
|
||||
COLUMNS=$("$TPUT" cols)
|
||||
else
|
||||
COLUMNS=80
|
||||
fi
|
||||
W1=15
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
if [ "$COLUMNS" = "" ]; then
|
||||
if TPUT=$(command -v tput); then
|
||||
COLUMNS=$("$TPUT" cols)
|
||||
else
|
||||
COLUMNS=80
|
||||
fi
|
||||
COLUMNS=$((COLUMNS - 1))
|
||||
W2=$((COLUMNS - W1))
|
||||
printf '%%-%ds%%-%ds\\r' "$W1" "$W2"
|
||||
else
|
||||
echo ♥cosmo >&2
|
||||
printf '\\033[F\\033[K%%-%ds%%s\\r\\n' "$W1"
|
||||
fi
|
||||
COLUMNS=$((COLUMNS - 1))
|
||||
W2=$((COLUMNS - W1))
|
||||
printf '%%-%ds%%-%ds\\r' "$W1" "$W2"
|
||||
else
|
||||
echo ♥cosmo >&2
|
||||
printf '\\033[F\\033[K%%-%ds%%s\\r\\n' "$W1"
|
||||
fi
|
||||
|
|
|
@ -19,7 +19,6 @@ if [ ! -d o/third_party/gcc ]; then
|
|||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
export LC_ALL=C # very important for ld
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
OUT=
|
||||
|
@ -41,10 +40,10 @@ for x; do
|
|||
set -- "$@" "$x"
|
||||
done
|
||||
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "%s\n" "$*" >&2
|
||||
else
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-LINK.elf}" "$OUT" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
OUTDIR="${OUT%/*}"
|
||||
|
|
|
@ -13,10 +13,10 @@ else
|
|||
set -- o/build/bootstrap/mkdeps.com "$@"
|
||||
fi
|
||||
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "%s\n" "$*" >&2
|
||||
else
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-MKDEPS}" "$3" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
|
|
|
@ -20,14 +20,14 @@ else
|
|||
fi
|
||||
|
||||
printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# if [ "$SILENT" = "0" ]; then
|
||||
# if [ "$V" = "0" ]; then
|
||||
# printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# else
|
||||
# COLUMNS=${COLUMNS:-80}
|
||||
# COLUMNS=$((COLUMNS - 4))
|
||||
# printf "%s\n" "$*" |
|
||||
# /usr/bin/fold -s -w $COLUMNS |
|
||||
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
||||
# else
|
||||
# printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# fi
|
||||
|
||||
exec "$@"
|
||||
|
|
116
build/rules.mk
116
build/rules.mk
|
@ -17,72 +17,72 @@
|
|||
MAKEFLAGS += --no-builtin-rules
|
||||
|
||||
o/%.a:; @$(ARCHIVE) $@ $^
|
||||
o/%.o: %.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.i: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.lds: %.lds; @ACTION=PREPROCESS build/compile $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/%.inc: %.h; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
|
||||
o/%.o: %.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.i: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.lds: %.lds; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/%.inc: %.h; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
|
||||
o/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/%.h.ok: %.h; @ACTION=CHECK.h build/compile $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/%.h.okk: %.h; @ACTION=CHECK.h build/compile $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/%.h.ok: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/%.h.okk: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/%.zip.o: o/%; @build/zipobj $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
|
||||
o/$(MODE)/%.a:; @$(ARCHIVE) $@ $^
|
||||
o/$(MODE)/%: o/$(MODE)/%.dbg; @ACTION=OBJCOPY TARGET=$@ build/do $(OBJCOPY) -SO binary $< $@
|
||||
o/$(MODE)/%.o: %.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.c; @ACTION=OBJECTIFY.c build/compile $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.f; @ACTION=OBJECTIFY.f build/compile $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.F; @ACTION=OBJECTIFY.F build/compile $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.c; @ACTION=OBJECTIFY.c build/compile $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: %.c; @ACTION=COMPILE.c build/compile $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: o/$(MODE)/%.c; @ACTION=OBJECTIFY.s build/compile $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.c; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.cc; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: o/$(MODE)/%.c; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h: %.c; @ACTION=AMALGAMATE build/compile $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.h: o/$(MODE)/%.c; @ACTION=AMALGAMATE build/compile $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.o: %.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.lds: %.lds; @ACTION=PREPROCESS build/compile $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h.ok: %.h; @ACTION=CHECK.h build/compile $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/$(MODE)/%.h.okk: %.h; @ACTION=CHECK.h build/compile $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/$(MODE)/%.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.ansi.c; @ACTION=OBJECTIFY.ansi build/compile $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.c; @ACTION=OBJECTIFY.ansi build/compile $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c99.o: %.c99.c; @ACTION=OBJECTIFY.c99 build/compile $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c11.o: %.c11.c; @ACTION=OBJECTIFY.c11 build/compile $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c2x.o: %.c2x.c; @ACTION=OBJECTIFY.c2x build/compile $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.initabi.o: %.initabi.c; @ACTION=OBJECTIFY.init build/compile $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ncabi.o: %.ncabi.c; @ACTION=OBJECTIFY.nc build/compile $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.real.o: %.c; @ACTION=OBJECTIFY.real build/compile $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%: o/$(MODE)/%.dbg; @ACTION=OBJCOPY TARGET=$@ $(COMPILE) $(OBJCOPY) -SO binary $< $@
|
||||
o/$(MODE)/%.o: %.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: %.c; @ACTION=COMPILE.c $(COMPILE) $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: o/$(MODE)/%.c; @ACTION=OBJECTIFY.s $(COMPILE) $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.c; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.cc; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: o/$(MODE)/%.c; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h: %.c; @ACTION=AMALGAMATE $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.h: o/$(MODE)/%.c; @ACTION=AMALGAMATE $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.o: %.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.lds: %.lds; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h.ok: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/$(MODE)/%.h.okk: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/$(MODE)/%.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.ansi.c; @ACTION=OBJECTIFY.ansi $(COMPILE) $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.c; @ACTION=OBJECTIFY.ansi $(COMPILE) $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c99.o: %.c99.c; @ACTION=OBJECTIFY.c99 $(COMPILE) $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c11.o: %.c11.c; @ACTION=OBJECTIFY.c11 $(COMPILE) $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c2x.o: %.c2x.c; @ACTION=OBJECTIFY.c2x $(COMPILE) $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.initabi.o: %.initabi.c; @ACTION=OBJECTIFY.init $(COMPILE) $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ncabi.o: %.ncabi.c; @ACTION=OBJECTIFY.nc $(COMPILE) $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.real.o: %.c; @ACTION=OBJECTIFY.real $(COMPILE) $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.runs: o/$(MODE)/%; @ACTION=CHECK.runs TARGET=$< build/runcom $< $(TESTARGS) && touch $@
|
||||
o/$(MODE)/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/$(MODE)/%.zip.o: %; @build/zipobj $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
|
||||
o/$(MODE)/%-gcc.asm: %.c; @ACTION=OBJECTIFY.c build/compile $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-gcc.asm: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.c; @ACTION=OBJECTIFY.c build/compile $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.f; @ACTION=OBJECTIFY.f build/compile $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.f; @ACTION=OBJECTIFY.f build/compile $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.F; @ACTION=OBJECTIFY.F build/compile $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.F; @ACTION=OBJECTIFY.F build/compile $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-clang.asm: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
|
|
|
@ -42,10 +42,10 @@ else
|
|||
set -- o/build/bootstrap/zipobj.com "$@"
|
||||
fi
|
||||
|
||||
if [ "$SILENT" = "0" ]; then
|
||||
printf "%s\n" "$*" >&2
|
||||
else
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-ZIPOBJ}" "$3" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/sysinfo.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/tms.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/typedef/sighandler_t.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/pflink.h"
|
||||
|
@ -54,17 +61,6 @@ COSMOPOLITAN_C_START_
|
|||
│ cosmopolitan § system calls ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
struct dirstream;
|
||||
struct iovec;
|
||||
struct rlimit;
|
||||
struct rusage;
|
||||
struct sigaction;
|
||||
struct sigset;
|
||||
struct stat;
|
||||
struct sysinfo;
|
||||
struct tms;
|
||||
struct utsname;
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
typedef struct dirstream DIR;
|
||||
|
||||
|
@ -196,12 +192,12 @@ int wait(int *);
|
|||
int wait3(int *, int, struct rusage *);
|
||||
int wait4(int, int *, int, struct rusage *);
|
||||
int waitpid(int, int *, int);
|
||||
int64_t lseek(int, int64_t, int);
|
||||
int64_t pread(int, void *, size_t, int64_t);
|
||||
int64_t preadv(int, struct iovec *, int, int64_t);
|
||||
int64_t pwrite(int, const void *, size_t, int64_t);
|
||||
int64_t pwritev(int, const struct iovec *, int, int64_t);
|
||||
int64_t syscall();
|
||||
ssize_t lseek(int, int64_t, unsigned);
|
||||
ssize_t pread(int, void *, size_t, int64_t);
|
||||
ssize_t preadv(int, struct iovec *, int, int64_t);
|
||||
ssize_t pwrite(int, const void *, size_t, int64_t);
|
||||
ssize_t pwritev(int, const struct iovec *, int, int64_t);
|
||||
intptr_t syscall(int, ...);
|
||||
void sync(void);
|
||||
long telldir(DIR *);
|
||||
int getpid(void);
|
||||
|
|
|
@ -17,7 +17,6 @@ LIBC_CALLS = $(LIBC_CALLS_A_DEPS) $(LIBC_CALLS_A)
|
|||
LIBC_CALLS_A = o/$(MODE)/libc/calls/syscalls.a
|
||||
LIBC_CALLS_A_FILES := \
|
||||
$(wildcard libc/calls/typedef/*) \
|
||||
$(wildcard libc/calls/thunks/*) \
|
||||
$(wildcard libc/calls/struct/*) \
|
||||
$(wildcard libc/calls/*)
|
||||
LIBC_CALLS_A_HDRS = $(filter %.h,$(LIBC_CALLS_A_FILES))
|
||||
|
|
|
@ -44,6 +44,5 @@
|
|||
* @see fchmod()
|
||||
*/
|
||||
int chmod(const char *pathname, uint32_t mode) {
|
||||
if (!pathname) return efault();
|
||||
return sys_fchmodat(AT_FDCWD, pathname, mode, 0);
|
||||
}
|
||||
|
|
|
@ -16,22 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mach.h"
|
||||
#include "libc/nt/struct/filetime.h"
|
||||
#include "libc/nt/struct/systemtime.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
/**
|
||||
* Returns nanosecond time.
|
||||
|
@ -43,40 +33,34 @@
|
|||
* @param clockid can be CLOCK_REALTIME, CLOCK_MONOTONIC, etc. noting
|
||||
* that on Linux CLOCK_MONOTONIC is redefined to use the monotonic
|
||||
* clock that's actually monotonic lool
|
||||
* @param out_ts is where the nanoseconds are stored if non-NULL
|
||||
* @return 0 on success or -1 w/ errno on error
|
||||
* @param ts is where the result is stored
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @error ENOSYS if clockid isn't available; in which case this function
|
||||
* guarantees an ordinary timestamp is still stored to out_ts; and
|
||||
* guarantees an ordinary timestamp is still stored to ts; and
|
||||
* errno isn't restored to its original value, to detect prec. loss
|
||||
* @see strftime(), gettimeofday()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int clock_gettime(int clockid, struct timespec *out_ts) {
|
||||
/* TODO(jart): Just ignore O/S for MONOTONIC and measure RDTSC on start */
|
||||
int clock_gettime(int clockid, struct timespec *ts) {
|
||||
int rc;
|
||||
axdx_t ad;
|
||||
struct NtFileTime ft;
|
||||
if (!ts) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (!IsXnu()) {
|
||||
if (out_ts) {
|
||||
out_ts->tv_sec = 0;
|
||||
out_ts->tv_nsec = 0;
|
||||
if ((rc = sys_clock_gettime(clockid, ts)) == -1 && errno == ENOSYS) {
|
||||
ad = sys_gettimeofday((struct timeval *)ts, NULL, NULL);
|
||||
assert(ad.ax != -1);
|
||||
if (SupportsXnu() && ad.ax) {
|
||||
ts->tv_sec = ad.ax;
|
||||
ts->tv_nsec = ad.dx;
|
||||
}
|
||||
return sys_clock_gettime(clockid, out_ts);
|
||||
} else {
|
||||
int rc;
|
||||
_Static_assert(sizeof(struct timeval) == sizeof(struct timespec));
|
||||
if (out_ts) {
|
||||
out_ts->tv_sec = 0;
|
||||
out_ts->tv_nsec = 0;
|
||||
}
|
||||
rc = sys_gettimeofday((struct timeval *)out_ts, NULL);
|
||||
if (out_ts) {
|
||||
out_ts->tv_nsec *= 1000;
|
||||
}
|
||||
return rc;
|
||||
ts->tv_nsec *= 1000;
|
||||
rc = 0;
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
struct NtFileTime ft;
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
*out_ts = FileTimeToTimeSpec(ft);
|
||||
*ts = FileTimeToTimeSpec(ft);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||
size_t i;
|
||||
char **shargs;
|
||||
if (__sys_execve(prog, argv, envp) != -1) return 0;
|
||||
__sys_execve(prog, argv, envp);
|
||||
if (errno != ENOEXEC) return -1;
|
||||
for (i = 0; argv[i];) ++i;
|
||||
shargs = alloca((i + 2) * sizeof(char *));
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
|
||||
if (!path) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_faccessat(dirfd, path, mode, flags);
|
||||
} else {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
int ftruncate(int fd, int64_t length) {
|
||||
if (!IsWindows()) {
|
||||
return sys_ftruncate(fd, length);
|
||||
return sys_ftruncate(fd, length, length);
|
||||
} else {
|
||||
return sys_ftruncate_nt(fd, length);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows char *sys_getcwd_nt(char *buf, size_t size) {
|
||||
uint16_t name16[PATH_MAX];
|
||||
char16_t name16[PATH_MAX];
|
||||
if (GetCurrentDirectory(ARRAYLEN(name16), name16)) {
|
||||
tprecode16to8(buf, size, name16);
|
||||
return buf;
|
||||
|
|
|
@ -24,9 +24,8 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#define NETBSD_F_GETPATH 15
|
||||
#define XNU_F_GETPATH 50
|
||||
#define XNU_MAXPATHLEN 1024
|
||||
#define XNU_F_GETPATH 50
|
||||
#define XNU_MAXPATHLEN 1024
|
||||
|
||||
char *sys_getcwd_xnu(char *res, size_t size) {
|
||||
int fd;
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
/**
|
||||
* Returns value of environment variable, or NULL if not found.
|
||||
*
|
||||
* Environment variables can store empty string on Unix but not Windows.
|
||||
*/
|
||||
char *getenv(const char *s) {
|
||||
char **p;
|
||||
|
@ -29,7 +31,7 @@ char *getenv(const char *s) {
|
|||
for (j = 0;; ++j) {
|
||||
if (!s[j]) {
|
||||
if (p[i][j] == '=') {
|
||||
return &p[i][j + 1];
|
||||
return p[i] + j + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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 │
|
||||
│ │
|
||||
|
@ -16,26 +16,27 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/ Makes fork() kernel ABI consistent across UNIX systems.
|
||||
/
|
||||
/ @return 0 if parent, pid if child, or -1 on error
|
||||
sys_fork:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
call __sys_fork
|
||||
#if SupportsXnu()
|
||||
testb IsXnu()
|
||||
jz 1f
|
||||
cmp $-1,%rax
|
||||
je 1f
|
||||
neg %edx # edx is 0 for parent and 1 for child
|
||||
not %edx # eax always returned with childs pid
|
||||
and %edx,%eax
|
||||
#endif
|
||||
1: pop %rbp
|
||||
ret
|
||||
.endfn sys_fork,globl,hidden
|
||||
#define CTL_KERN 1
|
||||
#define KERN_HOSTNAME 10
|
||||
|
||||
int gethostname_bsd(char *name, size_t len) {
|
||||
char *p;
|
||||
int cmd[2];
|
||||
char buf[254];
|
||||
size_t buflen;
|
||||
cmd[0] = CTL_KERN;
|
||||
cmd[1] = KERN_HOSTNAME;
|
||||
buflen = sizeof(buf);
|
||||
if (sysctl(cmd, 2, buf, &buflen, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM) errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
strncpy(name, buf, len);
|
||||
name[len - 1] = '\0';
|
||||
if ((p = strchr(name, '.'))) *p = '\0';
|
||||
return 0;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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 │
|
||||
│ │
|
||||
|
@ -16,11 +16,16 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/ Directly calls pread() impl on host o/s if available.
|
||||
sys_pread:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pread
|
||||
.endfn sys_pread,globl,hidden
|
||||
int gethostname_linux(char *name, size_t len) {
|
||||
struct utsname u;
|
||||
if (uname(&u) == -1) return -1;
|
||||
memccpy(name, u.nodename, '\0', len);
|
||||
name[len - 1] = '\0';
|
||||
return 0;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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 │
|
||||
│ │
|
||||
|
@ -16,22 +16,20 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/ Directly calls lseek() impl on host o/s if available.
|
||||
sys_lseek:
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
testb $OPENBSD|NETBSD,__hostos(%rip)
|
||||
cmovnz %rdx,%rcx # openbsd:evilpad
|
||||
cmovnz %rsi,%rdx
|
||||
cmovnz .Lzero(%rip),%rsi
|
||||
#endif
|
||||
jmp __sys_lseek
|
||||
.endfn sys_lseek,globl,hidden
|
||||
|
||||
.rodata.cst8
|
||||
.Lzero: .quad 0
|
||||
.endobj .Lzero
|
||||
.previous
|
||||
textwindows int gethostname_nt(char *name, size_t len) {
|
||||
uint32_t nSize;
|
||||
char16_t name16[256];
|
||||
nSize = ARRAYLEN(name16);
|
||||
if (GetComputerNameEx(kNtComputerNameDnsHostname, name16, &nSize)) {
|
||||
tprecode16to8(name, len, name16);
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
|
@ -18,20 +18,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#define CTL_KERN 1
|
||||
#define KERN_HOSTNAME 10
|
||||
|
||||
/**
|
||||
* Returns name of host system, e.g.
|
||||
*
|
||||
|
@ -42,38 +31,12 @@ int gethostname(char *name, size_t len) {
|
|||
if (len < 1) return einval();
|
||||
if (!name) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (IsBsd()) {
|
||||
char *p;
|
||||
int cmd[2];
|
||||
char buf[254];
|
||||
size_t buflen;
|
||||
cmd[0] = CTL_KERN;
|
||||
cmd[1] = KERN_HOSTNAME;
|
||||
buflen = sizeof(buf);
|
||||
if (sysctl(cmd, 2, buf, &buflen, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM) errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
strncpy(name, buf, len);
|
||||
name[len - 1] = '\0';
|
||||
if ((p = strchr(name, '.'))) *p = '\0';
|
||||
return 0;
|
||||
if (!IsBsd()) {
|
||||
return gethostname_linux(name, len);
|
||||
} else {
|
||||
struct utsname u;
|
||||
if (uname(&u) == -1) return -1;
|
||||
memccpy(name, u.nodename, '\0', len);
|
||||
name[len - 1] = '\0';
|
||||
return 0;
|
||||
return gethostname_bsd(name, len);
|
||||
}
|
||||
} else {
|
||||
uint32_t nSize;
|
||||
char16_t name16[256];
|
||||
nSize = ARRAYLEN(name16);
|
||||
if (GetComputerNameEx(kNtComputerNameDnsHostname, name16, &nSize)) {
|
||||
tprecode16to8(name, len, name16);
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
return gethostname_nt(name, len);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,15 @@
|
|||
#include "libc/nt/thread.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows int sys_getrusage_nt(int who, struct rusage *usage) {
|
||||
struct NtFileTime CreationFileTime;
|
||||
struct NtFileTime ExitFileTime;
|
||||
struct NtFileTime KernelFileTime;
|
||||
struct NtFileTime UserFileTime;
|
||||
if (!usage) return efault();
|
||||
if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */
|
||||
memset(usage, 0, sizeof(*usage));
|
||||
if ((who == RUSAGE_SELF ? GetProcessTimes : GetThreadTimes)(
|
||||
(who == RUSAGE_SELF ? GetCurrentProcess : GetCurrentThread)(),
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
* @return 0 on success, or -1 w/ errno
|
||||
*/
|
||||
int getrusage(int who, struct rusage *usage) {
|
||||
if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */
|
||||
if (!usage) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_getrusage(who, usage);
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
/ Calls GetTempPathA() w/ different API.
|
||||
/
|
||||
/ @see GetSystemDirectoryA(), GetWindowsDirectoryA()
|
||||
GetTempPathA$flunk:
|
||||
GetTempPathA_flunk:
|
||||
xchg %rcx,%rdx
|
||||
jmp *__imp_GetTempPathA(%rip)
|
||||
.endfn GetTempPathA$flunk,globl,hidden
|
||||
.endfn GetTempPathA_flunk,globl,hidden
|
|
@ -1,53 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns system wall time in microseconds.
|
||||
/
|
||||
/ @param rdi points to timeval that receives result
|
||||
/ @param rsi receives UTC timezone if non-NULL
|
||||
/ @return always zero
|
||||
/ @see clock_gettime() for nanosecond precision
|
||||
/ @see strftime() for string formatting
|
||||
sys_gettimeofday:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
test %rsi,%rsi
|
||||
jz 1f
|
||||
push $0
|
||||
pop (%rsi)
|
||||
1: xor %esi,%esi # no one zones this way.
|
||||
xor %edx,%edx # i64*mach_absolute_time
|
||||
call __sys_gettimeofday
|
||||
#if SupportsXnu()
|
||||
testb IsXnu() # XNU might do %rax:%rdx
|
||||
jz 1f
|
||||
test %rdi,%rdi
|
||||
jz 1f
|
||||
test %rax,%rax
|
||||
jz 1f
|
||||
mov %rax,(%rdi)
|
||||
mov %rdx,8(%rdi)
|
||||
#endif
|
||||
1: xor %eax,%eax # nevar fail
|
||||
pop %rbp
|
||||
ret
|
||||
.endfn sys_gettimeofday,globl,hidden
|
|
@ -16,9 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
|
@ -32,8 +34,15 @@
|
|||
* @see strftime() for string formatting
|
||||
*/
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
||||
axdx_t ad;
|
||||
if (!IsWindows()) {
|
||||
return sys_gettimeofday(tv, tz);
|
||||
ad = sys_gettimeofday(tv, tz, NULL);
|
||||
assert(ad.ax != -1);
|
||||
if (SupportsXnu() && ad.ax && tv) {
|
||||
tv->tv_sec = ad.ax;
|
||||
tv->tv_usec = ad.dx;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return sys_gettimeofday_nt(tv, tz);
|
||||
}
|
||||
|
|
|
@ -100,6 +100,10 @@ forceinline size_t clampio(size_t size) {
|
|||
│ cosmopolitan § syscalls » system five » synthetic jump slots ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
axdx_t __sys_pipe(i32[hasatleast 2], i32) hidden;
|
||||
axdx_t sys_fork(void) hidden;
|
||||
axdx_t sys_getpid(void) hidden;
|
||||
axdx_t sys_gettimeofday(struct timeval *, struct timezone *, void *) hidden;
|
||||
char *sys_getcwd(char *, u64) hidden;
|
||||
char *sys_getcwd_xnu(char *, u64) hidden;
|
||||
i32 __sys_dup3(i32, i32, i32) hidden;
|
||||
|
@ -127,11 +131,10 @@ i32 sys_fchownat(i32, const char *, u32, u32, u32) hidden;
|
|||
i32 sys_fcntl(i32, i32, ...) hidden;
|
||||
i32 sys_fdatasync(i32) hidden;
|
||||
i32 sys_flock(i32, i32) hidden;
|
||||
i32 sys_fork(void) hidden;
|
||||
i32 sys_fstat(i32, struct stat *) hidden;
|
||||
i32 sys_fstatat(i32, const char *, struct stat *, i32) hidden;
|
||||
i32 sys_fsync(i32) hidden;
|
||||
i32 sys_ftruncate(i32, i64) hidden;
|
||||
i32 sys_ftruncate(i32, i64, i64) hidden;
|
||||
i32 sys_futimes(i32, const struct timeval *) hidden;
|
||||
i32 sys_futimesat(i32, const char *, const struct timeval *) hidden;
|
||||
i32 sys_getitimer(i32, struct itimerval *) hidden;
|
||||
|
@ -139,11 +142,10 @@ i32 sys_getppid(void) hidden;
|
|||
i32 sys_getpriority(i32, u32) hidden;
|
||||
i32 sys_getrlimit(i32, struct rlimit *) hidden;
|
||||
i32 sys_getrusage(i32, struct rusage *) hidden;
|
||||
i32 sys_gettimeofday(struct timeval *, struct timezone *) hidden;
|
||||
i32 sys_ioctl(i32, u64, void *) hidden;
|
||||
i32 sys_kill(i32, i32, i32) hidden;
|
||||
i32 sys_linkat(i32, const char *, i32, const char *, i32) hidden;
|
||||
i32 sys_lseek(i32, i64, i32) hidden;
|
||||
i32 sys_lseek(i32, i64, i64, i64) hidden;
|
||||
i32 sys_lutimes(const char *, const struct timeval *) hidden;
|
||||
i32 sys_madvise(void *, size_t, i32) hidden;
|
||||
i32 sys_memfd_create(const char *, u32) hidden;
|
||||
|
@ -176,7 +178,7 @@ i32 sys_symlinkat(const char *, i32, const char *) hidden;
|
|||
i32 sys_sync(void) hidden;
|
||||
i32 sys_sync_file_range(i32, i64, i64, u32) hidden;
|
||||
i32 sys_sysinfo(struct sysinfo *) hidden;
|
||||
i32 sys_truncate(const char *, u64) hidden;
|
||||
i32 sys_truncate(const char *, u64, u64) hidden;
|
||||
i32 sys_uname(char *) hidden;
|
||||
i32 sys_unlinkat(i32, const char *, i32) hidden;
|
||||
i32 sys_utime(const char *, const struct utimbuf *) hidden;
|
||||
|
@ -185,22 +187,21 @@ i32 sys_utimes(const char *, const struct timeval *) hidden;
|
|||
i32 sys_wait4(i32, i32 *, i32, struct rusage *) hidden;
|
||||
i64 sys_copy_file_range(i32, long *, i32, long *, u64, u32) hidden;
|
||||
i64 sys_getrandom(void *, u64, u32) hidden;
|
||||
i64 sys_pread(i32, void *, u64, i64) hidden;
|
||||
i64 sys_preadv(i32, struct iovec *, i32, i64) hidden;
|
||||
i64 sys_pread(i32, void *, u64, i64, i64) hidden;
|
||||
i64 sys_preadv(i32, struct iovec *, i32, i64, i64) hidden;
|
||||
i64 sys_ptrace(int, i32, void *, void *) hidden;
|
||||
i64 sys_pwrite(i32, const void *, u64, i64) hidden;
|
||||
i64 sys_pwritev(i32, const struct iovec *, i32, i64) hidden;
|
||||
i64 sys_pwrite(i32, const void *, u64, i64, i64) hidden;
|
||||
i64 sys_pwritev(i32, const struct iovec *, i32, i64, i64) hidden;
|
||||
i64 sys_read(i32, void *, u64) hidden;
|
||||
i64 sys_sendfile(i32, i32, i64 *, u64) hidden;
|
||||
i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) hidden;
|
||||
i64 sys_vmsplice(i32, const struct iovec *, i64, u32) hidden;
|
||||
i64 sys_write(i32, const void *, u64) hidden;
|
||||
u32 sys_getgid(void) hidden;
|
||||
axdx_t sys_getpid(void) hidden;
|
||||
u32 sys_getsid(int) hidden;
|
||||
u32 sys_gettid(void) hidden;
|
||||
u32 sys_getuid(void) hidden;
|
||||
void *sys_mmap(void *, u64, u32, u32, i64, i64) hidden;
|
||||
void *sys_mmap(void *, u64, u32, u32, i64, i64, i64) hidden;
|
||||
void *sys_mremap(void *, u64, u64, i32, void *) hidden;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
|
@ -219,6 +220,9 @@ void __stat2linux(void *) hidden;
|
|||
void __restore_rt_netbsd(void) hidden;
|
||||
void __xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
|
||||
const struct __darwin_ucontext *) hidden wontreturn;
|
||||
int gethostname_linux(char *, size_t) hidden;
|
||||
int gethostname_bsd(char *, size_t) hidden;
|
||||
int gethostname_nt(char *, size_t) hidden;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § syscalls » windows nt » veneers ─╬─│┼
|
||||
|
|
|
@ -27,7 +27,7 @@ static int ioctl_tcgets_sysv(int fd, struct termios *tio) {
|
|||
int rc;
|
||||
union metatermios t;
|
||||
if ((rc = sys_ioctl(fd, TCGETS, &t)) != -1) {
|
||||
termios2linux(tio, &t);
|
||||
__termios2linux(tio, &t);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,14 @@
|
|||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int ioctl_tcsets_nt(int, uint64_t, const struct termios *);
|
||||
|
||||
static int ioctl_tcsets_sysv(int fd, uint64_t request,
|
||||
const struct termios *tio) {
|
||||
union metatermios t;
|
||||
return sys_ioctl(fd, request, termios2host(&t, tio));
|
||||
return sys_ioctl(fd, request, __termios2host(&t, tio));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,6 +39,7 @@ static int ioctl_tcsets_sysv(int fd, uint64_t request,
|
|||
* @see ioctl(fd, TIOCGETA{,W,F}, tio) dispatches here
|
||||
*/
|
||||
int ioctl_tcsets(int fd, uint64_t request, const struct termios *tio) {
|
||||
if (!tio) return efault();
|
||||
if (!IsWindows()) {
|
||||
return ioctl_tcsets_sysv(fd, request, tio);
|
||||
} else {
|
||||
|
|
|
@ -35,7 +35,7 @@ kTmpPath:
|
|||
movl $'/|'t<<010|'m<<020|'p<<030,(%rdi)
|
||||
movw $'/,4(%rdi)
|
||||
pushpop kTmpPathMax,%rdx
|
||||
ezlea GetTempPathA$flunk,ax
|
||||
ezlea GetTempPathA_flunk,ax
|
||||
call __getntsyspath
|
||||
.init.end 300,_init_kTmpPath
|
||||
.source __FILE__
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Creates hard filesystem link.
|
||||
|
@ -32,7 +32,6 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int link(const char *existingpath, const char *newpath) {
|
||||
if (!existingpath || !newpath) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_linkat(AT_FDCWD, existingpath, AT_FDCWD, newpath, 0);
|
||||
} else {
|
||||
|
|
|
@ -29,9 +29,11 @@
|
|||
* @return new position relative to beginning, or -1 on error
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int64_t lseek(int fd, int64_t offset, int whence) {
|
||||
if (!IsWindows()) {
|
||||
return sys_lseek(fd, offset, whence);
|
||||
int64_t lseek(int fd, int64_t offset, unsigned whence) {
|
||||
if (!IsWindows() && !IsOpenbsd() && !IsNetbsd()) {
|
||||
return sys_lseek(fd, offset, whence, 0);
|
||||
} else if (IsOpenbsd() || IsNetbsd()) {
|
||||
return sys_lseek(fd, offset, offset, whence);
|
||||
} else {
|
||||
return sys_lseek_nt(fd, offset, whence);
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ textwindows int __mkntpath2(const char *path,
|
|||
* 5. Reserve ≥13 for mkdir() i.e. 1+8+3+1, e.g. "\\ffffffff.xxx\0"
|
||||
*/
|
||||
size_t i, n;
|
||||
if (!path) return efault();
|
||||
path = FixNtMagicPath(path, flags);
|
||||
n = tprecode8to16(path16, PATH_MAX - 16, path).ax;
|
||||
if (n == PATH_MAX - 16 - 1) return enametoolong();
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
*/
|
||||
int nanosleep(const struct timespec *req, struct timespec *rem) {
|
||||
if (!req) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (!IsMetal()) {
|
||||
if (!IsXnu()) {
|
||||
return sys_nanosleep(req, rem);
|
||||
} else {
|
||||
return sys_nanosleep_xnu(req, rem);
|
||||
}
|
||||
} else {
|
||||
return enosys(); /* TODO: Sleep on Metal */
|
||||
}
|
||||
if (!IsWindows() && !IsMetal() && !IsXnu()) {
|
||||
return sys_nanosleep(req, rem);
|
||||
} else if (IsXnu()) {
|
||||
return sys_nanosleep_xnu(req, rem);
|
||||
} else if (IsMetal()) {
|
||||
return enosys(); /* TODO: Sleep on Metal */
|
||||
} else {
|
||||
return sys_nanosleep_nt(req, rem);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,14 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.windows
|
||||
.source __FILE__
|
||||
|
||||
__onntconsoleevent_nt:
|
||||
ezlea __onntconsoleevent,ax
|
||||
jmp __nt2sysv
|
||||
.endfn __onntconsoleevent_nt,globl,hidden
|
||||
|
||||
.init.start 300,_init_onntconsoleevent
|
||||
ezlea __onntconsoleevent_nt,cx
|
||||
pushpop 1,%rdx
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
nodiscard int openat(int dirfd, const char *file, int flags, ...) {
|
||||
int openat(int dirfd, const char *file, int flags, ...) {
|
||||
va_list va;
|
||||
unsigned mode;
|
||||
struct ZiposUri zipname;
|
||||
|
|
|
@ -78,9 +78,13 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
|
|||
pipefd[1] = writer;
|
||||
return 0;
|
||||
} else {
|
||||
__winerr();
|
||||
CloseHandle(hin);
|
||||
}
|
||||
} else {
|
||||
__winerr();
|
||||
}
|
||||
__releasefd(writer);
|
||||
__releasefd(reader);
|
||||
return __winerr();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Creates file descriptors for IPC.
|
||||
/
|
||||
/ @param rdi points to int3[2] that gets (reader, writer)
|
||||
/ @return 0 on success or -1 w/ errno
|
||||
/ @asyncsignalsafe
|
||||
/ @see libc/sysv/syscalls.sh
|
||||
/ @see pipe2()
|
||||
sys_pipe:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
#if SupportsFreebsd()
|
||||
xor %esi,%esi
|
||||
#endif
|
||||
call __sys_pipe
|
||||
#if SupportsXnu() || SupportsNetbsd()
|
||||
testb $XNU|NETBSD,__hostos(%rip)
|
||||
jz 1f
|
||||
cmp $-1,%rax
|
||||
je 1f
|
||||
mov %eax,(%rdi)
|
||||
mov %edx,4(%rdi)
|
||||
xor %eax,%eax
|
||||
#endif
|
||||
1: pop %rbp
|
||||
ret
|
||||
.endfn sys_pipe,globl,hidden
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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 │
|
||||
│ │
|
||||
|
@ -16,19 +16,19 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Pauses process w/ standard ABI.
|
||||
sys_sigsuspend:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jz 1f
|
||||
mov (%rdi),%edi # openbsd:byvalue
|
||||
#endif
|
||||
1: call __sys_sigsuspend
|
||||
pop %rbp
|
||||
ret
|
||||
.endfn sys_sigsuspend,globl
|
||||
int sys_pipe(int fds[2]) {
|
||||
axdx_t ad;
|
||||
int ax, dx;
|
||||
ad = __sys_pipe(fds, 0);
|
||||
ax = ad.ax;
|
||||
dx = ad.dx;
|
||||
if ((IsXnu() || IsNetbsd()) && ax != -1) {
|
||||
fds[0] = ax;
|
||||
fds[1] = dx;
|
||||
ax = 0;
|
||||
}
|
||||
return ax;
|
||||
}
|
|
@ -16,9 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) {
|
|||
rc = weaken(__zipos_read)(
|
||||
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, buf, size, offset);
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_pread(fd, buf, size, offset);
|
||||
rc = sys_pread(fd, buf, size, offset, offset);
|
||||
} else if (__isfdkind(fd, kFdFile)) {
|
||||
rc = sys_read_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset);
|
||||
} else {
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/sysv/consts/iov.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
@ -42,7 +42,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
int olderr;
|
||||
ssize_t rc;
|
||||
if (!count) return 0;
|
||||
if ((count = min(count, IOV_MAX)) < 0) return einval();
|
||||
if ((count = MIN(count, IOV_MAX)) < 0) return einval();
|
||||
|
||||
/*
|
||||
* NT, XNU, and 2007-era Linux don't support this system call.
|
||||
|
@ -58,7 +58,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
demodernize = true;
|
||||
} else {
|
||||
olderr = errno;
|
||||
rc = sys_preadv(fd, iovec, count, off);
|
||||
rc = sys_preadv(fd, iovec, count, off, off);
|
||||
if (rc == -1 && errno == ENOSYS) {
|
||||
errno = olderr;
|
||||
demodernize = true;
|
||||
|
@ -71,7 +71,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
}
|
||||
|
||||
if (!demodernize) {
|
||||
return sys_preadv(fd, iovec, count, off);
|
||||
return sys_preadv(fd, iovec, count, off, off);
|
||||
} else {
|
||||
return pread(fd, iovec[0].iov_base, iovec[0].iov_len, off);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
|
|||
if (fd == -1 || offset < 0) return einval();
|
||||
size = MIN(size, 0x7ffff000);
|
||||
if (!IsWindows()) {
|
||||
rc = sys_pwrite(fd, buf, size, offset);
|
||||
rc = sys_pwrite(fd, buf, size, offset, offset);
|
||||
} else if (__isfdkind(fd, kFdFile)) {
|
||||
rc = sys_write_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset);
|
||||
} else {
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/sysv/consts/iov.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
@ -45,9 +45,8 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
static bool once, demodernize;
|
||||
int olderr;
|
||||
ssize_t rc;
|
||||
|
||||
if (!count) return 0;
|
||||
if ((count = min(count, IOV_MAX)) < 0) return einval();
|
||||
if ((count = MIN(count, IOV_MAX)) < 0) return einval();
|
||||
|
||||
/*
|
||||
* NT, XNU, and 2007-era Linux don't support this system call.
|
||||
|
@ -63,7 +62,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
demodernize = true;
|
||||
} else {
|
||||
olderr = errno;
|
||||
rc = sys_pwritev(fd, iovec, count, off);
|
||||
rc = sys_pwritev(fd, iovec, count, off, off);
|
||||
if (rc == -1 && errno == ENOSYS) {
|
||||
errno = olderr;
|
||||
demodernize = true;
|
||||
|
@ -77,7 +76,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
}
|
||||
|
||||
if (!demodernize) {
|
||||
return sys_pwritev(fd, iovec, count, off);
|
||||
return sys_pwritev(fd, iovec, count, off, off);
|
||||
} else {
|
||||
return pwrite(fd, iovec[0].iov_base, iovec[0].iov_len, off);
|
||||
}
|
||||
|
|
|
@ -24,21 +24,37 @@
|
|||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/struct/overlapped.h"
|
||||
#include "libc/nt/struct/teb.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
uint32_t got;
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
size_t i, total;
|
||||
uint32_t got, size;
|
||||
struct NtOverlapped overlap;
|
||||
while (iovlen && !iov[0].iov_len) iov++, iovlen--;
|
||||
if (ReadFile(fd->handle, iovlen ? iov[0].iov_base : NULL,
|
||||
iovlen ? clampio(iov[0].iov_len) : 0, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return got;
|
||||
} else if (NtGetErr() == kNtErrorBrokenPipe) {
|
||||
return 0; /* read() doesn't EPIPE lool */
|
||||
if (iovlen) {
|
||||
for (total = i = 0; i < iovlen; ++i) {
|
||||
size = clampio(iov[i].iov_len);
|
||||
if (ReadFile(fd->handle, iov[i].iov_base, size, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
total += got;
|
||||
if (opt_offset != -1) opt_offset += got;
|
||||
if (got < iov[i].iov_len) break;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
break; /* read() doesn't EPIPE lool */
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
return total;
|
||||
} else {
|
||||
return __winerr();
|
||||
if (ReadFile(fd->handle, NULL, 0, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return got;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
*/
|
||||
int renameat(int olddirfd, const char *oldpath, int newdirfd,
|
||||
const char *newpath) {
|
||||
if (!oldpath || !newpath) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_renameat(olddirfd, oldpath, newdirfd, newpath);
|
||||
} else {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
@ -37,8 +38,18 @@
|
|||
* @vforksafe
|
||||
*/
|
||||
int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) {
|
||||
if (!IsWindows()) {
|
||||
int32_t x;
|
||||
if (!IsWindows() && !IsOpenbsd()) {
|
||||
return sys_sigprocmask(how, opt_set, opt_out_oldset, 8);
|
||||
} else if (IsOpenbsd()) {
|
||||
if (!opt_set) how = 1;
|
||||
if (opt_set) opt_set = (sigset_t *)(uintptr_t)(*(uint32_t *)opt_set);
|
||||
if ((x = sys_sigprocmask(how, opt_set, 0, 0)) != -1) {
|
||||
if (opt_out_oldset) memcpy(opt_out_oldset, &x, sizeof(x));
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return 0; /* TODO(jart): Implement me! */
|
||||
}
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int sigsuspend(const sigset_t *ignore) {
|
||||
if (!ignore) return efault();
|
||||
unsigned x;
|
||||
if (!IsWindows()) {
|
||||
if (IsOpenbsd()) ignore = (sigset_t *)(uintptr_t)(*(uint32_t *)ignore);
|
||||
return sys_sigsuspend(ignore, 8);
|
||||
} else {
|
||||
return enosys(); /* TODO(jart): Implement me! */
|
||||
|
|
|
@ -82,13 +82,13 @@ static textstartup void __stat2linux_netbsd(union metastat *ms) {
|
|||
*/
|
||||
textstartup void __stat2linux(void *ms) {
|
||||
if (ms) {
|
||||
if (SupportsXnu() && IsXnu()) {
|
||||
if (IsXnu()) {
|
||||
__stat2linux_xnu((union metastat *)ms);
|
||||
} else if (SupportsFreebsd() && IsFreebsd()) {
|
||||
} else if (IsFreebsd()) {
|
||||
__stat2linux_freebsd((union metastat *)ms);
|
||||
} else if (SupportsOpenbsd() && IsOpenbsd()) {
|
||||
} else if (IsOpenbsd()) {
|
||||
__stat2linux_openbsd((union metastat *)ms);
|
||||
} else if (SupportsNetbsd() && IsNetbsd()) {
|
||||
} else if (IsNetbsd()) {
|
||||
__stat2linux_netbsd((union metastat *)ms);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_
|
||||
#ifndef __STRICT_ANSI__
|
||||
#include "libc/calls/struct/termios.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
@ -33,5 +32,4 @@ union metatermios {
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* !ANSI */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_ */
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "libc/dce.h"
|
||||
|
||||
/**
|
||||
* Flushes file system changes to disk to the greatest extent possible.
|
||||
* Flushes file system changes to disk by any means necessary.
|
||||
*/
|
||||
void sync(void) {
|
||||
if (!IsWindows()) {
|
||||
|
|
|
@ -21,8 +21,8 @@ COSMOPOLITAN_C_START_
|
|||
(TO)->c_ospeed = (FROM)->c_ospeed; \
|
||||
} while (0)
|
||||
|
||||
void *termios2host(union metatermios *, const struct termios *);
|
||||
void termios2linux(struct termios *, const union metatermios *);
|
||||
void *__termios2host(union metatermios *, const struct termios *) hidden;
|
||||
void __termios2linux(struct termios *, const union metatermios *) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
void *termios2host(union metatermios *t, const struct termios *lt) {
|
||||
if (IsXnu()) {
|
||||
void *__termios2host(union metatermios *t, const struct termios *lt) {
|
||||
if (!IsXnu() && !IsFreebsd() && !IsOpenbsd() && !IsNetbsd()) {
|
||||
return lt;
|
||||
} else if (IsXnu()) {
|
||||
COPY_TERMIOS(&t->xnu, lt);
|
||||
return &t->xnu;
|
||||
} else if (IsFreebsd() || IsOpenbsd()) {
|
||||
} else {
|
||||
COPY_TERMIOS(&t->bsd, lt);
|
||||
return &t->bsd;
|
||||
} else {
|
||||
return lt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
void termios2linux(struct termios *lt, const union metatermios *t) {
|
||||
void __termios2linux(struct termios *lt, const union metatermios *t) {
|
||||
if (IsXnu()) {
|
||||
COPY_TERMIOS(lt, &t->xnu);
|
||||
} else if (IsFreebsd() || IsOpenbsd()) {
|
||||
} else if (IsFreebsd() || IsOpenbsd() || IsNetbsd()) {
|
||||
COPY_TERMIOS(lt, &t->bsd);
|
||||
} else {
|
||||
memcpy(lt, &t->linux, sizeof(*lt));
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls ftruncate() impl on host o/s if available.
|
||||
sys_ftruncate:
|
||||
mov %rsi,%rdx # netbsd+openbsd:pad
|
||||
jmp __sys_ftruncate
|
||||
.endfn sys_ftruncate,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.windows
|
||||
.source __FILE__
|
||||
|
||||
__onntconsoleevent_nt:
|
||||
ezlea __onntconsoleevent,ax
|
||||
jmp __nt2sysv
|
||||
.endfn __onntconsoleevent_nt,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls preadv() impl on host o/s if available.
|
||||
sys_preadv:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_preadv
|
||||
.endfn sys_preadv,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls pwrite() impl on host o/s if available.
|
||||
sys_pwrite:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pwrite
|
||||
.endfn sys_pwrite,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls pwritev() impl on host o/s if available.
|
||||
sys_pwritev:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pwritev
|
||||
.endfn sys_pwritev,globl,hidden
|
|
@ -1,46 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Sets System Five process signal mask w/ standard ABI.
|
||||
sys_sigprocmask:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jz 4f
|
||||
test %rsi,%rsi
|
||||
jnz 1f
|
||||
mov $1,%edi # SIG_BLOCK on BSDs
|
||||
jmp 2f
|
||||
1: mov (%rsi),%esi # openbsd:byvalue
|
||||
2: call __sys_sigprocmask
|
||||
cmp $-1,%eax
|
||||
je 5f
|
||||
test %rdx,%rdx # original param not a result
|
||||
jz 3f
|
||||
mov %eax,(%rdx) # openbsd:byvalue
|
||||
3: xor %eax,%eax
|
||||
jmp 5f
|
||||
#endif
|
||||
4: call __sys_sigprocmask
|
||||
5: pop %rbp
|
||||
ret
|
||||
.endfn sys_sigprocmask,globl
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls truncate() impl on host o/s if available.
|
||||
sys_truncate:
|
||||
mov %rsi,%rdx # netbsd+openbsd:pad
|
||||
jmp __sys_truncate
|
||||
.endfn sys_truncate,globl,hidden
|
|
@ -32,9 +32,8 @@
|
|||
* @error ENOENT
|
||||
*/
|
||||
int truncate(const char *path, uint64_t length) {
|
||||
if (!path) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_truncate(path, length);
|
||||
return sys_truncate(path, length, length);
|
||||
} else {
|
||||
return sys_truncate_nt(path, length);
|
||||
}
|
||||
|
|
|
@ -16,27 +16,32 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Removes environment variable.
|
||||
*/
|
||||
int unsetenv(const char *name) {
|
||||
if (isempty(name) || strchr(name, '=')) return einval();
|
||||
if (environ) {
|
||||
char **ep = environ;
|
||||
size_t removed = 0;
|
||||
size_t namelen = strlen(name);
|
||||
do {
|
||||
if (*ep && strncmp(*ep, name, namelen) == 0 && (*ep)[namelen] == '=') {
|
||||
--removed;
|
||||
} else if (removed) {
|
||||
ep[removed] = *ep;
|
||||
int unsetenv(const char *s) {
|
||||
char **p;
|
||||
size_t i, j, k;
|
||||
if (s && (p = environ)) {
|
||||
for (i = 0; p[i]; ++i) {
|
||||
for (j = 0;; ++j) {
|
||||
if (!s[j]) {
|
||||
if (p[i][j] == '=') {
|
||||
k = i + 1;
|
||||
do {
|
||||
p[k - 1] = p[k];
|
||||
} while (p[k++]);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (s[j] != p[i][j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (*ep++);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -25,7 +25,7 @@
|
|||
#include "libc/nt/struct/overlapped.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static size_t SumIovecLen(const struct iovec *v, size_t n) {
|
||||
static textwindows size_t SumIovecLen(const struct iovec *v, size_t n) {
|
||||
size_t i, sum;
|
||||
for (sum = i = 0; i < n; ++i) {
|
||||
sum += v[i].iov_len;
|
||||
|
@ -34,16 +34,32 @@ static size_t SumIovecLen(const struct iovec *v, size_t n) {
|
|||
}
|
||||
|
||||
textwindows ssize_t sys_write_nt(struct Fd *fd, const struct iovec *iov,
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
uint32_t wrote;
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
size_t i, total;
|
||||
uint32_t size, wrote;
|
||||
struct NtOverlapped overlap;
|
||||
while (iovlen && !iov[0].iov_len) iov++, iovlen--;
|
||||
if (WriteFile(fd->handle, iovlen ? iov[0].iov_base : NULL,
|
||||
iovlen ? clampio(iov[0].iov_len) : 0, &wrote,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
if (!wrote) assert(!SumIovecLen(iov, iovlen));
|
||||
return wrote;
|
||||
if (iovlen) {
|
||||
for (total = i = 0; i < iovlen; ++i) {
|
||||
if (!iov[i].iov_len) continue;
|
||||
size = clampio(iov[0].iov_len);
|
||||
if (WriteFile(fd->handle, iov[i].iov_base, size, &wrote,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
total += wrote;
|
||||
if (opt_offset != -1) opt_offset += wrote;
|
||||
if (wrote < iov[i].iov_len) break;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
if (!total) assert(!SumIovecLen(iov, iovlen));
|
||||
return total;
|
||||
} else {
|
||||
return __winerr();
|
||||
if (WriteFile(fd->handle, NULL, 0, &wrote,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
23
libc/dce.h
23
libc/dce.h
|
@ -51,12 +51,6 @@
|
|||
#define UseSecurityBlankets() 0
|
||||
#endif
|
||||
|
||||
#ifdef __MGENERAL_REGS_ONLY__
|
||||
#define UseGeneralRegsOnly() 1
|
||||
#else
|
||||
#define UseGeneralRegsOnly() 0
|
||||
#endif
|
||||
|
||||
#ifdef TINY
|
||||
#define IsTiny() 1
|
||||
#else
|
||||
|
@ -87,15 +81,14 @@
|
|||
((SUPPORT_VECTOR & (LINUX | METAL | XNU | OPENBSD | FREEBSD | NETBSD)) != 0)
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
#define __HOSTOS (__hostos & SUPPORT_VECTOR)
|
||||
#define IsLinux() ((__HOSTOS & LINUX) == LINUX)
|
||||
#define IsMetal() ((__HOSTOS & METAL) == METAL)
|
||||
#define IsWindows() ((__HOSTOS & WINDOWS) == WINDOWS)
|
||||
#define IsBsd() ((__HOSTOS & (XNU | FREEBSD | OPENBSD | NETBSD)) != 0)
|
||||
#define IsXnu() ((__HOSTOS & XNU) == XNU)
|
||||
#define IsFreebsd() ((__HOSTOS & FREEBSD) == FREEBSD)
|
||||
#define IsOpenbsd() ((__HOSTOS & OPENBSD) == OPENBSD)
|
||||
#define IsNetbsd() ((__HOSTOS & NETBSD) == NETBSD)
|
||||
#define IsLinux() (SupportsLinux() && (__hostos & LINUX))
|
||||
#define IsMetal() (SupportsMetal() && (__hostos & METAL))
|
||||
#define IsWindows() (SupportsWindows() && (__hostos & WINDOWS))
|
||||
#define IsXnu() (SupportsXnu() && (__hostos & XNU))
|
||||
#define IsFreebsd() (SupportsFreebsd() && (__hostos & FREEBSD))
|
||||
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & OPENBSD))
|
||||
#define IsNetbsd() (SupportsNetbsd() && (__hostos & NETBSD))
|
||||
#define IsBsd() (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
|
||||
#else
|
||||
/* clang-format off */
|
||||
#define IsLinux() $LINUX,__hostos(%rip)
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "libc/fmt/conv.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#define ISDELIM(c) (c == '/' || c == '\\' || c == '.')
|
||||
#define ISSLASH(c) (c == '/' || c == '\\')
|
||||
#define ISDELIM(c) (ISSLASH(c) || c == '.')
|
||||
|
||||
/**
|
||||
* Returns directory portion of path.
|
||||
|
@ -30,7 +31,7 @@ char *dirname(char *s) {
|
|||
if (!(n = strlen(s))) return s;
|
||||
while (n && ISDELIM(s[n - 1])) --n;
|
||||
if (n) {
|
||||
while (n && !ISDELIM(s[n - 1])) --n;
|
||||
while (n && !ISSLASH(s[n - 1])) --n;
|
||||
if (n) {
|
||||
while (n && ISDELIM(s[n - 1])) --n;
|
||||
if (!n) ++n;
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
│ be thread safe). │
|
||||
└─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/paland.inc"
|
||||
#include "libc/fmt/palandprintf.internal.h"
|
||||
#include "libc/fmt/palandprintf.h"
|
||||
#include "libc/math.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/paland.inc"
|
||||
#include "libc/fmt/palandprintf.internal.h"
|
||||
#include "libc/fmt/palandprintf.h"
|
||||
|
||||
uintmax_t __udivmodti4(uintmax_t, uintmax_t, uintmax_t *);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/paland.inc"
|
||||
#include "libc/fmt/palandprintf.internal.h"
|
||||
#include "libc/fmt/palandprintf.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_FMT_PFLINK_H_
|
||||
#define COSMOPOLITAN_LIBC_FMT_PFLINK_H_
|
||||
#include "libc/dce.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/unicode/unicode.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifndef __STRICT_ANSI__
|
||||
|
||||
|
@ -79,11 +83,6 @@ __asm__(".section .yoink\n\t"
|
|||
"nopl\t__grow(%rip)\n\t"
|
||||
".previous");
|
||||
#else
|
||||
#include "libc/fmt/palandprintf.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/unicode/unicode.h"
|
||||
static long __pflink(long x) {
|
||||
x |= kCp437[0];
|
||||
x |= ntoa(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/palandprintf.internal.h"
|
||||
#include "libc/fmt/palandprintf.h"
|
||||
|
||||
int spacepad(int out(long, void *), void *arg, unsigned long n) {
|
||||
int i, rc;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/fmt/paland.inc"
|
||||
#include "libc/fmt/palandprintf.internal.h"
|
||||
#include "libc/fmt/palandprintf.h"
|
||||
#include "libc/nexgen32e/tinystrlen.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/thompike.h"
|
||||
|
|
|
@ -32,7 +32,7 @@ int PutEnvImpl(char *s, bool overwrite) {
|
|||
if (!p) goto fail;
|
||||
namelen = p + 1 - s;
|
||||
for (i = 0; environ[i]; ++i) {
|
||||
if (strncmp(environ[i], s, namelen) == 0) {
|
||||
if (!strncmp(environ[i], s, namelen)) {
|
||||
if (!overwrite) {
|
||||
free(s);
|
||||
return 0;
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
noasan struct DirectMap __mmap(void *addr, size_t size, int prot, int flags,
|
||||
int fd, int64_t off) {
|
||||
if (!IsWindows()) {
|
||||
return (struct DirectMap){sys_mmap(addr, size, prot, flags, fd, off),
|
||||
return (struct DirectMap){sys_mmap(addr, size, prot, flags, fd, off, off),
|
||||
kNtInvalidHandleValue};
|
||||
} else {
|
||||
return sys_mmap_nt(addr, size, prot, flags,
|
||||
|
|
|
@ -28,14 +28,22 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int fork(void) {
|
||||
int rc;
|
||||
axdx_t ad;
|
||||
int ax, dx;
|
||||
if (!IsWindows()) {
|
||||
rc = sys_fork();
|
||||
ad = sys_fork();
|
||||
ax = ad.ax;
|
||||
dx = ad.dx;
|
||||
if (IsXnu() && ax != -1) {
|
||||
/* eax always returned with childs pid */
|
||||
/* edx is 0 for parent and 1 for child */
|
||||
ax &= dx - 1;
|
||||
}
|
||||
} else {
|
||||
rc = sys_fork_nt();
|
||||
ax = sys_fork_nt();
|
||||
}
|
||||
if (rc == 0) {
|
||||
if (!ax) {
|
||||
__onfork();
|
||||
}
|
||||
return rc;
|
||||
return ax;
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ o/$(MODE)/libc/runtime/winmain.greg.o: \
|
|||
OVERRIDE_CFLAGS += \
|
||||
$(NO_MAGIC)
|
||||
|
||||
o/$(MODE)/libc/runtime/ftrace.greg.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-mgeneral-regs-only
|
||||
|
||||
LIBC_RUNTIME_LIBS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)))
|
||||
LIBC_RUNTIME_SRCS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_RUNTIME_HDRS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)_HDRS))
|
||||
|
|
|
@ -59,7 +59,7 @@ static ssize_t sendfile_linux2netflix(int outfd, int infd,
|
|||
int64_t offset, sbytes;
|
||||
if (inout_opt_inoffset) {
|
||||
offset = *inout_opt_inoffset;
|
||||
} else if ((offset = sys_lseek(infd, 0, SEEK_CUR)) == -1) {
|
||||
} else if ((offset = lseek(infd, 0, SEEK_CUR)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
if ((rc = sys_sendfile_netflix(infd, outfd, offset, uptobytes, NULL, &sbytes,
|
||||
|
|
|
@ -16,42 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static void KnuthMorrisPrattInit(ssize_t m, ssize_t *T, const char *W) {
|
||||
ssize_t i = 2;
|
||||
ssize_t j = 0;
|
||||
T[0] = -1;
|
||||
T[1] = 0;
|
||||
while (i < m) {
|
||||
if (W[i - 1] == W[j]) {
|
||||
T[i++] = j++ + 1;
|
||||
} else if (j > 0) {
|
||||
j = T[j];
|
||||
} else {
|
||||
T[i++] = 0;
|
||||
}
|
||||
}
|
||||
T[m] = 0;
|
||||
}
|
||||
|
||||
static size_t KnuthMorrisPratt(long m, const long *T, const char *W, long n,
|
||||
const char *S) {
|
||||
long i = 0, j = 0;
|
||||
while (i + j < n) {
|
||||
if (W[i] == S[i + j]) {
|
||||
i++;
|
||||
if (i == m) break;
|
||||
} else {
|
||||
j = j + i - T[i];
|
||||
if (i > 0) i = T[i];
|
||||
}
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for fixed-length substring in memory region.
|
||||
*
|
||||
|
@ -61,24 +27,16 @@ static size_t KnuthMorrisPratt(long m, const long *T, const char *W, long n,
|
|||
* @param needlelen is its character count
|
||||
* @return pointer to first result or NULL if not found
|
||||
*/
|
||||
void *memmem(const void *haystackp, size_t haystacklen, const void *needlep,
|
||||
void *memmem(const void *haystack, size_t haystacklen, const void *needle,
|
||||
size_t needlelen) {
|
||||
long *T;
|
||||
size_t i;
|
||||
const char *haystack, *needle, *h;
|
||||
needle = needlep;
|
||||
haystack = haystackp;
|
||||
if (needlelen > haystacklen) return NULL;
|
||||
size_t i, j;
|
||||
if (!needlelen) return haystack;
|
||||
h = memchr(haystack, *needle, haystacklen);
|
||||
if (!h || needlelen == 1) return h;
|
||||
haystacklen -= h - haystack;
|
||||
if (needlelen < haystacklen && memcmp(h, needle, needlelen) == 0) {
|
||||
return h;
|
||||
} else {
|
||||
T = alloca((needlelen + 1) * sizeof(long));
|
||||
KnuthMorrisPrattInit(needlelen, T, needle);
|
||||
i = KnuthMorrisPratt(needlelen, T, needle, haystacklen, h);
|
||||
return i < haystacklen ? h + i : NULL;
|
||||
for (i = 0; i < haystacklen; ++i) {
|
||||
for (j = 0;; ++j) {
|
||||
if (j == needlelen) return (/*unconst*/ char *)haystack + i;
|
||||
if (i + j == haystacklen) break;
|
||||
if (((char *)needle)[j] != ((char *)haystack)[i + j]) break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -28,5 +28,15 @@
|
|||
* @see memmem()
|
||||
*/
|
||||
char *strstr(const char *haystack, const char *needle) {
|
||||
return memmem(haystack, strlen(haystack), needle, strlen(needle));
|
||||
size_t i;
|
||||
for (;;) {
|
||||
for (i = 0;;) {
|
||||
if (!needle[i]) return (/*unconst*/ char *)haystack;
|
||||
if (!haystack[i]) break;
|
||||
if (needle[i] != haystack[i]) break;
|
||||
++i;
|
||||
}
|
||||
if (!*haystack++) break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_fork 0x0020020022002039 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_ftruncate 0x0c90c91e020c904d globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_gettimeofday 0x1a20430742074060 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_lseek 0x0c70c71de20c7008 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_mmap 0x0c50c51dd20c5009 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_pread 0x0ad0ad1db2099011 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_preadv 0x12110b121ffff127 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_pwrite 0x0ae0ae1dc209a012 globl hidden
|
|
@ -1,2 +0,0 @@
|
|||
.include "o/libc/sysv/macros.internal.inc"
|
||||
.scall __sys_pwritev 0x12210c122ffff128 globl hidden
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue