C header files in TypeScript

TypeScript implementations of 20 C standard library functions across 5 modules. Each function is individually importable and tree-shakeable.

ctype math stdio stdlib string

We have 20 C functions so far - help us add more

Got a rainy Sunday afternoon and a taste for a porting puzzle?

We will then review it. If it's useful to the project and in line with our contributing guidelines your work will become part of Locutus and you'll be automatically credited in the authors section accordingly.

Upstream Surface Inventory 20/576 shipped · 128 next 3%

Locutus tracks 32 upstream namespaces for C and sorts them into what is already shipped, what we still want, what we intentionally keep, and what still needs a decision.

3% catalog shipped
Shipped Next Explicit non-goals
ctype 57% string 14% stdlib 8% math 2% stdio 2% assert 0% complex 0% errno 0% fenv 0% float 0% inttypes 0% iso646 0% limits 0% locale 0% setjmp 0% signal 0% stdalign 0% stdarg 0% stdatomic 0% stdbit 0% stdbool 0% stdckdint 0% stddef 0% stdint 0% stdmchar 0% stdnoreturn 0% tgmath 0% threads 0% time 0% uchar 0% wchar 0% wctype 0%
Tracked namespaces 32
Shipped 20/576
Next to port 128
Explicit non-goals 428

In progress

ctype.h

C23 · Catalog source: version-pinned source manifest https://en.cppreference.com/w/c/header/ctype

57% shipped
8/14 shipped 6 next
Shipped (8)

Next

Character classification helpers map cleanly to plain strings and numbers.

  • isblank
  • iscntrl
  • isgraph
  • isprint
  • ispunct
  • isxdigit

string.h

C23 · Catalog source: version-pinned source manifest https://en.cppreference.com/w/c/header/string

50% shipped
5/10 shipped 5 next 27 explicit non-goals
Shipped (5)

Next

Character-class span helpers are useful for string scanning.

  • strcspn
  • strspn

Prefix-bounded string comparison still has a clean plain-value contract.

  • strncmp

Character-class search maps naturally to string scanning.

  • strpbrk

Last-occurrence search maps naturally to string lookup.

  • strrchr
Explicit non-goals (27)
  • memccpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memchr Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memcmp Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memcpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memcpy_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memmove Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memmove_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memset Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memset_explicit Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memset_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strcat_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strcoll Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strcpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strcpy_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strdup Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strerror Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strerrorlen_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strncat Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strncat_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strncpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strncpy_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strndup Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strnlen Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strnlen_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strtok Skip Stateful tokenizer semantics do not fit Locutus' plain-value model.
  • strtok_s Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strxfrm Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.

stdlib.h

C23 · Catalog source: version-pinned source manifest https://en.cppreference.com/w/c/header/stdlib

9% shipped
5/57 shipped 52 next 3 explicit non-goals
Shipped (5)

Next

Scalar conversion and numeric helpers are good portability targets.

  • abort
  • abort_handler_s
  • aligned_alloc
  • at_quick_exit
  • atexit
  • atol
  • atoll
  • bsearch
  • bsearch_s
  • call_once
  • calloc
  • defined
  • div
  • exit
  • free
  • free_aligned_sized
  • free_sized
  • getenv_s
  • ignore_handler_s
  • labs
  • ldiv
  • llabs
  • lldiv
  • malloc
  • mblen
  • mbstowcs
  • mbstowcs_s
  • mbtowc
  • memalignment
  • qsort_s
  • quick_exit
  • rand
  • realloc
  • strfromd
  • strfromd128
  • strfromd32
  • strfromd64
  • strfromf
  • strfroml
  • strtod128
  • strtod32
  • strtod64
  • strtof
  • strtold
  • strtoll
  • strtoul
  • strtoull
  • system
  • wcstombs
  • wcstombs_s
  • wctomb
  • wctomb_s
Explicit non-goals (3)
  • getenv Skip Process environment lookup depends on host state outside Locutus' model.
  • qsort Skip In-place comparator-driven sorting does not map cleanly to plain JS values.
  • srand Skip Global RNG seeding mutates ambient runtime state.

math.h

C23 · Catalog source: version-pinned source manifest https://en.cppreference.com/w/c/header/math

2% shipped
1/63 shipped 62 next
Shipped (1)

Next

Scalar math helpers are strong plain-value portability targets.

  • acos
  • acosh
  • asin
  • asinh
  • atan
  • atan2
  • atanh
  • cbrt
  • ceil
  • copysign
  • cos
  • cosh
  • erf
  • erfc
  • exp
  • exp2
  • expm1
  • fabs
  • fdim
  • floor
  • fma
  • fmax
  • fmin
  • fmod
  • fpclassify
  • hypot
  • ilogb
  • isfinite
  • isgreater
  • isgreaterequal
  • isinf
  • isless
  • islessequal
  • islessgreater
  • isnan
  • isnormal
  • isunordered
  • ldexp
  • lgamma
  • log
  • log10
  • log1p
  • log2
  • logb
  • modf
  • nan
  • nearbyint
  • nextafter
  • pow
  • remainder
  • remquo
  • rint
  • round
  • scalbn
  • signbit
  • sin
  • sinh
  • sqrt
  • tan
  • tanh
  • tgamma
  • trunc

stdio.h

C23 · Catalog source: version-pinned source manifest https://en.cppreference.com/w/c/header/stdio

25% shipped
1/4 shipped 3 next 60 explicit non-goals
Shipped (1)

Next

Sized string formatting still produces a plain string result.

  • snprintf

Variadic string formatting still yields a plain string result.

  • vsnprintf
  • vsprintf
Explicit non-goals (60)
  • clearerr Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fclose Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • feof Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • ferror Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fflush Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fgetc Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fgetpos Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fgets Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fopen Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fopen_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fprintf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fputc Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fputs Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fread Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • freopen Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • freopen_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fscanf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fscanf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fseek Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fsetpos Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • ftell Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fwrite Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • getc Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • getchar Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • gets_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • perror Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • printf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • printf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • putc Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • putchar Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • puts Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • remove Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • rename Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • rewind Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • scanf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • scanf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • setbuf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • setvbuf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • snprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • sprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • sscanf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • sscanf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • tmpfile Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • tmpfile_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • tmpnam Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • tmpnam_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • ungetc Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vfprintf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vfprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vfscanf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vfscanf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vprintf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vscanf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vscanf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vsnprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vsprintf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vsscanf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vsscanf_s Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.

Triaged as out of scope

complex.h C23
0/0 66 skipped
fenv.h C23
0/0 17 skipped
inttypes.h C23
0/0 6 skipped
locale.h C23
0/0 2 skipped
setjmp.h C23
0/0 2 skipped
signal.h C23
0/0 2 skipped
stdarg.h C23
0/0 4 skipped
stdatomic.h C23
0/0 19 skipped
stdbit.h C23
0/0 12 skipped
stdckdint.h C23
0/0 3 skipped
stdmchar.h C23
0/0 50 skipped
threads.h C23
0/0 25 skipped
time.h C23
0/0 18 skipped
uchar.h C23
0/0 6 skipped
wchar.h C23
0/0 88 skipped
wctype.h C23
0/0 18 skipped

Not yet triaged

assert.h C23
0/0
errno.h C23
0/0
float.h C23
0/0
iso646.h C23
0/0
limits.h C23
0/0
stdalign.h C23
0/0
stdbool.h C23
0/0
stddef.h C23
0/0
stdint.h C23
0/0
stdnoreturn.h C23
0/0
tgmath.h C23
0/0