Commit Graph

180 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen 69a71425f1
mescc: Mes C Library: Support gcc-4.6.4. WIP 2019-01-16 13:21:36 +01:00
Jan Nieuwenhuizen c410e4ad18
WIP typo in stage0 copyright headers. 2019-01-16 13:19:53 +01:00
Jan Nieuwenhuizen 984fb447ae
build: Remove POSIX define, use WITH_GLIBC only. WIP 2019-01-12 22:08:34 +01:00
Jan Nieuwenhuizen 7291308484
mescc: Mes C Library: Fix compile warnings.
* include/libmes.h (dtoab, itoa, ltoa, ntoab, ultoa, utoa): Return
char* (WAS: char const*).
* lib/*/*c: Update, add missing includes.
2019-01-12 22:08:22 +01:00
Jan Nieuwenhuizen 4a78958133
mescc: Mes C Library: vsscanf: Increase count for scanned float.
* lib/stdio/vsscanf.c (vsscanf): Increase count for scanned float.
2019-01-12 22:08:22 +01:00
Jan Nieuwenhuizen 212cce5692
mescc: Mes C Library: Fix isatty.
* lib/posix/isatty.c (isatty): Test ioctl == 0.
* mes/module/mes/boot-0.scm.in: Update: no tty?: read from stdin.
2019-01-12 22:08:22 +01:00
Jan Nieuwenhuizen f9ceaac9b7
test: 50-getenv: Test PATH, allow to fail.
* lib/tests/posix/50-getenv.c (main): Test PATH.
* build-aux/check-mescc.sh (broken): Add 50-getenv.
2019-01-12 22:08:22 +01:00
Jan Nieuwenhuizen 64ccd5c9c2
mescc: Mes C Library: Use __ as global internal prefix.
* include/libmes-mini.h (g_stdin, g_stdout, g_stderr): Rename to
__stdin, __stdout, __stderr.  Update users.
2019-01-12 22:08:21 +01:00
Jan Nieuwenhuizen 338010d498
mescc: Mes C Library: Support GNU Sed: Fix ungetc.
* include/sys/resource.h (OPEN_MAX, RLIMIT_NOFILE): New macro.
* lib/libc.c: Add memset.c include.
* lib/libc+tcc.c: Remove memset.c include.
* lib/linux/tcc.c (close):
* lib/mes/fdgetc.c (__ungetc_buf): New global.
(_ungetc_pos, _ungetc_fd, _ungetc_buf): Remove.  Update users.
2019-01-12 22:08:19 +01:00
Jan Nieuwenhuizen ab6028e5bd
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-01-12 22:01:43 +01:00
Jan Nieuwenhuizen 2fd4ce4e62
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-01-12 22:01:43 +01:00
Jan Nieuwenhuizen 640ec0a9ea
mescc: Mes C Library: Support GNU Awk: Add wchar_t.
* include/sys/types.h (wchar_t): New typedef.
2019-01-12 22:01:42 +01:00
Jan Nieuwenhuizen f308c3f6bc
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-01-12 22:01:42 +01:00
Jan Nieuwenhuizen b1a96c2fc6
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-01-12 22:01:42 +01:00
Jan Nieuwenhuizen 2b3fbf5ffa
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/gnu.c (mknod): New function, use it.
* include/sys/stat.h: Declare it.
* include/fcntl.h (creat): New macro.
2019-01-12 22:01:42 +01:00
Jan Nieuwenhuizen 73fb77c191
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-01-12 22:01:42 +01:00
Jan Nieuwenhuizen a2fbf3de11
mescc: Mes C Library: Bugfix for tcc-compiled exit assembly.
* lib/linux/x86-mes-gcc/mini.c (_exit): Add clobbered registers %eax,
%ebx.  Fixes always exit 1.
2019-01-12 22:01:42 +01:00
Jan Nieuwenhuizen 09a7722c21
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.
* 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-01-12 22:01:41 +01:00
Jan Nieuwenhuizen 0ce74918c1
mescc: Mes C Library: Support GNU Awk: Add abtod, implementing sttrod.
* include/libmes.h (abtod): Declare.
* lib/mes/abtod.c: New file.
* 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-01-12 22:01:41 +01:00
Jan Nieuwenhuizen 85c108076a
mescc: Mes C Library: Support GNU Awk: vsscanf: Support %f.
* lib/stdio/vsscanf.c (vsscanf): Support %f.
2019-01-12 22:01:41 +01:00
Jan Nieuwenhuizen 288a25893c
mescc: Mes C Library: Support GNU Awk: Do not flush std files.
* lib/stdio/fflush.c (fflush): Do not flush std files.
2019-01-12 22:01:41 +01:00
Jan Nieuwenhuizen 539dcb2680
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-01-12 22:01:41 +01:00
Jan Nieuwenhuizen ab9d47a72f
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-01-12 22:01:41 +01:00
Jan Nieuwenhuizen 73bb01dc13
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.
* 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-01-12 22:01:41 +01:00
Jan Nieuwenhuizen 9dbbe334b0
mescc: Mes C Library: Initialize streams in crt1.
* lib/linux/x86-mes-gcc/crt1.c: Initialize streams.
* lib/linux/x86-mes/crt1.c: Likewise.
* lib/linux/x86_64-mes-gcc/crt1.c: Likewise.
* lib/linux/x86_64-mes/crt1.c: Likewise.
* src/mes.c (main): Remove initialization of streams.
2019-01-12 22:01:40 +01:00
Jan Nieuwenhuizen 8b21ff5925
mescc: Mes C Library: Populate with function tests from scaffold.
* .gitignore: Update.
* build-aux/bootstrap.sh.in: Update.
* build-aux/build-mes.sh: Update.
* build-aux/check-mescc.sh: Update.
* lib/tests/assert/50-assert.c: Move from scaffold/tests/50-assert.c.
* lib/tests/dirent/90-readdir.c: Move from scaffold/tests/99-readdir.c.
* lib/tests/dirent/readdir.dir: Move from scaffold/tests/readdir.dir.
* lib/tests/io/90-stat.c: Move from scaffold/tests/92-stat.c.
* lib/tests/mes/30-oputs.c: Move from scaffold/tests/31-oputs.c.
* lib/tests/mes/50-itoa.c: Move from scaffold/tests/51-itoa.c.
* lib/tests/posix/90-unsetenv.c: Move from scaffold/tests/94-unsetenv.c.
* lib/tests/setjmp/80-setjmp.c: Move from scaffold/tests/80-setjmp.c.
* lib/tests/signal/90-signal.c: Move from scaffold/tests/95-signal.c.
* lib/tests/stdio/70-printf-hello.c: Move from scaffold/tests/70-printf-hello.c.
* lib/tests/stdio/70-printf-simple.c: Move from scaffold/tests/70-printf-simple.c.
* lib/tests/stdio/70-printf.c: Move from scaffold/tests/70-printf.c.
* lib/tests/stdio/80-sscanf.c: Move from scaffold/tests/87-sscanf.c.
* lib/tests/stdio/90-fopen-append.c: Move from scaffold/tests/98-fopen.c.
* lib/tests/stdio/90-fopen.c: Move from scaffold/tests/97-fopen.c.
* lib/tests/stdio/90-fread-fwrite.c: Move from scaffold/tests/93-fread-fwrite.c.
* lib/tests/stdio/90-fseek.c: Move from scaffold/tests/91-fseek.c.
* lib/tests/stdlib/50-getenv.c: Move from lib/tests/stdlib/getenv.c.
* lib/tests/stdlib/50-malloc.c: Move from lib/tests/stdlib/malloc.c.
* lib/tests/stdlib/70-strtoull.c: Move from scaffold/tests/7j-strtoull.c.
* lib/tests/stdlib/80-qsort-dupes.c: Move from scaffold/tests/81-qsort-dupes.c.
* lib/tests/stdlib/80-qsort.c: Move from scaffold/tests/81-qsort.c.
* lib/tests/stdlib/90-strtol.c: Move from scaffold/tests/96-strto.c.
* lib/tests/string/30-strlen.c: Move from scaffold/tests/30-strlen.c.
* lib/tests/string/50-strcmp.c: Move from scaffold/tests/51-strcmp.c.
* lib/tests/string/50-strcpy.c: Move from scaffold/tests/53-strcpy.c.
* lib/tests/string/50-strncmp.c: Move from scaffold/tests/51-strncmp.c.
* lib/tests/string/70-strchr.c: Move from scaffold/tests/70-strchr.c.
* lib/tests/string/80-strncpy.c: Move from scaffold/tests/86-strncpy.c.
* lib/tests/string/80-strrchr.c: Move from scaffold/tests/88-strrchr.c.
* lib/tests/string/90-snprintf.c: Move from scaffold/tests/9a-snprintf.c.
* lib/tests/string/90-strpbrk.c: Move from scaffold/tests/90-strpbrk.c.
* lib/tests/string/90-strspn.c: Move from scaffold/tests/90-strspn.c.
2019-01-12 22:01:40 +01:00
Jan Nieuwenhuizen d3c9fcf57a
mescc: Mes C Library: Start test suite.
TODO: move strict libc tests from scaffold/test/* here.

* lib/tests/stdlib/getenv.c: New file.
* lib/tests/stdlib/malloc.c: Move from scaffold.
* build-aux/bootstrap.sh.in: Built them.
* build-aux/build-mes.sh: Likewise.
2019-01-12 22:01:40 +01:00
Jan Nieuwenhuizen 9ab3d3cc59
mescc: Mes C Library: Fix brk return type compare.
* lib/stdlib/malloc.c (malloc): Fix brk return type compare.
2019-01-12 22:01:39 +01:00
Jan Nieuwenhuizen 6947d7505d
core: Resurrect POSIX build. Thanks, gio!
* lib/libmes.c[POSIX]: Define and initialize g_stdin, g_stdout and
g_stderr that were moved to crt1 for non-POSIX builds.
* src/mes.c[POSIX]: Remove struct-initialisation exceptions.
2019-01-12 22:01:39 +01:00
Jan Nieuwenhuizen 47d9996079
mescc: Support Bash: Add getppid.
* lib/linux/gnu.c (getppid): New function.
* include/linux/x86/syscall.h (SYS_getppid): New macro.
* include/linux/x86_64/syscall.h (SYS_getppid): New macro.
2018-12-14 18:48:03 +01:00
Jan Nieuwenhuizen 7f6ca031f9
mescc: Support bash: Add sigdelset stub.
* lib/stub/sigdelset.c (sigdelset): New stub.
* lib/libc+gnu.c: Include it.
2018-12-14 18:46:44 +01:00
Jan Nieuwenhuizen 5f14a46422
mescc: getcwd: Support getcwd (0, 0) GNU extension.
* lib/linux/libc.c (_getcwd): Rename from getcwd.
(_getcwd): New function.  Support getcwd (0, 0) GNU extension.
2018-12-07 20:18:01 +01:00
Jan Nieuwenhuizen 149f2a3e51
core: String as array of bytes.
* src/strings.c: New file.
* src/mes.c: Use it.  Update users.
2018-11-11 16:25:36 +01:00
Jan Nieuwenhuizen 2e97dc1250
mescc: Move mecmp to libc.
* lib/libc.c: Include mecmp.c.
* lib/libc+tcc.c: Remove mecmp.c include.
2018-11-25 16:09:31 +01:00
Jan Nieuwenhuizen 3e87e9de3c
mescc: Move memchr to libc.
* lib/libc.c: Include memchr.c.
2018-11-16 00:01:18 +01:00
Jan Nieuwenhuizen 7d2e0f1215
core: Support redirection of stderr.
* include/libmes-mini.h (g_stderr): New global.
* lib/mes/eputc.c (eputc): Use it.
* lib/mes/eputs.c (eputs): Likewise.
* lib/mes/oputc.c (oputc): Likewise.
* lib/mes/oputs.c (oputs): Likewise.
* src/lib.c (display_error_, write_error_): Likewise.
* src/posix.c (write_byte): Likewise.
* src/mes.c (mes_builtins): Likewise.
(main): Iniitalize g_stderr.
* src/posix.c (current_error_port, set_current_error_port): New
function.
* mes/module/mes/boot-0.scm.in (current-output-port,
current-error-port): Remove.
2018-11-11 10:04:03 +01:00
Jan Nieuwenhuizen 82df50eae9
mescc: unlink: Move to libc.
* lib/linux/libc.c (unlink): New function.
* lib/linux/tcc.c (unlink): Remove.
2018-11-11 11:00:42 +01:00
Jan Nieuwenhuizen e660665dfd
mescc: dup, dup2: Move to libc.
* lib/linux/libc.c (dup, dup2): New function.
* lib/linux/gnu.c (dup, dup2): Remove.
2018-11-11 10:13:01 +01:00
Jan Nieuwenhuizen 6e2f941573
mescc: getcwd: Move to libc.
* lib/linux/libc.c (getcwd): New function.
* lib/linux/tcc.c (getcwd): Remove.
2018-11-11 10:12:19 +01:00
Jan Nieuwenhuizen 68441476e0
mescc: Support GNU make with POSIX.
* include/linux/x86/syscall.h (SYS_sigprocmask): New macro.
* include/linux/x86_64/syscall.h (SYS_rt_sigprocmask): New macro.
* include/signal.h (SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK): New macro.
(sigprocmask): Declare.
* lib/linux/gnu.c (sigprocmask): New function.
2018-11-10 08:32:42 +01:00
Jan Nieuwenhuizen 9ecc11ee52
mescc: Support GNU Bash.
* include/errno.h (EACCES, ENOSPC, ESPIPE): New macro.
* include/linux/x86/syscall.h (SYS_setuid, SYS_geteuid, SYS_getegid,
SYS_setgid): New macro.
* include/linux/x86_64/syscall.h: Likewise.
* include/stdint.h (LLONG_MIN, LLONG_MAX, SIZE_MAX): New macro.
* include/sys/stat.h (S_ISUID, S_ISGID, S_IXGRP, S_IXOTH, S_IRGRP,
S_IROTH, S_IWGRP, S_IWOTH, S_IRWXG, S_IRWXO): New macro.
* include/termio.h: New file.
* include/unistd.h (_POSIX_VERSION): New macro.
* lib/linux/gnu.c (geteuid, getegid, setuid, setgid): New function.
* lib/string/memchr.c: New file.
* lib/stub/getpwuid.c: New file.
* lib/stub/rand.c: New file.
* lib/stub/ttyname.c: New file.
* include/string.h (memchr): Declare.
* include/unistd.h (geteuid, getegid, setuid, setgid): Declare.
2018-11-09 21:26:10 +01:00
Jan Nieuwenhuizen 172879360e
mescc: Add missing define.
* lib/x86-mes/x86.M1: Add missing define.
2018-11-09 16:56:54 +01:00
Jan Nieuwenhuizen 3d528b0257
mescc: vsnprintf: Compliant implementation.
* lib/stdio/vsnprintf.c (vsnprintf): New, complient implementation,
replacing vsnprint.
* lib/stdio/vsprintf.c (vsnprint): Forward to vsnprint.
* lib/stdio/snprintf.c (snprintf): Likewise.
* scaffold/tests/9a-snprintf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
2018-10-22 18:33:40 +02:00
Jan Nieuwenhuizen 094bdac0bd
core: Support time functions.
* lib/linux/clock_gettime.c: New file, move from gnu.c.
* lib/linux/gettimeofday.c: New file, move from tcc.c.
* lib/linux/time.c: New file, move from tcc.c.
* lib/linux/libc.c: Include them.
* lib/linux/gnu.c (clock_gettime): Remove.
* lib/linux/tcc.c (time, gettimeofday): Remove.
* include/time.h (CLOCK_PROCESS_CPUTIME_ID): New define.
* src/posix.c (init_time, current_time, gettimeofday_,
seconds_and_nanoseconds_to_long, get_internal_run_time): New function.
* src/mes.c (scm_symbol_internal_time_units_per_second): New symbol.
(main): Call init_time.
2018-10-20 14:18:04 +02:00
Jan Nieuwenhuizen 999642052b
mescc: Mes C Library: oputs: New function.
* lib/mes/oputc.c: New file.
* lib/libmes.c: Include it.
* include/libmes.h: Declare it.
2018-10-15 15:44:47 +02:00
Peter De Wachter d96730b892
mescc: Add missing assembly defines.
* lib/x86-mes/x86.M1: Add missing assembly defines.
* lib/x86_64-mes/x86_64.M1: Likewise.
2018-10-16 20:40:37 +02:00
Peter De Wachter 2726a984a2
mescc: Delete duplicate assembly defines.
* lib/x86-mes/x86.M1: Delete duplicate assembly defines.
* lib/x86_64-mes/x86_64.M1: Likewise.
2018-10-16 20:40:36 +02:00
Jan Nieuwenhuizen 08f04f5596
build: Oops, remove stray lib/linux/x86_64-mes/crt1.
* lib/linux/x86_64-mes/crt1: Remove.
2018-10-11 21:14:14 +02:00
Jan Nieuwenhuizen 5277669b04
mescc: Oops, delete wrong line of assembly.
* lib/x86-mes/x86.M1 (movzbl_%bx,%ebx): Delete wrong line.  Thanks, pdewacht!
2018-10-08 18:14:30 +02:00
Jan Nieuwenhuizen 9a36cf22d0
mescc: Another attempt at divide.
* module/mescc/i386/as.scm (i386:r0/r1): Never be signed.  Use div for unsigned.
(i386:r0%r1): Likewise.
* module/mescc/x86_64/as.scm (x86_64:r0/r1): Likewise.
(x86_64:r0%r1): Likewise.
* lib/x86-mes/x86.M1: Add div.
* lib/x86_64-mes/x86_64.M1: Likewise.
2018-10-07 15:15:45 +02:00