Browse Source

Add minor improvements and cleanup

main
Justine Tunney 1 year ago
parent
commit
feed0d2b0e
  1. 1
      Makefile
  2. 3
      ape/lib/pc.h
  3. 26
      build/realify.sed
  4. 15
      dsp/tty/itoa8.c
  5. 93
      dsp/tty/ttyraster.c
  6. 1
      dsp/tty/ttyraw.c
  7. 1
      examples/ctrlc.c
  8. 1
      examples/findprime.c
  9. 2
      examples/subprocess.c
  10. 118
      examples/unbourne.c
  11. 10
      libc/calls/calls.h
  12. 13
      libc/calls/fcntl-nt.c
  13. 7
      libc/calls/fcntl.c
  14. 40
      libc/calls/fixntmagicpath.ncabi.c
  15. 16
      libc/calls/internal.h
  16. 32
      libc/calls/mkntpath.ncabi.c
  17. 2
      libc/calls/setitimer-nt.c
  18. 2
      libc/calls/thunks/onntconsoleevent.S
  19. 8
      libc/calls/thunks/onwincrash.S
  20. 8
      libc/calls/thunks/winalarm.S
  21. 4
      libc/calls/winalarm.c
  22. 2
      libc/calls/wincrash.c
  23. 6
      libc/calls/wincrash_init.S
  24. 5
      libc/crt/crt.S
  25. 2
      libc/dns/getaddrinfo.c
  26. 262
      libc/errno.h
  27. 47
      libc/escape/aescape.c
  28. 64
      libc/escape/cunescape.c
  29. 22
      libc/escape/escape.h
  30. 57
      libc/escape/escape.mk
  31. 73
      libc/escape/escapesh.c
  32. 3
      libc/fmt/palandprintf.c
  33. 1
      libc/fmt/stoa.c
  34. 2
      libc/fmt/strerror_r.c
  35. 24
      libc/log/asan.c
  36. 25
      libc/log/checkfail.c
  37. 2
      libc/log/checkfail_ndebug.c
  38. 20
      libc/log/color.h
  39. 26
      libc/log/internal.h
  40. 1
      libc/log/log.h
  41. 1
      libc/log/log.mk
  42. 13
      libc/log/oncrash.c
  43. 46
      libc/log/oncrashthunks.S
  44. 1
      libc/log/perror.c
  45. 4
      libc/log/showcrashreports.c
  46. 13
      libc/log/startfatal.c
  47. 8
      libc/log/startfatal_ndebug.c
  48. 4
      libc/log/ubsan.c
  49. 1
      libc/log/verr.c
  50. 1
      libc/log/verrx.c
  51. 5
      libc/log/vflogf.c
  52. 1
      libc/log/vwarn.c
  53. 1
      libc/log/vwarnx.c
  54. 14
      libc/mem/malloc_trim.c
  55. 5
      libc/nexgen32e/nt2sysv.S
  56. 11
      libc/nexgen32e/strsak.S
  57. 1
      libc/rand/rand.mk
  58. 8
      libc/stdio/g_stderr_init.S
  59. 8
      libc/stdio/g_stdin_init.S
  60. 8
      libc/stdio/g_stdout_init.S
  61. 1
      libc/stdio/stdio.mk
  62. 1
      libc/stdio/system.c
  63. 13
      libc/str/endswith.c
  64. 1
      libc/str/escapedos.c
  65. 8
      libc/str/getkvlin.c
  66. 13
      libc/str/indexdoublenulstring.c
  67. 19
      libc/str/internal.h
  68. 1
      libc/str/isascii.c
  69. 64
      libc/str/isnotplaintext.c
  70. 56
      libc/str/ktpdecoderring.S
  71. 4
      libc/str/startswith.c
  72. 43
      libc/str/stpcpy.c
  73. 28
      libc/str/str.h
  74. 1
      libc/str/str.mk
  75. 18
      libc/str/strclen.c
  76. 31
      libc/str/strcpy.c
  77. 38
      libc/str/strlen.c
  78. 4
      libc/str/thompike.h
  79. 2
      libc/stubs/sysv2nt.S
  80. 2
      libc/sysv/calls/vfork.s
  81. 11
      libc/sysv/consts.sh
  82. 2
      libc/sysv/consts/MAP_FIXED.s
  83. 2
      libc/sysv/consts/MAP_NONBLOCK.s
  84. 2
      libc/sysv/consts/__NR_vfork.s
  85. 2
      libc/sysv/syscalls.sh
  86. 6
      libc/sysv/systemfive.S
  87. 2
      libc/sysv/sysv.mk
  88. 40
      libc/sysv/vfork.S
  89. 1
      libc/testlib/showerror.c
  90. 1
      libc/testlib/showerror_.c
  91. 2
      libc/time/dsleep.c
  92. 91
      libc/unicode/strnwidth.c
  93. 58
      libc/unicode/strwidth.c
  94. 33
      libc/unicode/unicode.h
  95. 5
      libc/unicode/wcwidth.c
  96. 5
      libc/x/x.h
  97. 1
      libc/x/x.mk
  98. 31
      libc/x/xaescapec.c
  99. 34
      libc/x/xaescapesh.c
  100. 1
      net/http/http.mk

1
Makefile

@ -117,7 +117,6 @@ include libc/ohmyplus/ohmyplus.mk # │
include libc/zipos/zipos.mk # │
include third_party/dtoa/dtoa.mk # │
include libc/time/time.mk # │
include libc/escape/escape.mk # │
include libc/alg/alg.mk # │
include libc/calls/hefty/hefty.mk # │
include libc/stdio/stdio.mk # │

3
ape/lib/pc.h

@ -128,7 +128,7 @@
/* Long Mode Paging
@see Intel Manual V.3A §4.1 §4.5
IsValid (ignored on CR3) V
Block Instr. Fetches (if NXE) IsWritable (ignored on CR3) RW
XD:No Inst. Fetches (if NXE) IsWritable (ignored on CR3) RW
Permit User-Mode Access - u
Page-level Write-Through - PWT
Page-level Cache Disable - PCD
@ -147,7 +147,6 @@
Phys. Addr. 1GB
0b00000000000011111111111111111111111111111111111111000000000000
6666555555555544444444443333333333222222222211111111110000000000
3210987654321098765432109876543210987654321098765432109876543210*/
#define PAGE_V /* */ 0b000000001

26
build/realify.sed

