Commit Graph

248 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen da85d20500
mescc: Mes C Library: Prepare for M2-Planet: strcpy.
* lib/string/strcpy.c: Rewrite C-constructs not supported by M2-Planet.
2019-11-17 12:25:30 +01:00
Jan Nieuwenhuizen c3a7033886
mescc: Mes C Library: Prepare for M2-Planet: strcmp.
* lib/string/strcmp.c: Rewrite C-constructs not supported by M2-Planet.
2019-11-17 12:25:30 +01:00
Jan Nieuwenhuizen 2b8bb1abd2
mescc: Mes C Library: Prepare for M2-Planet: __assert_fail.
Rewrite C-constructs not supported by M2-Planet, such as

    foo ? bar : baz;       -> if (foo) bar; else baz;
    static char foo[1024]  -> __func_buf = malloc (1024); ... char *foo = __func_buf;
    *foo                   -> foo[0]
    foo++                  -> foo = foo + 1   TODO: pointer arithmetic
    foo += 1;              -> foo = foo + 1
    for (int foo = ;       -> int foo; for (foo=
    if (foo)               -> if (foo != 0)
    if (!foo)              -> if (foo == 0)
    ;                      -> 0;

* lib/mes/__assert_fail.c: Rewrite C-constructs not supported by
M2-Planet.
2019-11-17 12:25:30 +01:00
Jan Nieuwenhuizen 6f5d815e7d
mescc: Mes C Library: Add assert_msg.
* lib/mes/assert_msg.c: New file.
2019-11-17 12:25:30 +01:00
Danny Milosavljevic 35e84ff8aa
Add missing #include.
* lib/stdlib/mbstowcs.c: Add missing #include.
2019-11-17 12:24:47 +01:00
Danny Milosavljevic 58f9e644f4
Fix dtoab.
* lib/mes/dtoab.c (dtoab): Fix it.
* lib/tests/mes/90-dtoab.c (main): Fix test.
* build-aux/check-mescc.sh (XFAIL_TESTS: Remove it.
2019-11-17 12:24:47 +01:00
Danny Milosavljevic 0ea76f2f61
Add missing #include.
* lib/tests/mes/90-abtod.c (main): Add missing #include.
2019-11-17 12:24:46 +01:00
Danny Milosavljevic 809aa3f03a
Fix variable argument list traversal for doubles.
* include/stdarg.h (va_align): New macro.
(va_arg8): New macro.
* lib/stdio/vfprintf.c (vfprintf): Use it.
* lib/stdio/vsnprintf.c (vsnprintf): Use it.
2019-11-17 12:24:46 +01:00
Jan Nieuwenhuizen 4d55c843dc
build: Improve --with-system-libc support.
* build-aux/build-lib.sh: Avoid building libc for --with-system-libc.
Make libmes richer.
build-aux/check-mescc.sh: Enable 50-malloc test.
* include/dirstream.h: Use HAVE_DIRSTREAM_H to cater for non-existing
dirstream.h.
* include/grp.h[SYSTEM_LIBC]: Typo.
* include/mes/lib.h (__brk, __call_at_exit)[SYSTEM_LIBC]: Declare.
* include/stdlib.h (comparison_fn_t)[SYSTEM_LIBC]: Declare.
* include/time.h (mktime): Return time_t.
* lib/posix/isatty.c [SYSTEM_LIBC]: Do not (re)declare termios.
* lib/stub/mktime.c (mktime): Return time_t.
* lib/tests/scaffold/41-ternary.c (main): Remove assumption that
locals are initialized.
* lib/tests/scaffold/70-stdarg.c: Cater for SYSTEM_LIBC.
* lib/tests/setjmp/80-setjmp.c: Declare jmp buf.
* lib/*/*.c: Add missing mes/lib.h, errno.h includes.
2019-11-17 12:24:46 +01:00
Jan Nieuwenhuizen 0857d59c24
mescc: Mes C Library: vfprintf, vsnprintf: Pad floats with space.
* lib/stdio/vfprintf.c (vfprintf): Pad floats with space.
* lib/stdio/vsnprintf.c (vsnprintf): Pad floats with space.
* lib/tests/stdio/90-sprintf.c: Test it.
2019-11-17 12:24:46 +01:00
Jan Nieuwenhuizen c7ff4cf2e2
mescc: Mes C Library: vsscanf: Increase count for scanned float.
* lib/stdio/vsscanf.c (vsscanf): Increase count for scanned float.
2019-11-17 12:24:46 +01:00
Jan Nieuwenhuizen 11ef8a5f85
mescc: Mes C Library: Support GNU Tar: Fix getpwnam, getpwuid stubs.
* lib/stub/getpwnam.c (getpwnam): Return pointer to static struct
passwd.
* lib/stub/getpwuid.c (getpwuid): Likewise.
2019-11-17 12:24:46 +01:00
Jan Nieuwenhuizen 082ca6a786
mescc: Mes C Library: Support GNU Tar: Add getgrgid, getgrnam, setgrent stub.
* include/grp.h: New file.
* lib/stub/getgrgid.c: New file.
* lib/stub/getgrnam.c: New file.
* lib/stub/setgrent.c: New file.
* lib/libc+gnu.c: Include them.
2019-11-17 12:24:45 +01:00
Jan Nieuwenhuizen ce5b77062f
mescc: Mes C Library: Support GNU Awk: Add wchar_t.
* include/sys/types.h (wchar_t): New typedef.
2019-11-17 12:24:45 +01:00
Jan Nieuwenhuizen cea8ff7b13
mescc: Mes C Library: Support GNU Awk: Add getpgid, getpgrp stubs.
* include/unistd.h (getpgid, getpgrp): Declare.
* lib/stub/getpgid.c: New file.
* lib/stub/getpgrp.c: New file.
* lib/libc+gnu.c: Include them.
2019-11-17 12:24:45 +01:00
Jan Nieuwenhuizen 9c734094ba
mescc: Mes C Library: Support GNU Tar: Add mktime stub, fix localtime stub.
* include/time.h (mktime): Declare.
* lib/stub/mktime.c: New stub.
* lib/libc+gnu.c: Include it.
* lib/stub/localtime.c (localtime): Return pointer to static struct
tm.  Avoids segfaults.
2019-11-17 12:24:45 +01:00
Jan Nieuwenhuizen 6e59b834ef
mescc: Mes C Library: Support GNU Tar: Add creat, mknod.
* include/linux/x86_64/syscall.h (SYS_mknod): New macro.
* include/linux/x86/syscall.h (SYS_mknod): New macro.
* lib/linux/mknod.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add it.
* include/sys/stat.h (mknod): Declare it.
* include/fcntl.h (creat): New macro.
2019-11-17 12:24:45 +01:00
Jan Nieuwenhuizen f7bad50ac8
mescc: Mes C Library: Support GNU Awk: Implement atof.
* lib/stdlib/atoi.c: Update.
* lib/stdlib/atof.c: Rename from stub/atof.c; Implement.
* lib/libc+gnu.c: Update include.
* lib/libg.c: Update include.
2019-11-17 12:24:44 +01:00
Jan Nieuwenhuizen bea67d7683
mescc: Mes C Library: Support GNU Awk: Add dtoab, %f in vfprintf, vsnprintf.
* include/libmes.h (dtoab): Declare.
* lib/mes/ntoab.c (ntoab): Update.
* lib/mes/dtoab.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/tests/mes/90-dtoab.c: Test it.
* lib/tests/stdio/90-sprintf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it, against...
* lib/tests/mes/90-dtoab.stdout: ...baseline.
* lib/stdio/vfprintf.c (vfprintf): Support %f, even more naive support
for %e, %E, %g, %G.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
2019-11-17 12:24:44 +01:00
Jan Nieuwenhuizen d5a542215a
mescc: Mes C Library: Support GNU Awk: Add abtod, implementing strtod.
* include/libmes.h (abtod): Declare.
* lib/mes/abtod.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/mes/abtol.c: Update.
* lib/stdlib/strtod.c: Use it to implement; move from stub/strtod.
* lib/tests/mes/90-abtod.c: Test it.
* lib/tests/mes/90-abtod.stdout: Baseline.
* build-aux/check-mescc.sh (tests): Run it.
2019-11-17 12:24:44 +01:00
Jan Nieuwenhuizen c63067c0c9
mescc: Mes C Library: Support GNU Awk: vsscanf: Support %f.
* lib/stdio/vsscanf.c (vsscanf): Support %f.
2019-11-17 12:24:44 +01:00
Jan Nieuwenhuizen 37e82074f0
mescc: Mes C Library: Support GNU Awk: Do not flush std files.
* lib/stdio/fflush.c (fflush): Do not flush std files.
2019-11-17 12:24:44 +01:00
Jan Nieuwenhuizen efd813d404
mescc: Mes C Library: Support GNU Awk: Add isgraph.
* lib/ctype/isgraph.c: New file.
* lib/libc+gnu.c: Include it.
* include/ctype.h: Add missing prototypes.
2019-11-17 12:24:44 +01:00
Jan Nieuwenhuizen e040e55f8e
mescc: Mes C Library: Support GNU Tar: Add readlink, readlink.
* lib/linux/gnu.c (readlink, symlink): New function.
* include/unistd.h (readlink, symlink): Declare.
* include/linux/x86/syscall.h (SYS_readlink, SYS_symlink): New macro.
* include/linux/x86_64/syscall.h (SYS_symlink, SYS_readlink): New
macro.
2019-11-17 12:24:43 +01:00
Jan Nieuwenhuizen bcb8a071ee
mescc: Mes C Library: Support GNU Tar: Add execlp.
* lib/posix/execl.c (vexec): New function.
(execl): Use it.
* lib/posix/execlp.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES): Add it.
* lib/libc+gnu.c: Include it.
* include/unistd.h (execlp): Declare.
* lib/tests/posix/90-execlp.c: New file.
* lib/tests/posix/90-execlp.stdout: New file.
* build-aux/check-mescc.sh: Test it.
2019-11-17 12:24:43 +01:00
Jan Nieuwenhuizen d12afa089e
mescc: Mes C Library: Fix compile warnings.
* include/stdlib.h (abort): Add prototype.
2019-11-17 12:24:43 +01:00
Jan Nieuwenhuizen 8f223bf978
mescc: Mes C Library: Add missing stubs.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add fscanf, rewind stubs.
* lib/stdio/freeopen.c: Remove.
2019-11-17 12:24:43 +01:00
Jan Nieuwenhuizen 3bed314d94
getopt: Remove old FSF address, thanks Vagrant.
* lib/posix/getopt.c: Remove old FSF address.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic 15a39f0efe
Add missing #include.
* lib/tests/scaffold/55-char-array.c: Add missing #include.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic e2dfaef89e
Add missing #include.
* lib/tests/io/90-stat.c: Add missing #include.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic 5f82a697b3
Add missing #include.
* lib/posix/getcwd.c: Add missing #include.
2019-09-09 16:04:15 +02:00
Jan Nieuwenhuizen 2db5ec2f55
signal: Use SA_RESTORER on x86-64.
* lib/linux/signal.c (signal)[x86_64]: Avoid segfault by setting
SA_RESTORER flag.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic 23d857c834
signal: Add comment on why we don't use the restorer.
* lib/linux/signal.c: Add comment on why we don't use the restorer.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic 4a183fa1cf
signal: Remove SA_SIGINFO.
* lib/linux/signal.c (signal): Remove SA_SIGINFO.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic 3e6306a5ce
signal: Don't use custom restorer.
* lib/linux/signal.c (signal): Don't use custom restorer.
2019-09-09 16:04:14 +02:00
Danny Milosavljevic 02fdead244
signal: Use SA_SIGINFO (like glibc).
* lib/linux/signal.c (_restorer): Rename to...
(_restorer_for_siginfo): ...this.
(signal): Use it.  Use SA_SIGINFO.
2019-09-09 16:04:14 +02:00
Danny Milosavljevic e8bbe21499
signal: Make sure that the signal mask is actually unsigned long.
* lib/linux/signal.c (signal): Make sure that the signal mask is actually
unsigned long.
2019-09-09 16:04:14 +02:00
Danny Milosavljevic 5754e379af
Delete "__sigmask".
Follow-up to 6d95b89759d3c598fc84194429ae8c57249daa1a

* lib/linux/signal.c (__sigmask): Delete definition.
2019-09-09 16:04:14 +02:00
Danny Milosavljevic 3f1ba73fc7
Fix "struct sigaction" structure for rt_sigaction.
* include/signal.h (sigset_t): Increase size.
* lib/linux/signal.c (signal): Use new sigset_t.
2019-09-09 16:04:14 +02:00
Danny Milosavljevic c7d050c0cd
tests: Fail early on nonexistent file.
* lib/tests/io/90-stat.c (main): Fail early on nonexistent file.
2019-09-09 16:04:13 +02:00
Danny Milosavljevic 5a2a00f4e8
open: Check flags, and use _open2 if applicable.
* lib/linux/open.c (open): Check flags; use _open2.
2019-09-09 16:04:13 +02:00
Danny Milosavljevic 3943155a64
ldiv: Make rem < 0 if a < 0.
* lib/mes/div.c (ldiv): Make rem < 0 if a < 0.
2019-09-09 16:04:13 +02:00
Danny Milosavljevic 21bd2c1e90
ldiv: Handle a == LONG_MIN.
* lib/mes/div.c (ldiv): Handle a == LONG_MIN.
2019-09-09 16:04:13 +02:00
Jan Nieuwenhuizen 49aff4ec1c
ntoab: Use __mesabi_uldiv only for arm.
* lib/mes/ntoab.c (ntoab)[__MESC__ && __arm__]: Use __mesabi_uldiv.
* build-aux/check-mescc.sh (XFAIL_TESTS): 70-printf-simple.c and
70-printf.c now pass for x86_64 mescc.
2019-09-09 16:04:13 +02:00
Danny Milosavljevic 08774a9c74
Fix ntoab.
Follow-up to b5b19304b59fefbed923b146ec8c8d495556fa76.

* lib/mes/ntoab.c (ntoab): Fix non-MESC case.
2019-07-01 20:04:26 +02:00
Danny Milosavljevic b0466331a7
signal: Define "_restorer" everywhere except on i386.
* lib/linux/signal.c: Define "_restorer" everywhere except on i386.
2019-06-18 19:26:45 +02:00
Danny Milosavljevic 9b0efad295
ntoab: Use __mesabi_uldiv only on __MESC__.
* lib/mes/ntoab.c (ntoab): Use __mesabi_uldiv only on __MESC__.
2019-06-14 17:45:32 +02:00
Danny Milosavljevic a63b0bae44
ntoab: Include "assert.h".
* lib/mes/ntoab.c: #include "assert.h".
2019-06-14 01:27:15 +02:00
Danny Milosavljevic c35124ab54
mescc: Mes C Library: Use __mesabi_uldiv.
* lib/mes/ntoab.c (ntoab): Use __mesabi_uldiv.
2019-06-14 01:02:40 +02:00
Danny Milosavljevic cc870b4adc
mescc: Mes C Library: Add integer division algorithm.
* lib/mes/div.c: New file.
2019-06-14 00:57:43 +02:00