@ -15,22 +15,22 @@
# remove comments
s/[ \t][ \t]*#.*//
#s/leave\(q\|\)/leavew/
#s/call\(q\|\)/callw/
#s/ret\(q\|\)/retw/
#s/popq\t%rbp/pop\t%bp/
#s/pushq\t%rbp/push\t%bp/
#s/pushq\t\(.*\)/sub $6,%sp\n\tpush \1/
#s/popq\t\(.*\)/pop \1\n\tadd $6,%sp/
# preserve hardcoded stack offsets
# bloats code size 13%
s/leave\(q\|\)/leavew\n\tadd\t$6,%sp/
s/call\(q\|\)\t/sub\t$6,%sp\n\tcallw\t/
s/ret\(q\|\)/retw\t$6/
s/leave\(q\|\)/leavew/
s/call\(q\|\)/callw/
s/ret\(q\|\)/retw/
s/popq\t%rbp/pop\t%bp/
s/pushq\t%rbp/push\t%bp/
s/pushq\t\(.*\)/sub\t$6,%sp\n\tpush\t\1/
s/popq\t\(.*\)/pop\t\1\n\tadd\t$6,%sp/
# # preserve hardcoded stack offsets
# # bloats code size 13%
# s/leave\(q\|\)/leavew\n\tadd\t$6,%sp/
# s/call\(q\|\)\t/sub\t$6,%sp\n\tcallw\t/
# s/ret\(q\|\)/retw\t$6/
# s/pushq\t\(.*\)/sub\t$6,%sp\n\tpush\t\1/
# s/popq\t\(.*\)/pop\t\1\n\tadd\t$6,%sp/
s/, /,/g
# 32-bitify

15
dsp/tty/itoa8.c

@ -27,24 +27,21 @@ struct Itoa8 kItoa8;
static textstartup void itoa8_init(void) {
int i;
uint8_t z;
char p[4];
uint32_t w;
for (i = 0; i < 256; ++i) {
memset(p, 0, sizeof(p));
if (i < 10) {
z = 1;
p[0] = '0' + i;
w = '0' + i;
} else if (i < 100) {
z = 2;
p[0] = '0' + i / 10;
p[1] = '0' + i % 10;
w = ('0' + i / 10) | ('0' + i % 10) << 8;
} else {
z = 3;
p[0] = '0' + i / 100;
p[1] = '0' + i % 100 / 10;
p[2] = '0' + i % 100 % 10;
w = ('0' + i / 100) | ('0' + i % 100 / 10) << 8 |
('0' + i % 100 % 10) << 16;
}
kItoa8.size[i] = z;
memcpy(&kItoa8.data[i], p, sizeof(p));
kItoa8.data[i] = w;
}
}

93
dsp/tty/ttyraster.c

@ -240,9 +240,10 @@ static const struct Pick kPicksMixBlock[32] = {
{TL, TR, 9}, /* ▓ */
};
static unsigned short bdist(struct TtyRgb a, struct TtyRgb b, struct TtyRgb c,
struct TtyRgb d, struct TtyRgb w, struct TtyRgb x,
struct TtyRgb y, struct TtyRgb z) {
static unsigned short GetBlockDist(struct TtyRgb a, struct TtyRgb b,
struct TtyRgb c, struct TtyRgb d,
struct TtyRgb w, struct TtyRgb x,
struct TtyRgb y, struct TtyRgb z) {
unsigned short dist;
dist = 0;
dist += ABS(a.r - w.r);
@ -260,7 +261,7 @@ static unsigned short bdist(struct TtyRgb a, struct TtyRgb b, struct TtyRgb c,
return dist;
}
static uint16_t *mixblock(uint16_t *p, struct TtyRgb ttl, struct TtyRgb ttr,
static uint16_t *MixBlock(uint16_t *p, struct TtyRgb ttl, struct TtyRgb ttr,
struct TtyRgb tbl, struct TtyRgb tbr,
struct TtyRgb qtl, struct TtyRgb qtr,
struct TtyRgb qbl, struct TtyRgb qbr) {
@ -465,15 +466,15 @@ static uint16_t *mixblock(uint16_t *p, struct TtyRgb ttl, struct TtyRgb ttr,
return p;
}
static struct TtyRgb getquant(struct TtyRgb rgb) {
static struct TtyRgb GetQuant(struct TtyRgb rgb) {
return g_ansi2rgb_[rgb.xt];
}
static uint16_t *pickunicode(uint16_t *p, struct TtyRgb tl, struct TtyRgb tr,
static uint16_t *PickUnicode(uint16_t *p, struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br,
struct TtyRgb tl2, struct TtyRgb tr2,
struct TtyRgb bl2, struct TtyRgb br2) {
#define PICK(A, B, C, D) *p++ = bdist(tl, tr, bl, br, A, B, C, D)
#define PICK(A, B, C, D) *p++ = GetBlockDist(tl, tr, bl, br, A, B, C, D)
PICK(bl2, bl2, bl2, bl2); /* k=0 bg=bl fg=NULL */
PICK(bl2, bl2, bl2, br2); /* ▗ k=4 bg=bl fg=br */
PICK(bl2, bl2, bl2, tl2); /* ▗ k=4 bg=bl fg=tl */
@ -566,11 +567,11 @@ static uint16_t *pickunicode(uint16_t *p, struct TtyRgb tl, struct TtyRgb tr,
return p;
}
static uint16_t *pickcp437(uint16_t *p, struct TtyRgb tl, struct TtyRgb tr,
static uint16_t *PickCp437(uint16_t *p, struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br,
struct TtyRgb tl2, struct TtyRgb tr2,
struct TtyRgb bl2, struct TtyRgb br2) {
#define PICK(A, B, C, D) *p++ = bdist(tl, tr, bl, br, A, B, C, D)
#define PICK(A, B, C, D) *p++ = GetBlockDist(tl, tr, bl, br, A, B, C, D)
PICK(bl2, bl2, bl2, bl2); /* k=0 bg=bl fg=NULL */
PICK(bl2, bl2, br2, br2); /* ▄ k=1 bg=bl fg=br */
PICK(bl2, bl2, tl2, tl2); /* ▄ k=1 bg=bl fg=tl */
@ -603,30 +604,30 @@ static uint16_t *pickcp437(uint16_t *p, struct TtyRgb tl, struct TtyRgb tr,
return p;
}
static struct Pick pickblock_unicode_ansi(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
struct TtyRgb tl2 = getquant(tl);
struct TtyRgb tr2 = getquant(tr);
struct TtyRgb bl2 = getquant(bl);
struct TtyRgb br2 = getquant(br);
static struct Pick PickBlockUnicodeAnsi(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
struct TtyRgb tl2 = GetQuant(tl);
struct TtyRgb tr2 = GetQuant(tr);
struct TtyRgb bl2 = GetQuant(bl);
struct TtyRgb br2 = GetQuant(br);
unsigned i, p1, p2;
uint16_t picks1[96] aligned(32);
uint16_t picks2[32] aligned(32);
memset(picks1, 0x79, sizeof(picks1));
memset(picks2, 0x79, sizeof(picks2));
pickunicode(picks1, tl, tr, bl, br, tl2, tr2, bl2, br2);
mixblock(picks2, tl, tr, bl, br, tl2, tr2, bl2, br2);
PickUnicode(picks1, tl, tr, bl, br, tl2, tr2, bl2, br2);
MixBlock(picks2, tl, tr, bl, br, tl2, tr2, bl2, br2);
p1 = windex(picks1, 96);
p2 = windex(picks2, 32);
return picks1[p1] <= picks2[p2] ? kPicksUnicode[p1] : kPicksMixBlock[p2];
}
static struct Pick pickblock_unicode_true(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
static struct Pick PickBlockUnicodeTrue(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
unsigned i;
uint16_t picks[96] aligned(32);
memset(picks, 0x79, sizeof(picks));
pickunicode(picks, tl, tr, bl, br, tl, tr, bl, br);
PickUnicode(picks, tl, tr, bl, br, tl, tr, bl, br);
i = windex(picks, 96);
if (i >= 88) {
unsigned j;
@ -640,39 +641,39 @@ static struct Pick pickblock_unicode_true(struct TtyRgb tl, struct TtyRgb tr,
return kPicksUnicode[i];
}
static struct Pick pickblock_cp437_ansi(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
struct TtyRgb tl2 = getquant(tl);
struct TtyRgb tr2 = getquant(tr);
struct TtyRgb bl2 = getquant(bl);
struct TtyRgb br2 = getquant(br);
static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
struct TtyRgb tl2 = GetQuant(tl);
struct TtyRgb tr2 = GetQuant(tr);
struct TtyRgb bl2 = GetQuant(bl);
struct TtyRgb br2 = GetQuant(br);
unsigned i, p1, p2;
uint16_t picks1[32] aligned(32);
uint16_t picks2[32] aligned(32);
memset(picks1, 0x79, sizeof(picks1));
memset(picks2, 0x79, sizeof(picks2));
pickcp437(picks1, tl, tr, bl, br, tl2, tr2, bl2, br2);
mixblock(picks2, tl, tr, bl, br, tl2, tr2, bl2, br2);
PickCp437(picks1, tl, tr, bl, br, tl2, tr2, bl2, br2);
MixBlock(picks2, tl, tr, bl, br, tl2, tr2, bl2, br2);
p1 = windex(picks1, 32);
p2 = windex(picks2, 32);
return picks1[p1] <= picks2[p2] ? kPicksCp437[p1] : kPicksMixBlock[p2];
}
static struct Pick pickblock_cp437_true(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
static struct Pick PickBlockCp437True(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
unsigned i;
uint16_t picks[32] aligned(32);
memset(picks, 0x79, sizeof(picks));
pickcp437(picks, tl, tr, bl, br, tl, tr, bl, br);
PickCp437(picks, tl, tr, bl, br, tl, tr, bl, br);
return kPicksCp437[windex(picks, 32)];
}
static char *copyglyph(char *v, struct Glyph glyph) {
static char *CopyGlyph(char *v, struct Glyph glyph) {
memcpy(v, &glyph, 4);
return v + glyph.len;
}
static char *copyblock(char *v, const struct TtyRgb chunk[hasatleast 4],
static char *CopyBlock(char *v, const struct TtyRgb chunk[hasatleast 4],
struct Pick pick, struct TtyRgb *bg, struct TtyRgb *fg,
struct Glyph *glyph) {
unsigned i;
@ -721,16 +722,16 @@ static char *copyblock(char *v, const struct TtyRgb chunk[hasatleast 4],
} else if (!ttyeq(*bg, chunk[pick.bg])) {
v = setbg(v, (*bg = chunk[pick.bg]));
}
return copyglyph(v, (*glyph = kGlyphs[i][pick.k]));
return CopyGlyph(v, (*glyph = kGlyphs[i][pick.k]));
}
static bool chunkeq(struct TtyRgb c[hasatleast 4],
static bool ChunkEq(struct TtyRgb c[hasatleast 4],
struct TtyRgb c2[hasatleast 4]) {
return ttyeq(c[TL], c[TR]) && ttyeq(c[BL], c[BR]) && ttyeq(c2[TL], c2[TR]) &&
ttyeq(c2[BL], c2[BR]);
}
static struct TtyRgb *copychunk(struct TtyRgb chunk[hasatleast 4],
static struct TtyRgb *CopyChunk(struct TtyRgb chunk[hasatleast 4],
const struct TtyRgb *c, size_t n) {
chunk[TL] = c[0 + 0];
chunk[TR] = c[0 + 1];
@ -739,7 +740,7 @@ static struct TtyRgb *copychunk(struct TtyRgb chunk[hasatleast 4],
return chunk;
}
static noinline char *copyrun(char *v, size_t n,
static noinline char *CopyRun(char *v, size_t n,
struct TtyRgb lastchunk[hasatleast 4],
const struct TtyRgb **c, size_t *x,
struct TtyRgb *bg, struct TtyRgb *fg,
@ -752,12 +753,12 @@ static noinline char *copyrun(char *v, size_t n,
*glyph = kGlyphs[0][0];
}
do {
v = copyglyph(v, *glyph);
v = CopyGlyph(v, *glyph);
*x += 2;
*c += 2;
if (*x >= n) break;
copychunk(chunk, *c, n);
} while (chunkeq(chunk, lastchunk));
CopyChunk(chunk, *c, n);
} while (ChunkEq(chunk, lastchunk));
*x -= 2;
*c -= 2;
return v;
@ -776,21 +777,21 @@ char *ttyraster(char *v, const struct TtyRgb *c, size_t yn, size_t n,
for (y = 0; y < yn; y += 2, c += n) {
if (y) *v++ = '\r', *v++ = '\n';
for (x = 0; x < n; x += 2, c += 2) {
copychunk(chun, c, n);
CopyChunk(chun, c, n);
if (ttyquant()->alg == kTtyQuantTrue) {
if (ttyquant()->blocks == kTtyBlocksCp437) {
p = pickblock_cp437_true(chun[TL], chun[TR], chun[BL], chun[BR]);
p = PickBlockCp437True(chun[TL], chun[TR], chun[BL], chun[BR]);
} else {
p = pickblock_unicode_true(chun[TL], chun[TR], chun[BL], chun[BR]);
p = PickBlockUnicodeTrue(chun[TL], chun[TR], chun[BL], chun[BR]);
}
} else {
if (ttyquant()->blocks == kTtyBlocksCp437) {
p = pickblock_cp437_ansi(chun[TL], chun[TR], chun[BL], chun[BR]);
p = PickBlockCp437Ansi(chun[TL], chun[TR], chun[BL], chun[BR]);
} else {
p = pickblock_unicode_ansi(chun[TL], chun[TR], chun[BL], chun[BR]);
p = PickBlockUnicodeAnsi(chun[TL], chun[TR], chun[BL], chun[BR]);
}
}
v = copyblock(v, chun, p, &bg, &fg, &glyph);
v = CopyBlock(v, chun, p, &bg, &fg, &glyph);
memcpy(lastchunk, chun, sizeof(chun));
}
}

1
dsp/tty/ttyraw.c

@ -158,6 +158,5 @@ textstartup int ttyraw(enum TtyRawFlags flags) {
} else {
rc = ttyraw_disable();
}
cancolor();
return rc;
}

1
examples/ctrlc.c

@ -9,6 +9,7 @@
#endif
#include "libc/calls/calls.h"
#include "libc/log/check.h"
#include "libc/log/color.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"

1
examples/findprime.c

@ -13,6 +13,7 @@
#include "libc/conv/conv.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/color.h"
#include "libc/log/log.h"
#include "libc/math.h"
#include "libc/runtime/runtime.h"

2
examples/subprocess.c

@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
*
* 1. gc() automates calling free() on return.
* 2. xasprintf("foo %s", "bar") is our version of "foo %s" % ("bar")
* 3. Demonstrates correct escaping for bourne shell cf. xaescapeshq()
* 3. Demonstrates correct escaping for bourne shell
*/
if (!fileexists(kProgram)) {
system(gc(xasprintf("%s '%s'", "make -j4",

118
examples/unbourne.c

@ -620,12 +620,12 @@
#define octtobin(c) ((c) - '0')
#define scopy(s1, s2) ((void)strcpy(s2, s1))
/* #define TRACE(param) */
#define TRACE(param) \
do { \
printf("TRACE: "); \
printf param; \
} while (0)
#define TRACE(param)
/* #define TRACE(param) \ */
/* do { \ */
/* printf("TRACE: "); \ */
/* printf param; \ */
/* } while (0) */
#define TRACEV(param)
#define digit_val(c) ((c) - '0')
@ -634,8 +634,6 @@
#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
#define is_special(c) ((is_type + SYNBASE)[(signed char)(c)] & (ISSPECL | ISDIGIT))
/* #define likely(x) __builtin_expect(!!(x), 1) */
/* #define unlikely(x) __builtin_expect(!!(x), 0) */
#define uninitialized_var(x) x = x /* suppress uninitialized warning w/o code */
@ -643,9 +641,7 @@
* Shell variables.
*/
#define vifs varinit[0]
#define vmail (&vifs)[1]
#define vmpath (&vmail)[1]
#define vpath (&vmpath)[1]
#define vpath (&vifs)[1]
#define vps1 (&vpath)[1]
#define vps2 (&vps1)[1]
#define vps4 (&vps2)[1]
@ -1497,46 +1493,48 @@ enum token {
enum token_types { UNOP, BINOP, BUNOP, BBINOP, PAREN };
static struct t_op const ops[] = {{"-r", FILRD, UNOP},
{"-w", FILWR, UNOP},
{"-x", FILEX, UNOP},
{"-e", FILEXIST, UNOP},
{"-f", FILREG, UNOP},
{"-d", FILDIR, UNOP},
{"-c", FILCDEV, UNOP},
{"-b", FILBDEV, UNOP},
{"-p", FILFIFO, UNOP},
{"-u", FILSUID, UNOP},
{"-g", FILSGID, UNOP},
{"-k", FILSTCK, UNOP},
{"-s", FILGZ, UNOP},
{"-t", FILTT, UNOP},
{"-z", STREZ, UNOP},
{"-n", STRNZ, UNOP},
{"-h", FILSYM, UNOP}, /* for backwards compat */
{"-O", FILUID, UNOP},
{"-G", FILGID, UNOP},
{"-L", FILSYM, UNOP},
{"-S", FILSOCK, UNOP},
{"=", STREQ, BINOP},
{"!=", STRNE, BINOP},
{"<", STRLT, BINOP},
{">", STRGT, BINOP},
{"-eq", INTEQ, BINOP},
{"-ne", INTNE, BINOP},
{"-ge", INTGE, BINOP},
{"-gt", INTGT, BINOP},
{"-le", INTLE, BINOP},
{"-lt", INTLT, BINOP},
{"-nt", FILNT, BINOP},
{"-ot", FILOT, BINOP},
{"-ef", FILEQ, BINOP},
{"!", UNOT, BUNOP},
{"-a", BAND, BBINOP},
{"-o", BOR, BBINOP},
{"(", LPAREN, PAREN},
{")", RPAREN, PAREN},
{0, 0, 0}};
static struct t_op const ops[] = {
{"-r", FILRD, UNOP},
{"-w", FILWR, UNOP},
{"-x", FILEX, UNOP},
{"-e", FILEXIST, UNOP},
{"-f", FILREG, UNOP},
{"-d", FILDIR, UNOP},
{"-c", FILCDEV, UNOP},
{"-b", FILBDEV, UNOP},
{"-p", FILFIFO, UNOP},
{"-u", FILSUID, UNOP},
{"-g", FILSGID, UNOP},
{"-k", FILSTCK, UNOP},
{"-s", FILGZ, UNOP},
{"-t", FILTT, UNOP},
{"-z", STREZ, UNOP},
{"-n", STRNZ, UNOP},
{"-h", FILSYM, UNOP}, /* for backwards compat */
{"-O", FILUID, UNOP},
{"-G", FILGID, UNOP},
{"-L", FILSYM, UNOP},
{"-S", FILSOCK, UNOP},
{"=", STREQ, BINOP},
{"!=", STRNE, BINOP},
{"<", STRLT, BINOP},
{">", STRGT, BINOP},
{"-eq", INTEQ, BINOP},
{"-ne", INTNE, BINOP},
{"-ge", INTGE, BINOP},
{"-gt", INTGT, BINOP},
{"-le", INTLE, BINOP},
{"-lt", INTLT, BINOP},
{"-nt", FILNT, BINOP},
{"-ot", FILOT, BINOP},
{"-ef", FILEQ, BINOP},
{"!", UNOT, BUNOP},
{"-a", BAND, BBINOP},
{"-o", BOR, BBINOP},
{"(", LPAREN, PAREN},
{")", RPAREN, PAREN},
{0, 0, 0},
};
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § the unbourne shell » text
@ -3644,7 +3642,7 @@ static int evalcommand(union node *cmd, int flags) {
}
/* Now locate the command. */
if (cmdentry.cmdtype != CMDBUILTIN || !(cmdentry.u.cmd->flags & BUILTIN_REGULAR)) {
path = unlikely(path != NULL) ? path : pathval();
path = unlikely(path != NULL) ? path : pathval(); /* wut */
find_command(argv[0], &cmdentry, cmd_flag | DO_ERR, path);
}
jp = NULL;
@ -4213,21 +4211,21 @@ static void hashcd(void) {
* Called with interrupts off.
*/
static void changepath(const char *newval) {
const char *new;
int idx;
int bltin;
new = newval;
const char *neu;
neu = newval;
idx = 0;
bltin = -1;
for (;;) {
if (*new == '%' && prefix(new + 1, "builtin")) {
if (*neu == '%' && prefix(neu + 1, "builtin")) {
bltin = idx;
break;
}
new = strchr(new, ':');
if (!new) break;
neu = strchr(neu, ':');
if (!neu) break;
idx++;
new ++;
neu++;
}
builtinloc = bltin;
clearcmdentry();
@ -9603,6 +9601,9 @@ static char *conv_escape(char *str, int *conv_ch) {
case 'f':
value = '\f';
break; /* form-feed */
case 'e':
value = '\e';
break; /* escape */
case 'n':
value = '\n';
break; /* newline */
@ -10787,6 +10788,7 @@ static int exitcmd(int argc, char **argv) {
*/
int main(int argc, char **argv) {
showcrashreports();
unsetenv("PS1");
char *shinit;
volatile int state;
struct jmploc jmploc;

10
libc/calls/calls.h

@ -111,7 +111,7 @@ int fchmod(int, uint32_t) nothrow;
int fchmodat(int, const char *, uint32_t, uint32_t);
int fchown(int, uint32_t, uint32_t);
int fchownat(int, const char *, uint32_t, uint32_t, uint32_t);
int fcntl();
int fcntl(int, int, ...);
int fdatasync(int);
int filecmp(const char *, const char *);
int flock(int, int);
@ -189,7 +189,7 @@ int uname(struct utsname *);
int unlink(const char *);
int unlink_s(const char **);
int unlinkat(int, const char *, int);
int vfork(void);
int vfork(void) returnstwice;
int wait(int *);
int wait3(int *, int, struct rusage *);
int wait4(int, int *, int, struct rusage *);
@ -242,7 +242,7 @@ int vdprintf(int, const char *, va_list) paramsnonnull();
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
void _init_onntconsoleevent(void);
void _init_onwincrash(void);
void _init_wincrash(void);
#define __SIGACTION(FN, SIG, ...) \
({ \
@ -260,14 +260,14 @@ void _init_onwincrash(void);
case SIGSEGV: \
case SIGABRT: \
case SIGFPE: \
YOINK(_init_onwincrash); \
YOINK(_init_wincrash); \
break; \
default: \
break; \
} \
} else { \
YOINK(_init_onntconsoleevent); \
YOINK(_init_onwincrash); \
YOINK(_init_wincrash); \
} \
} \
(FN)(SIG, __VA_ARGS__); \

13
libc/calls/fcntl-nt.c

@ -24,16 +24,17 @@
#include "libc/sysv/errfuns.h"
textwindows int fcntl$nt(int fd, int cmd, unsigned arg) {
uint32_t flags;
if (!isfdkind(fd, kFdFile)) return ebadf();
switch (cmd) {
case F_GETFD:
return GetHandleInformation(g_fds.p[fd].handle, &arg) ? (arg ^ FD_CLOEXEC)
: -1;
if (!GetHandleInformation(g_fds.p[fd].handle, &flags)) return -1;
arg = (flags & FD_CLOEXEC) ^ FD_CLOEXEC;
return arg;
case F_SETFD:
return SetHandleInformation(g_fds.p[fd].handle, FD_CLOEXEC,
arg ^ FD_CLOEXEC)
? 0
: -1;
arg ^= FD_CLOEXEC;
if (!SetHandleInformation(g_fds.p[fd].handle, FD_CLOEXEC, arg)) return -1;
return 0;
default:
return 0; /* TODO(jart): Implement me. */
}

7
libc/calls/fcntl.c

@ -31,7 +31,12 @@
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
*/
int fcntl(int fd, int cmd, int arg) {
int fcntl(int fd, int cmd, ...) {
va_list va;
unsigned arg;
va_start(va, cmd);
arg = va_arg(va, unsigned);
va_end(va);
if (!IsWindows()) {
return fcntl$sysv(fd, cmd, arg);
} else {

40
libc/calls/fixntmagicpath.ncabi.c

@ -1,40 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/calls/ntmagicpaths.h"
#include "libc/nexgen32e/tinystrcmp.h"
#include "libc/sysv/consts/o.h"
textwindows const char *(fixntmagicpath)(const char *path, unsigned flags) {
const struct NtMagicPaths *mp = &kNtMagicPaths;
asm("" : "+r"(mp));
if (path[0] != '/') return path;
if (tinystrcmp(path, mp->devtty) == 0) {
if ((flags & O_ACCMODE) == O_RDONLY) {
return mp->conin;
} else if ((flags & O_ACCMODE) == O_WRONLY) {
return mp->conout;
}
}
if (tinystrcmp(path, mp->devnull) == 0) return mp->nul;
if (tinystrcmp(path, mp->devstdin) == 0) return mp->conin;
if (tinystrcmp(path, mp->devstdout) == 0) return mp->conout;
return path;
}

16
libc/calls/internal.h

@ -261,15 +261,11 @@ void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden;
struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden;
bool32 ntsetprivilege(i64, const char16_t *, u32) hidden;
bool32 onntconsoleevent$nt(u32) hidden;
void onntalarm(void *, uint32_t, uint32_t) hidden;
void __winalarm(void *, uint32_t, uint32_t) hidden;
int ntaccesscheck(const char16_t *, u32) paramsnonnull() hidden;
i64 ntreturn(u32);
i64 winerr(void) nocallback privileged;
const char *__fixntmagicpath(const char *, unsigned) paramsnonnull() hidden;
int __mkntpath(const char *, unsigned, char16_t[hasatleast PATH_MAX - 16])
paramsnonnull() hidden;
#define mkntpath(PATH, PATH16) mkntpath2(PATH, -1u, PATH16)
#define mkntpath2(PATH, FLAGS, PATH16) \
({ \
@ -281,16 +277,6 @@ int __mkntpath(const char *, unsigned, char16_t[hasatleast PATH_MAX - 16])
Count; \
})
#define fixntmagicpath(PATH, FLAGS) \
({ \
const char *Path2; \
asm("call\tfixntmagicpath" \
: "=a"(Path2) \
: "D"(PATH), "S"(FLAGS), "m"((PATH)[0]) \
: "cc"); \
Path2; \
})
#undef sigset
#undef i32
#undef i64

32
libc/calls/mkntpath.ncabi.c

@ -17,15 +17,31 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/pushpop.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/hefty/ntspawn.h"
#include "libc/calls/internal.h"
#include "libc/conv/conv.h"
#include "libc/calls/ntmagicpaths.h"
#include "libc/nexgen32e/tinystrcmp.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
textwindows static const char *FixNtMagicPath(const char *path,
unsigned flags) {
const struct NtMagicPaths *mp = &kNtMagicPaths;
asm("" : "+r"(mp));
if (path[0] != '/') return path;
if (tinystrcmp(path, mp->devtty) == 0) {
if ((flags & O_ACCMODE) == O_RDONLY) {
return mp->conin;
} else if ((flags & O_ACCMODE) == O_WRONLY) {
return mp->conout;
}
}
if (tinystrcmp(path, mp->devnull) == 0) return mp->nul;
if (tinystrcmp(path, mp->devstdin) == 0) return mp->conin;
if (tinystrcmp(path, mp->devstdout) == 0) return mp->conout;
return path;
}
/**
* Copies path for Windows NT.
*
@ -33,13 +49,13 @@
* forward-slashes with backslashes; and (3) remapping several
* well-known paths (e.g. /dev/null NUL) for convenience.
*
* @param flags is used by open()
* @param path16 is shortened so caller can prefix, e.g. \\.\pipe\, and
* due to a plethora of special-cases throughout the Win32 API
* @param flags is used by open(), see fixntmagicpath2()
* @return short count excluding NUL on success, or -1 w/ errno
* @error ENAMETOOLONG
*/
forcealignargpointer textwindows int(mkntpath)(
forcealignargpointer textwindows int mkntpath(
const char *path, unsigned flags,
char16_t path16[hasatleast PATH_MAX - 16]) {
/*
@ -52,7 +68,7 @@ forcealignargpointer textwindows int(mkntpath)(
int rc;
wint_t wc;
size_t i, j;
path = fixntmagicpath(path, flags);
path = FixNtMagicPath(path, flags);
i = 0;
j = 0;
for (;;) {

2
libc/calls/setitimer-nt.c

@ -55,7 +55,7 @@ static struct ItimerNt {
static uint32_t ItimerWorker(void *arg) {
do {
if (!WaitForSingleObject(g_itimernt.ith, -1)) {
onntalarm(NULL, 0, 0);
__winalarm(NULL, 0, 0);
}
} while (g_itimernt.ith && g_itimernt.tid == GetCurrentThreadId());
return 0;

2
libc/calls/thunks/onntconsoleevent.S

@ -23,5 +23,5 @@
onntconsoleevent$nt:
ezlea onntconsoleevent,ax
jmp nt2sysv
jmp __nt2sysv
.endfn onntconsoleevent$nt,globl,hidden

8
libc/calls/thunks/onwincrash.S

@ -21,7 +21,7 @@
.text.windows
.source __FILE__
onwincrash$nt:
ezlea onwincrash,ax
jmp nt2sysv
.endfn onwincrash$nt,globl
__wincrash$nt:
ezlea __wincrash,ax
jmp __nt2sysv
.endfn __wincrash$nt,globl

8
libc/calls/thunks/onntalarm.S → libc/calls/thunks/winalarm.S

@ -21,7 +21,7 @@
.text.windows
.source __FILE__
onntalarm$nt:
ezlea onntalarm,ax
jmp nt2sysv
.endfn onntalarm$nt,globl,hidden
__winalarm$nt:
ezlea __winalarm,ax
jmp __nt2sysv
.endfn __winalarm$nt,globl,hidden

4
libc/calls/onntalarm.c → libc/calls/winalarm.c

@ -22,8 +22,8 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/sig.h"
void onntalarm(void *lpArgToCompletionRoutine, uint32_t dwTimerLowValue,
uint32_t dwTimerHighValue) {
void __winalarm(void *lpArgToCompletionRoutine, uint32_t dwTimerLowValue,
uint32_t dwTimerHighValue) {
siginfo_t info;
memset(&info, 0, sizeof(info));
info.si_signo = SIGALRM;

2
libc/calls/onwincrash.c → libc/calls/wincrash.c

@ -27,7 +27,7 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/sig.h"
textwindows unsigned onwincrash(struct NtExceptionPointers *ep) {
textwindows unsigned __wincrash(struct NtExceptionPointers *ep) {
int sig;
struct Goodies {
ucontext_t ctx;

6
libc/calls/onwincrash_init.S → libc/calls/wincrash_init.S

@ -20,8 +20,8 @@
#include "libc/macros.h"
.source __FILE__
.init.start 300,_init_onwincrash
.init.start 300,_init_wincrash
pushpop 1,%rcx
ezlea onwincrash$nt,dx
ezlea __wincrash$nt,dx
ntcall __imp_AddVectoredExceptionHandler
.init.end 300,_init_onwincrash,globl,hidden
.init.end 300,_init_wincrash,globl,hidden

5
libc/crt/crt.S

@ -54,9 +54,8 @@ _start: test %rdi,%rdi
mov %rdi,%rcx # auxv
mov %ebx,%edi
call _executive
9: .endfn _start,weak,hidden
ud2
9: ud2
.endfn _start,weak,hidden
/ Macintosh userspace program entrypoint.
/

2
libc/dns/getaddrinfo.c

@ -35,7 +35,7 @@
/**
* Resolves address for internet name.
*
* @param node is either an ip string or a utf-8 hostname
* @param name is either an ip string or a utf-8 hostname
* @param service is the port number as a string
* @param hints may be passed to specialize behavior (optional)
* @param res receives a pointer that must be freed with freeaddrinfo(),

262
libc/errno.h

@ -6,137 +6,137 @@
* @see libc/sysv/consts.sh for numbers
*/
#define EPERM EPERM /* operation not permitted */
#define ENOENT ENOENT /* no such file or directory */
#define ESRCH ESRCH /* no such process */
#define EINTR EINTR /* interrupted system call */
#define EIO EIO /* input/output error */
#define ENXIO ENXIO /* no such device or address */
#define E2BIG E2BIG /* argument list too long */
#define ENOEXEC ENOEXEC /* exec format error */
#define EBADF EBADF /* bad file descriptor */
#define ECHILD ECHILD /* no child processes */
#define EAGAIN EAGAIN /* resource temporarily unavailable */
#define ENOMEM ENOMEM /* not enough space */
#define EACCES EACCES /* permission denied */
#define EFAULT EFAULT /* bad address */
#define ENOTBLK ENOTBLK /* block device required */
#define EBUSY EBUSY /* device or resource busy */
#define EEXIST EEXIST /* file exists */
#define EXDEV EXDEV /* improper link */
#define ENODEV ENODEV /* no such device */
#define ENOTDIR ENOTDIR /* not a directory */
#define EISDIR EISDIR /* is a directory */
#define EINVAL EINVAL /* invalid argument */
#define ENFILE ENFILE /* too many open files in system */
#define EMFILE EMFILE /* too many open files */
#define ENOTTY ENOTTY /* inappropriate I/O control op */
#define ETXTBSY ETXTBSY /* text file busy */
#define EFBIG EFBIG /* file too large */
#define ENOSPC ENOSPC /* no space left on device */
#define ESPIPE ESPIPE /* invalid seek */
#define EROFS EROFS /* read-only filesystem */
#define EMLINK EMLINK /* too many links */
#define EPIPE EPIPE /* broken pipe */
#define EDOM EDOM /* argument out of function domain */
#define ERANGE ERANGE /* result too large */
#define EDEADLK EDEADLK /* resource deadlock avoided */
#define ENAMETOOLONG ENAMETOOLONG /* filename too long */
#define ENOLCK ENOLCK /* no locks available */
#define ENOSYS ENOSYS /* system call not implemented */
#define ENOTEMPTY ENOTEMPTY /* directory not empty */
#define ELOOP ELOOP /* too many levels of symbolic links */
#define ENOMSG ENOMSG /* no message of the desired type */
#define EIDRM EIDRM /* identifier removed */
#define ECHRNG ECHRNG /* channel number out of range */
#define EL2NSYNC EL2NSYNC /* level 2 not synchronized */
#define EL3HLT EL3HLT /* level 3 halted */
#define EL3RST EL3RST /* level 3 halted */
#define ELNRNG ELNRNG /* link number out of range */
#define EUNATCH EUNATCH /* protocol driver not attached */
#define ENOCSI ENOCSI /* no csi structure available */
#define EL2HLT EL2HLT /* level 2 halted */
#define EBADE EBADE /* invalid exchange */
#define EBADR EBADR /* invalid request descriptor */
#define EXFULL EXFULL /* exchange full */
#define ENOANO ENOANO /* no anode */
#define EBADRQC EBADRQC /* invalid request code */
#define EBADSLT EBADSLT /* invalid slot */
#define ENOSTR ENOSTR /* no string */
#define ENODATA ENODATA /* no data */
#define ETIME ETIME /* timer expired */
#define ENOSR ENOSR /* out of streams resources */
#define ENONET ENONET /* no network */
#define ENOPKG ENOPKG /* package not installed */
#define EREMOTE EREMOTE /* object is remote */
#define ENOLINK ENOLINK /* link severed */
#define EADV EADV /* todo */
#define ESRMNT ESRMNT /* todo */
#define ECOMM ECOMM /* communication error on send */
#define EPROTO EPROTO /* protocol error */
#define EMULTIHOP EMULTIHOP /* multihop attempted */
#define EDOTDOT EDOTDOT /* todo */
#define EBADMSG EBADMSG /* bad message */
#define EOVERFLOW EOVERFLOW /* value too large for type */
#define ENOTUNIQ ENOTUNIQ /* name not unique on network */
#define EBADFD EBADFD /* fd in bad *state* (cf. EBADF) */
#define EREMCHG EREMCHG /* remote address changed */
#define ELIBACC ELIBACC /* cannot access dso */
#define ELIBBAD ELIBBAD /* corrupted shared library */
#define ELIBSCN ELIBSCN /* a.out section corrupted */
#define ELIBMAX ELIBMAX /* too many shared libraries */
#define ELIBEXEC ELIBEXEC /* cannot exec a dso directly */
#define EILSEQ EILSEQ /* invalid wide character */
#define ERESTART ERESTART /* please restart syscall */
#define ESTRPIPE ESTRPIPE /* streams pipe error */
#define EUSERS EUSERS /* too many users */
#define ENOTSOCK ENOTSOCK /* not a socket */
#define EDESTADDRREQ EDESTADDRREQ /* dest address needed */
#define EMSGSIZE EMSGSIZE /* message too long */
#define EPROTOTYPE EPROTOTYPE /* protocol wrong for socket */
#define ENOPROTOOPT ENOPROTOOPT /* protocol not available */
#define EPROTONOSUPPORT EPROTONOSUPPORT /* protocol not supported */
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT /* socket type not supported */
#define EOPNOTSUPP EOPNOTSUPP /* operation not supported on socket */
#define EPFNOSUPPORT EPFNOSUPPORT /* protocol family not supported */
#define EAFNOSUPPORT EAFNOSUPPORT /* address family not supported */
#define EADDRINUSE EADDRINUSE /* address already in use */
#define EADDRNOTAVAIL EADDRNOTAVAIL /* address not available */
#define ENETDOWN ENETDOWN /* network is down */
#define ENETUNREACH ENETUNREACH /* network unreachable */
#define ENETRESET ENETRESET /* connection aborted by network */
#define ECONNABORTED ECONNABORTED /* connection aborted */
#define ECONNRESET ECONNRESET /* connection reset */
#define ENOBUFS ENOBUFS /* no buffer space available */
#define EISCONN EISCONN /* socket is connected */
#define ENOTCONN ENOTCONN /* the socket is not connected */
#define ESHUTDOWN ESHUTDOWN /* no send after endpoint shutdown */
#define ETOOMANYREFS ETOOMANYREFS /* too many refs */
#define ETIMEDOUT ETIMEDOUT /* connection timed out */
#define ECONNREFUSED ECONNREFUSED /* connection refused */
#define EHOSTDOWN EHOSTDOWN /* host is down */
#define EHOSTUNREACH EHOSTUNREACH /* host is unreachable */
#define EALREADY EALREADY /* connection already in progress */
#define EINPROGRESS EINPROGRESS /* operation in progress */
#define ESTALE ESTALE /* stale file handle */
#define EUCLEAN EUCLEAN /* structure needs cleaning */
#define ENOTNAM ENOTNAM /* todo */
#define ENAVAIL ENAVAIL /* todo */
#define EISNAM EISNAM /* is a named type file */
#define EREMOTEIO EREMOTEIO /* remote i/o error */
#define EDQUOT EDQUOT /* disk quota exceeded */
#define ENOMEDIUM ENOMEDIUM /* no medium found */
#define EMEDIUMTYPE EMEDIUMTYPE /* wrong medium type */
#define ECANCELED ECANCELED /* operation canceled */
#define ENOKEY ENOKEY /* required key not available */
#define EKEYEXPIRED EKEYEXPIRED /* key has expired */
#define EKEYREVOKED EKEYREVOKED /* key has been revoked */
#define EKEYREJECTED EKEYREJECTED /* key was rejected by service */
#define EOWNERDEAD EOWNERDEAD /* owner died */
#define ENOTRECOVERABLE ENOTRECOVERABLE /* state not recoverable */
#define ERFKILL ERFKILL /* can't op b/c RF-kill */
#define EHWPOISON EHWPOISON /* mempage has h/w error */
#define EWOULDBLOCK EAGAIN /* poll fd and try again */
#define EPERM EPERM // operation not permitted
#define ENOENT ENOENT // no such file or directory
#define ESRCH ESRCH // no such process
#define EINTR EINTR // interrupted system call
#define EIO EIO // input/output error
#define ENXIO ENXIO // no such device or address
#define E2BIG E2BIG // argument list too long
#define ENOEXEC ENOEXEC // exec format error
#define EBADF EBADF // bad file descriptor
#define ECHILD ECHILD // no child processes
#define EAGAIN EAGAIN // resource temporarily unavailable
#define ENOMEM ENOMEM // not enough space
#define EACCES EACCES // permission denied
#define EFAULT EFAULT // bad address
#define ENOTBLK ENOTBLK // block device required
#define EBUSY EBUSY // device or resource busy
#define EEXIST EEXIST // file exists
#define EXDEV EXDEV // improper link
#define ENODEV ENODEV // no such device
#define ENOTDIR ENOTDIR // not a directory
#define EISDIR EISDIR // is a directory
#define EINVAL EINVAL // invalid argument
#define ENFILE ENFILE // too many open files in system
#define EMFILE EMFILE // too many open files
#define ENOTTY ENOTTY // inappropriate I/O control op
#define ETXTBSY ETXTBSY // text file busy
#define EFBIG EFBIG // file too large
#define ENOSPC ENOSPC // no space left on device
#define ESPIPE ESPIPE // invalid seek
#define EROFS EROFS // read-only filesystem
#define EMLINK EMLINK // too many links
#define EPIPE EPIPE // broken pipe
#define EDOM EDOM // argument out of function domain
#define ERANGE ERANGE // result too large
#define EDEADLK EDEADLK // resource deadlock avoided
#define ENAMETOOLONG ENAMETOOLONG // filename too long
#define ENOLCK ENOLCK // no locks available
#define ENOSYS ENOSYS // system call not implemented
#define ENOTEMPTY ENOTEMPTY // directory not empty
#define ELOOP ELOOP // too many levels of symbolic links
#define ENOMSG ENOMSG // no message of the desired type
#define EIDRM EIDRM // identifier removed
#define ECHRNG ECHRNG // channel number out of range
#define EL2NSYNC EL2NSYNC // level 2 not synchronized
#define EL3HLT EL3HLT // level 3 halted
#define EL3RST EL3RST // level 3 halted
#define ELNRNG ELNRNG // link number out of range
#define EUNATCH EUNATCH // protocol driver not attached
#define ENOCSI ENOCSI // no csi structure available
#define EL2HLT EL2HLT // level 2 halted
#define EBADE EBADE // invalid exchange
#define EBADR EBADR // invalid request descriptor
#define EXFULL EXFULL // exchange full
#define ENOANO ENOANO // no anode
#define EBADRQC EBADRQC // invalid request code
#define EBADSLT EBADSLT // invalid slot
#define ENOSTR ENOSTR // no string
#define ENODATA ENODATA // no data
#define ETIME ETIME // timer expired
#define ENOSR ENOSR // out of streams resources
#define ENONET ENONET // no network
#define ENOPKG ENOPKG // package not installed
#define EREMOTE EREMOTE // object is remote
#define ENOLINK ENOLINK // link severed
#define EADV EADV // todo
#define ESRMNT ESRMNT // todo
#define ECOMM ECOMM // communication error on send
#define EPROTO EPROTO // protocol error
#define EMULTIHOP EMULTIHOP // multihop attempted
#define EDOTDOT EDOTDOT // todo
#define EBADMSG EBADMSG // bad message
#define EOVERFLOW EOVERFLOW // value too large for type
#define ENOTUNIQ ENOTUNIQ // name not unique on network
#define EBADFD EBADFD // fd in bad *state* (cf. EBADF)
#define EREMCHG EREMCHG // remote address changed
#define ELIBACC ELIBACC // cannot access dso
#define ELIBBAD ELIBBAD // corrupted shared library
#define ELIBSCN ELIBSCN // a.out section corrupted
#define ELIBMAX ELIBMAX // too many shared libraries
#define ELIBEXEC ELIBEXEC // cannot exec a dso directly
#define EILSEQ EILSEQ // invalid wide character
#define ERESTART ERESTART // please restart syscall
#define ESTRPIPE ESTRPIPE // streams pipe error
#define EUSERS EUSERS // too many users
#define ENOTSOCK ENOTSOCK // not a socket
#define EDESTADDRREQ EDESTADDRREQ // dest address needed
#define EMSGSIZE EMSGSIZE // message too long
#define EPROTOTYPE EPROTOTYPE // protocol wrong for socket
#define ENOPROTOOPT ENOPROTOOPT // protocol not available
#define EPROTONOSUPPORT EPROTONOSUPPORT // protocol not supported
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT // socket type not supported
#define EOPNOTSUPP EOPNOTSUPP // operation not supported on socket
#define EPFNOSUPPORT EPFNOSUPPORT // protocol family not supported
#define EAFNOSUPPORT EAFNOSUPPORT // address family not supported
#define EADDRINUSE EADDRINUSE // address already in use
#define EADDRNOTAVAIL EADDRNOTAVAIL // address not available
#define ENETDOWN ENETDOWN // network is down
#define ENETUNREACH ENETUNREACH // network unreachable
#define ENETRESET ENETRESET // connection aborted by network
#define ECONNABORTED ECONNABORTED // connection aborted
#define ECONNRESET ECONNRESET // connection reset
#define ENOBUFS ENOBUFS // no buffer space available
#define EISCONN EISCONN // socket is connected
#define ENOTCONN ENOTCONN // the socket is not connected
#define ESHUTDOWN ESHUTDOWN // no send after endpoint shutdown
#define ETOOMANYREFS ETOOMANYREFS // too many refs
#define ETIMEDOUT ETIMEDOUT // connection timed out
#define ECONNREFUSED ECONNREFUSED // connection refused
#define EHOSTDOWN EHOSTDOWN // host is down
#define EHOSTUNREACH EHOSTUNREACH // host is unreachable
#define EALREADY EALREADY // connection already in progress
#define EINPROGRESS EINPROGRESS // operation in progress
#define ESTALE ESTALE // stale file handle
#define EUCLEAN EUCLEAN // structure needs cleaning
#define ENOTNAM ENOTNAM // todo
#define ENAVAIL ENAVAIL // todo
#define EISNAM EISNAM // is a named type file
#define EREMOTEIO EREMOTEIO // remote i/o error
#define EDQUOT EDQUOT // disk quota exceeded
#define ENOMEDIUM ENOMEDIUM // no medium found
#define EMEDIUMTYPE EMEDIUMTYPE // wrong medium type
#define ECANCELED ECANCELED // operation canceled
#define ENOKEY ENOKEY // required key not available
#define EKEYEXPIRED EKEYEXPIRED // key has expired
#define EKEYREVOKED EKEYREVOKED // key has been revoked
#define EKEYREJECTED EKEYREJECTED // key was rejected by service
#define EOWNERDEAD EOWNERDEAD // owner died
#define ENOTRECOVERABLE ENOTRECOVERABLE // state not recoverable
#define ERFKILL ERFKILL // can't op b/c RF-kill
#define EHWPOISON EHWPOISON // mempage has h/w error
#define EWOULDBLOCK EAGAIN // poll fd and try again
#define ENOTSUP ENOTSUP
#if !(__ASSEMBLER__ + __LINKER__ + 0)

47
libc/escape/aescape.c

@ -1,47 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/escape/escape.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
/**
* Internal function aspecting escaping ops with allocating behavior.
* @see aescapesh(), aescapec()
*/
int aescape(char **escaped, size_t size, const char *unescaped, unsigned length,
int impl(char *escaped, unsigned size, const char *unescaped,
unsigned length)) {
int wrote;
char *p2;
if ((p2 = realloc(*escaped, size)) != NULL) {
*escaped = p2;
if ((wrote = impl(*escaped, size, unescaped, length)) != -1) {
if ((unsigned)wrote <= size - 1) {
return wrote;
} else {
assert(__builtin_return_address(0) != aescape);
return aescape(escaped, wrote + 1, unescaped, length, impl);
}
}
}
free_s(escaped);
return -1;
}

64
libc/escape/cunescape.c

@ -1,64 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/escape/escape.h"
#include "libc/macros.h"
#include "libc/str/str.h"
// TODO(jart): implement me
/**
* Decodes backslash escape sequences in-place.
*
* We support the C standard definitions, and the gotchas that entails:
*
<