mescc: Support gcc-2.6.3.

* TODO
This commit is contained in:
Jan Nieuwenhuizen 2018-06-02 11:41:06 +02:00
parent f1efaa0e93
commit de964f3e1f
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
70 changed files with 1142 additions and 408 deletions

1
.gitignore vendored
View file

@ -9,6 +9,7 @@
*.gcc *.gcc
*.gcc-o *.gcc-o
*.gcc-out *.gcc-out
*.gcc-stdout
*.go *.go
*.guile *.guile
*.log *.log

View file

@ -3,6 +3,9 @@ GUILE_FLAGS:=--no-auto-compile -L . -L guile -C . -C guile
include .config.make include .config.make
.config.make:
./configure
PHONY_TARGETS:= all all-go check clean clean-go default help install PHONY_TARGETS:= all all-go check clean clean-go default help install
.PHONY: $(PHONY_TARGETS) .PHONY: $(PHONY_TARGETS)

View file

@ -62,12 +62,14 @@ C32FLAGS=${C32FLAGS-"
-nostdlib -nostdlib
"} "}
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt0
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt1 ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt1
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc-mini
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libgetopt ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libgetopt
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+tcc ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+tcc
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+gnu ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+gnu
ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libg
sh build-aux/cc-mes-gcc.sh scaffold/main sh build-aux/cc-mes-gcc.sh scaffold/main
sh build-aux/cc-mes-gcc.sh scaffold/hello sh build-aux/cc-mes-gcc.sh scaffold/hello

View file

@ -55,6 +55,7 @@ $CC\
-c\ -c\
$CPPFLAGS\ $CPPFLAGS\
$CFLAGS\ $CFLAGS\
-D WITH_GLIBC=1\
-D POSIX=1\ -D POSIX=1\
-o "$o".${p}o\ -o "$o".${p}o\
"$c".c "$c".c

View file

@ -145,6 +145,8 @@ broken="$broken
91-fseek 91-fseek
" "
# gcc not supported
CC=
set +e set +e
expect=$(echo $broken | wc -w) expect=$(echo $broken | wc -w)
pass=0 pass=0

View file

@ -34,6 +34,24 @@ shift
set -e set -e
rm -f "$t".gcc-out
if [ -n "$CC" ]; then
sh build-aux/cc.sh "$t"
r=0
[ -f "$t".exit ] && r=$(cat "$t".exit)
set +e
"$t".gcc-out $ARGS > "$t".gcc-stdout
m=$?
cat "$t".gcc-stdout
set -e
[ $m = $r ]
if [ -f "$t".expect ]; then
$DIFF -ub "$t".expect "$t".gcc-stdout;
fi
fi
rm -f "$t".mes-gcc-out rm -f "$t".mes-gcc-out
if [ -n "$CC32" ]; then if [ -n "$CC32" ]; then
sh build-aux/cc-mes-gcc.sh "$t" sh build-aux/cc-mes-gcc.sh "$t"

View file

@ -20,15 +20,15 @@
#ifndef __MES_ALLOCA_H #ifndef __MES_ALLOCA_H
#define __MES_ALLOCA_H 1 #define __MES_ALLOCA_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_ALLOCA_H 1 #undef __MES_ALLOCA_H 1
#include_next <alloca.h> #include_next <alloca.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
void* alloca (size_t); void* alloca (size_t);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_ALLOCA_H #endif // __MES_ALLOCA_H

View file

@ -20,15 +20,15 @@
#ifndef __MES_ASSERT_H #ifndef __MES_ASSERT_H
#define __MES_ASSERT_H 1 #define __MES_ASSERT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_ASSERT_H #undef __MES_ASSERT_H
#include_next <assert.h> #include_next <assert.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define assert(x) ((x) ? (void)0 : assert_fail (#x)) #define assert(x) ((x) ? (void)0 : assert_fail (#x))
void assert_fail (char* s); void assert_fail (char* s);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_ASSERT_H #endif // __MES_ASSERT_H

View file

@ -20,18 +20,18 @@
#ifndef __MES_CTYPE_H #ifndef __MES_CTYPE_H
#define __MES_CTYPE_H 1 #define __MES_CTYPE_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_CTYPE_H #undef __MES_CTYPE_H
#include_next <ctype.h> #include_next <ctype.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <endian.h> #include <endian.h>
int isdigit (int); int isdigit (int);
int isxdigit (int); int isxdigit (int);
int isspace (int); int isspace (int);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_CTYPE_H #endif // __MES_CTYPE_H

View file

@ -20,11 +20,11 @@
#ifndef __MES_DLFCN_H #ifndef __MES_DLFCN_H
#define __MES_DLFCN_H 1 #define __MES_DLFCN_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_DLFCN_H #undef __MES_DLFCN_H
#include_next <dlfcn.h> #include_next <dlfcn.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define RTLD_LAZY 0x00001 #define RTLD_LAZY 0x00001
#define RTLD_NOW 0x00002 #define RTLD_NOW 0x00002
@ -38,7 +38,7 @@
void *dlopen (char const *filename, int flags); void *dlopen (char const *filename, int flags);
int dlclose (void *handle); int dlclose (void *handle);
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_DLFCN_H #endif // __MES_DLFCN_H

View file

@ -20,17 +20,17 @@
#ifndef __MES_ENDIAN_H #ifndef __MES_ENDIAN_H
#define __MES_ENDIAN_H 1 #define __MES_ENDIAN_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_ENDIAN_H #undef __MES_ENDIAN_H
#include_next <endian.h> #include_next <endian.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define __LITTLE_ENDIAN 1234 #define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321 #define __BIG_ENDIAN 4321
#define __BYTE_ORDER __LITTLE_ENDIAN #define __BYTE_ORDER __LITTLE_ENDIAN
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_ENDIAN_H #endif // __MES_ENDIAN_H

View file

@ -20,30 +20,31 @@
#ifndef __MES_ERRNO_H #ifndef __MES_ERRNO_H
#define __MES_ERRNO_H 1 #define __MES_ERRNO_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_ERRNO_H #undef __MES_ERRNO_H
#include_next <errno.h> #include_next <errno.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
int errno; int errno;
#define ENOENT 2 /* No such file or directory */ #define ENOENT 2
#define EIO 5 /* I/O error */ #define EIO 5
#define EBADF 9 /* Bad file number */ #define EBADF 9
#define ENOMEM 12 /* Out of memory */ #define EAGAIN 11
#define EEXIST 17 /* File exists */ #define ENOMEM 12
#define ENOTDIR 20 /* Not a directory */ #define EEXIST 17
#define EISDIR 21 /* Is a directory */ #define ENOTDIR 20
#define EINVAL 22 /* Invalid argument */ #define EISDIR 21
#define EMFILE 24 /* Too many open files */ #define EINVAL 22
#define EPIPE 32 /* Broken pipe */ #define EMFILE 24
#define ERANGE 34 /* Math result not representable */ #define EPIPE 32
#define ERANGE 34
#define ENAMETOOLONG 36 /* File name too long */ #define ENAMETOOLONG 36
#define ENOSYS 38 /* Invalid system call number */ #define ENOSYS 38
#define ELOOP 40 /* Too many symbolic links encountered */ #define ELOOP 40
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_ERRNO_H #endif // __MES_ERRNO_H

View file

@ -20,14 +20,14 @@
#ifndef __MES_FCNTL_H #ifndef __MES_FCNTL_H
#define __MES_FCNTL_H 1 #define __MES_FCNTL_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_FCNTL_H #undef __MES_FCNTL_H
#include_next <fcntl.h> #include_next <fcntl.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define O_RDONLY 0 #define O_RDONLY 0
#define O_WRONLY 1 #define O_WRONLY 1
#define O_RDWR 2 #define O_RDWR 2
@ -42,6 +42,6 @@
#define F_SETFL 4 #define F_SETFL 4
int open (char const *s, int flags, ...); int open (char const *s, int flags, ...);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_FCNTL_H #endif // __MES_FCNTL_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_FEATURES_H #ifndef __MES_FEATURES_H
#define __MES_FEATURES_H 1 #define __MES_FEATURES_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_FEATURES_H #undef __MES_FEATURES_H
#include_next <features.h> #include_next <features.h>
#endif // (__GNUC__ && POSIX) #endif // (WITH_GLIBC)
#endif // __MES_FEATURES_H #endif // __MES_FEATURES_H

View file

@ -20,15 +20,15 @@
#ifndef __MES_FLOAT_H #ifndef __MES_FLOAT_H
#define __MES_FLOAT_H 1 #define __MES_FLOAT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_FLOAT_H #undef __MES_FLOAT_H
#include_next <float.h> #include_next <float.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define MIN_EXP -1021 #define MIN_EXP -1021
#define DBL_MIN_EXP -1021 #define DBL_MIN_EXP -1021
#define LDBL_MIN_EXP -1021 #define LDBL_MIN_EXP -1021
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_FLOAT_H #endif // __MES_FLOAT_H

View file

@ -21,14 +21,14 @@
#ifndef __MES_GETOPT_H #ifndef __MES_GETOPT_H
#define __MES_GETOPT_H 1 #define __MES_GETOPT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_GETOPT_H #undef __MES_GETOPT_H
#include_next <getopt.h> #include_next <getopt.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <endian.h> #include <endian.h>
int isdigit (int); int isdigit (int);
int isxdigit (int); int isxdigit (int);
@ -57,6 +57,6 @@ int getopt_long (int argc, char *const *argv, char const *options,
int getopt_long_only (int argc, char *const *argv, char const *options, int getopt_long_only (int argc, char *const *argv, char const *options,
struct option const *long_options, int *opt_index); struct option const *long_options, int *opt_index);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_GETOPT_H #endif // __MES_GETOPT_H

View file

@ -20,15 +20,15 @@
#ifndef __MES_INTTYPES_H #ifndef __MES_INTTYPES_H
#define __MES_INTTYPES_H 1 #define __MES_INTTYPES_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_INTTYPES_H #undef __MES_INTTYPES_H
#include_next <inttypes.h> #include_next <inttypes.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <stdint.h> #include <stdint.h>
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_INTTYPES_H #endif // __MES_INTTYPES_H

View file

@ -20,15 +20,15 @@
#ifndef __MES_LIBGEN_H #ifndef __MES_LIBGEN_H
#define __MES_LIBGEN_H 1 #define __MES_LIBGEN_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_LIBGEN_H #undef __MES_LIBGEN_H
#include_next <libgen.h> #include_next <libgen.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
char* dirname (char*); char* dirname (char*);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_LIBGEN_H #endif // __MES_LIBGEN_H

View file

@ -21,7 +21,9 @@
#ifndef __MES_LIBMES_H #ifndef __MES_LIBMES_H
#define __MES_LIBMES_H #define __MES_LIBMES_H
char const* itoa (int); char const* number_to_ascii (int number, int base, int signed_p);
char const* itoa (int number);
char const* utoa (unsigned number);
char const* itoab (int x, int base); char const* itoab (int x, int base);
int _atoi (char const**, int base); int _atoi (char const**, int base);
int atoi (char const *s); int atoi (char const *s);

View file

@ -20,14 +20,14 @@
#ifndef __MES_LIMITS_H #ifndef __MES_LIMITS_H
#define __MES_LIMITS_H 1 #define __MES_LIMITS_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_LIMITS_H #undef __MES_LIMITS_H
#include_next <limits.h> #include_next <limits.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define CHAR_BIT 8 #define CHAR_BIT 8
#define UCHAR_MAX 255 #define UCHAR_MAX 255
#define INT_MIN -2147483648 #define INT_MIN -2147483648
@ -36,6 +36,6 @@
#define LONG_MIN -2147483648 #define LONG_MIN -2147483648
#define LONG_MAX 2147483647 #define LONG_MAX 2147483647
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_LIMITS_H #endif // __MES_LIMITS_H

View file

@ -20,15 +20,15 @@
#ifndef __MES_LOCALE_H #ifndef __MES_LOCALE_H
#define __MES_LOCALE_H 1 #define __MES_LOCALE_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_LOCALE_H #undef __MES_LOCALE_H
#include_next <locale.h> #include_next <locale.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
char* dirname (char*); char* dirname (char*);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_LOCALE_H #endif // __MES_LOCALE_H

View file

@ -20,12 +20,12 @@
#ifndef __MES_MATH_H #ifndef __MES_MATH_H
#define __MES_MATH_H 1 #define __MES_MATH_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_MATH_H #undef __MES_MATH_H
#include_next <math.h> #include_next <math.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
double ldexp (double x, int exp); double ldexp (double x, int exp);
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_MATH_H #endif // __MES_MATH_H

View file

@ -20,17 +20,17 @@
#ifndef __MES_MEMORY_H #ifndef __MES_MEMORY_H
#define __MES_MEMORY_H 1 #define __MES_MEMORY_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_MEMORY_H #undef __MES_MEMORY_H
#include_next <memory.h> #include_next <memory.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <string.h> #include <string.h>
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_MEMORY_H #endif // __MES_MEMORY_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_PWD_H #ifndef __MES_PWD_H
#define __MES_PWD_H 1 #define __MES_PWD_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_PWD_H #undef __MES_PWD_H
#include_next <pwd.h> #include_next <pwd.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
struct passwd struct passwd
{ {
@ -36,6 +36,6 @@ struct passwd
char *pw_shell; char *pw_shell;
}; };
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_PWD_H #endif // __MES_PWD_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SETJMP_H #ifndef __MES_SETJMP_H
#define __MES_SETJMP_H 1 #define __MES_SETJMP_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SETJMP_H #undef __MES_SETJMP_H
#include_next <setjmp.h> #include_next <setjmp.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
typedef struct typedef struct
{ {
@ -42,7 +42,7 @@ jmp_buf buf;
void longjmp (jmp_buf env, int val); void longjmp (jmp_buf env, int val);
int setjmp (jmp_buf env); int setjmp (jmp_buf env);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SETJMP_H #endif // __MES_SETJMP_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SIGNAL_H #ifndef __MES_SIGNAL_H
#define __MES_SIGNAL_H 1 #define __MES_SIGNAL_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SIGNAL_H #undef __MES_SIGNAL_H
#include_next <signal.h> #include_next <signal.h>
#else //! (__GNUC__ && POSIX) #else //! WITH_GLIBC
typedef int sigset_t; typedef int sigset_t;
typedef int stack_t; typedef int stack_t;
@ -218,6 +218,6 @@ typedef struct ucontext
int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact); int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact);
int sigemptyset (sigset_t *set); int sigemptyset (sigset_t *set);
#endif //! (__GNUC__ && POSIX) #endif //! WITH_GLIBC
#endif // __MES_SIGNAL_H #endif // __MES_SIGNAL_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_STDARG_H #ifndef __MES_STDARG_H
#define __MES_STDARG_H 1 #define __MES_STDARG_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_STDARG_H #undef __MES_STDARG_H
#include_next <stdarg.h> #include_next <stdarg.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef __MES_SIZE_T #ifndef __MES_SIZE_T
#define __MES_SIZE_T #define __MES_SIZE_T
@ -48,6 +48,6 @@ int vsprintf (char *str, char const *format, va_list ap);
int vsnprintf (char *str, size_t size, char const *format, va_list ap); int vsnprintf (char *str, size_t size, char const *format, va_list ap);
int vsscanf (char const *s, char const *template, va_list ap); int vsscanf (char const *s, char const *template, va_list ap);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDARG_H #endif // __MES_STDARG_H

View file

@ -20,17 +20,17 @@
#ifndef __MES_STDBOOL_H #ifndef __MES_STDBOOL_H
#define __MES_STDBOOL_H 1 #define __MES_STDBOOL_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_STDBOOL_H #undef __MES_STDBOOL_H
#include_next <stdbool.h> #include_next <stdbool.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
typedef int bool; typedef int bool;
#define false 0 #define false 0
#define true 1 #define true 1
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDBOOL_H #endif // __MES_STDBOOL_H

View file

@ -20,10 +20,11 @@
#ifndef __MES_STDDEF_H #ifndef __MES_STDDEF_H
#define __MES_STDDEF_H 1 #define __MES_STDDEF_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_STDDEF_H #undef __MES_STDDEF_H
#include_next <stddef.h> #include_next <stddef.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
@ -35,6 +36,6 @@
#endif // !__MESC__ #endif // !__MESC__
#endif // offsetof #endif // offsetof
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDDEF_H #endif // __MES_STDDEF_H

View file

@ -20,14 +20,14 @@
#ifndef __MES_STDINT_H #ifndef __MES_STDINT_H
#define __MES_STDINT_H 1 #define __MES_STDINT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_STDINT_H #undef __MES_STDINT_H
#include_next <stdint.h> #include_next <stdint.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#undef unsigned #undef unsigned
#undef uint8_t #undef uint8_t
@ -71,6 +71,6 @@ typedef unsigned* uintptr_t;
typedef unsigned ptrdiff_t; typedef unsigned ptrdiff_t;
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDINT_H #endif // __MES_STDINT_H

View file

@ -36,14 +36,14 @@ int g_stdout;
#define STDERR 2 #define STDERR 2
#endif #endif
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_STDIO_H #undef __MES_STDIO_H
#include_next <stdio.h> #include_next <stdio.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef __MESCCLIB__ #ifndef __MESCCLIB__
#define __MESCCLIB__ 15 #define __MESCCLIB__ 15
@ -113,6 +113,6 @@ size_t fread (void *ptr, size_t size, size_t count, FILE *stream);
size_t freadahead (FILE *fp); size_t freadahead (FILE *fp);
size_t fwrite (void const *ptr, size_t size, size_t count, FILE *stream); size_t fwrite (void const *ptr, size_t size, size_t count, FILE *stream);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDIO_H #endif // __MES_STDIO_H

View file

@ -20,13 +20,13 @@
#ifndef __MES_STDLIB_H #ifndef __MES_STDLIB_H
#define __MES_STDLIB_H 1 #define __MES_STDLIB_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_STDLIB_H #undef __MES_STDLIB_H
#include_next <stdlib.h> #include_next <stdlib.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef __MES_SIZE_T #ifndef __MES_SIZE_T
#define __MES_SIZE_T #define __MES_SIZE_T
@ -56,7 +56,7 @@ unsigned long long strtoull (char const *nptr, char **endptr, int base);
#include <endian.h> #include <endian.h>
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDLIB_H #endif // __MES_STDLIB_H

View file

@ -20,15 +20,15 @@
#ifndef __MES_STDNORETURN_H #ifndef __MES_STDNORETURN_H
#define __MES_STDNORETURN_H 1 #define __MES_STDNORETURN_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_STDNORETURN_H #undef __MES_STDNORETURN_H
#include_next <stdnoreturn.h> #include_next <stdnoreturn.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
// whut? // whut?
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STDNORETURN_H #endif // __MES_STDNORETURN_H

View file

@ -20,14 +20,14 @@
#ifndef __MES_STRING_H #ifndef __MES_STRING_H
#define __MES_STRING_H 1 #define __MES_STRING_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_STRING_H #undef __MES_STRING_H
#include_next <string.h> #include_next <string.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef NULL #ifndef NULL
#define NULL 0 #define NULL 0
@ -55,10 +55,11 @@ char *strchr (char const *s, int c);
int strcmp (char const*, char const*); int strcmp (char const*, char const*);
char *strcpy (char *dest, char const *src); char *strcpy (char *dest, char const *src);
size_t strlen (char const*); size_t strlen (char const*);
char *strncpy (char *to, char const *from, size_t size);
int strncmp (char const*, char const*, size_t); int strncmp (char const*, char const*, size_t);
char *strrchr (char const *s, int c); char *strrchr (char const *s, int c);
char *strstr (char const *haystack, char const *needle); char *strstr (char const *haystack, char const *needle);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_STRING_H #endif // __MES_STRING_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_STRINGS_H #ifndef __MES_STRINGS_H
#define __MES_STRINGS_H 1 #define __MES_STRINGS_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_STRINGS_H #undef __MES_STRINGS_H
#include_next <strings.h> #include_next <strings.h>
#endif // (__GNUC__ && POSIX) #endif // (WITH_GLIBC)
#endif // __MES_STRINGS_H #endif // __MES_STRINGS_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SYS_CDEFS_H #ifndef __MES_SYS_CDEFS_H
#define __MES_SYS_CDEFS_H 1 #define __MES_SYS_CDEFS_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_CDEFS_H #undef __MES_SYS_CDEFS_H
#include_next <sys/cdefs.h> #include_next <sys/cdefs.h>
#endif // (__GNUC__ && POSIX) #endif // (WITH_GLIBC)
#endif // __MES_SYS_CDEFS_H #endif // __MES_SYS_CDEFS_H

View file

@ -20,13 +20,13 @@
#ifndef __MES_SYS_DIR_H #ifndef __MES_SYS_DIR_H
#define __MES_SYS_DIR_H 1 #define __MES_SYS_DIR_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_DIR_H #undef __MES_SYS_DIR_H
#include_next <sys/dir.h> #include_next <sys/dir.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_DIR_H #endif // __MES_SYS_DIR_H

View file

@ -20,13 +20,13 @@
#ifndef __MES_SYS_FILE_H #ifndef __MES_SYS_FILE_H
#define __MES_SYS_FILE_H 1 #define __MES_SYS_FILE_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_FILE_H #undef __MES_SYS_FILE_H
#include_next <sys/file.h> #include_next <sys/file.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_FILE_H #endif // __MES_SYS_FILE_H

View file

@ -20,17 +20,17 @@
#ifndef __MES_SYS_IOCTL_H #ifndef __MES_SYS_IOCTL_H
#define __MES_SYS_IOCTL_H 1 #define __MES_SYS_IOCTL_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_IOCTL_H #undef __MES_SYS_IOCTL_H
#include_next <sys/ioctl.h> #include_next <sys/ioctl.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#define TCGETS 0x5401 #define TCGETS 0x5401
#define TCGETA 0x5405 #define TCGETA 0x5405
int ioctl (int fd, unsigned long request, ...); int ioctl (int fd, unsigned long request, ...);
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_IOCTL_H #endif // __MES_SYS_IOCTL_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SYS_MMAN_H #ifndef __MES_SYS_MMAN_H
#define __MES_SYS_MMAN_H 1 #define __MES_SYS_MMAN_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_MMAN_H #undef __MES_SYS_MMAN_H
#include_next <sys/mman.h> #include_next <sys/mman.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef __MES_SIZE_T #ifndef __MES_SIZE_T
#define __MES_SIZE_T #define __MES_SIZE_T
@ -37,7 +37,7 @@ typedef unsigned long size_t;
int mprotect (void *addr, size_t len, int prot); int mprotect (void *addr, size_t len, int prot);
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_MMAN_H #endif // __MES_SYS_MMAN_H

View file

@ -20,12 +20,12 @@
#ifndef __MES_SYS_PARAM_H #ifndef __MES_SYS_PARAM_H
#define __MES_SYS_PARAM_H 1 #define __MES_SYS_PARAM_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_PARAM_H #undef __MES_SYS_PARAM_H
#include_next <sys/param.h> #include_next <sys/param.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_PARAM_H #endif // __MES_SYS_PARAM_H

View file

@ -20,12 +20,12 @@
#ifndef __MES_SYS_SELECT_H #ifndef __MES_SYS_SELECT_H
#define __MES_SYS_SELECT_H 1 #define __MES_SYS_SELECT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_SELECT_H #undef __MES_SYS_SELECT_H
#include_next <sys/select.h> #include_next <sys/select.h>
#else //! (__GNUC__ && POSIX) #else //! WITH_GLIBC
typedef int fd_set; typedef int fd_set;
#endif //! (__GNUC__ && POSIX) #endif //! WITH_GLIBC
#endif // __MES_SYS_SELECT_H #endif // __MES_SYS_SELECT_H

View file

@ -20,11 +20,11 @@
#ifndef __MES_SYS_STAT_H #ifndef __MES_SYS_STAT_H
#define __MES_SYS_STAT_H 1lei #define __MES_SYS_STAT_H 1lei
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_STAT_H #undef __MES_SYS_STAT_H
#include_next <sys/stat.h> #include_next <sys/stat.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <sys/types.h> #include <sys/types.h>
@ -75,6 +75,6 @@ int rmdir (char const *file_name);
#define S_IWUSR 00200 #define S_IWUSR 00200
#define S_IRUSR 00400 #define S_IRUSR 00400
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_STAT_H #endif // __MES_SYS_STAT_H

View file

@ -20,11 +20,11 @@
#ifndef __MES_SYS_TIME_H #ifndef __MES_SYS_TIME_H
#define __MES_SYS_TIME_H 1 #define __MES_SYS_TIME_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_TIME_H #undef __MES_SYS_TIME_H
#include_next <sys/time.h> #include_next <sys/time.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
struct timeval struct timeval
{ {
@ -51,6 +51,6 @@ struct itimerval
int gettimeofday (struct timeval *tv, struct timezone *tz); int gettimeofday (struct timeval *tv, struct timezone *tz);
int setitimer (int which, struct itimerval const *new, struct itimerval *old); int setitimer (int which, struct itimerval const *new, struct itimerval *old);
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_TIME_H #endif // __MES_SYS_TIME_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SYS_TIMEB_H #ifndef __MES_SYS_TIMEB_H
#define __MES_SYS_TIMEB_H 1 #define __MES_SYS_TIMEB_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_TIMEB_H #undef __MES_SYS_TIMEB_H
#include_next <sys/timeb.h> #include_next <sys/timeb.h>
#endif // (__GNUC__ && POSIX) #endif // (WITH_GLIBC)
#endif // __MES_SYS_TIMEB_H #endif // __MES_SYS_TIMEB_H

49
include/sys/times.h Normal file
View file

@ -0,0 +1,49 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes 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; either version 3 of the License, or (at
* your option) any later version.
*
* Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_SYS_TIMES_H
#define __MES_SYS_TIMES_H 1
#if WITH_GLIBC
#undef __MES_SYS_TIMES_H
#include_next <sys/times.h>
#else // ! WITH_GLIBC
#ifndef __MES_CLOCK_T
#define __MES_CLOCK_T
#undef clock_t
typedef long clock_t;
#endif
#ifndef HZ
#define HZ 100
#endif
struct tms
{
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};
#endif // ! WITH_GLIBC
#endif // __MES_SYS_TIMES_H

View file

@ -20,22 +20,16 @@
#ifndef __MES_SYS_TYPES_H #ifndef __MES_SYS_TYPES_H
#define __MES_SYS_TYPES_H 1 #define __MES_SYS_TYPES_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_TYPES_H #undef __MES_SYS_TYPES_H
#include_next <sys/types.h> #include_next <sys/types.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#include <endian.h> #include <endian.h>
#ifndef __MES_SIZE_T #ifndef __MES_DEV_T
#define __MES_SIZE_T #define __MES_DEV_T
#undef size_t #undef dev_t
typedef unsigned long size_t; typedef int dev_t;
#endif
#ifndef __MES_PID_T
#define __MES_PID_T
#undef pid_t
typedef int pid_t;
#endif #endif
#ifndef __MES_GID_T #ifndef __MES_GID_T
@ -44,12 +38,30 @@ typedef int pid_t;
typedef int gid_t; typedef int gid_t;
#endif #endif
#ifndef __MES_INO_T
#define __MES_INO_T
#undef ino_t
typedef unsigned ino_t;
#endif
#ifndef __MES_PID_T
#define __MES_PID_T
#undef pid_t
typedef int pid_t;
#endif
#ifndef __MES_SIZE_T
#define __MES_SIZE_T
#undef size_t
typedef unsigned long size_t;
#endif
#ifndef __MES_UID_T #ifndef __MES_UID_T
#define __MES_UID_T #define __MES_UID_T
#undef uid_t #undef uid_t
typedef int uid_t; typedef int uid_t;
#endif #endif
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_TYPES_H #endif // __MES_SYS_TYPES_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SYS_UCONTEXT_H #ifndef __MES_SYS_UCONTEXT_H
#define __MES_SYS_UCONTEXT_H 1 #define __MES_SYS_UCONTEXT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_UCONTEXT_H #undef __MES_SYS_UCONTEXT_H
#include_next <sys/ucontext.h> #include_next <sys/ucontext.h>
#endif // (__GNUC__ && POSIX) #endif // (WITH_GLIBC)
#endif // __MES_SYS_UCONTEXT_H #endif // __MES_SYS_UCONTEXT_H

View file

@ -20,11 +20,11 @@
#ifndef __MES_SYS_USER_H #ifndef __MES_SYS_USER_H
#define __MES_SYS_USER_H 1 #define __MES_SYS_USER_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_USER_H #undef __MES_SYS_USER_H
#include_next <sys/user.h> #include_next <sys/user.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
/* These are the 32-bit x86 structures. */ /* These are the 32-bit x86 structures. */
struct user_fpregs_struct struct user_fpregs_struct
@ -104,6 +104,6 @@ struct user
#define HOST_TEXT_START_ADDR (u.start_code) #define HOST_TEXT_START_ADDR (u.start_code)
#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_USER_H #endif // __MES_SYS_USER_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_SYS_WAIT_H #ifndef __MES_SYS_WAIT_H
#define __MES_SYS_WAIT_H 1 #define __MES_SYS_WAIT_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_SYS_WAIT_H #undef __MES_SYS_WAIT_H
#include_next <sys/wait.h> #include_next <sys/wait.h>
#else // !(__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef __MES_PID_T #ifndef __MES_PID_T
#define __MES_PID_T #define __MES_PID_T
@ -33,6 +33,6 @@ typedef int pid_t;
pid_t waitpid (pid_t pid, int *status_ptr, int options); pid_t waitpid (pid_t pid, int *status_ptr, int options);
pid_t wait (int *status_ptr); pid_t wait (int *status_ptr);
#endif // !(__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_SYS_WAIT_H #endif // __MES_SYS_WAIT_H

View file

@ -20,10 +20,10 @@
#ifndef __MES_TIME_H #ifndef __MES_TIME_H
#define __MES_TIME_H 1 #define __MES_TIME_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#undef __MES_TIME_H #undef __MES_TIME_H
#include_next <time.h> #include_next <time.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
typedef int time_t; typedef int time_t;
struct tm { struct tm {
@ -44,21 +44,22 @@ time_t time (time_t *tloc);
#ifndef __MES_STRUCT_TIMESPEC #ifndef __MES_STRUCT_TIMESPEC
#define __MES_STRUCT_TIMESPEC #define __MES_STRUCT_TIMESPEC
#ifndef __kernel_long_t // #ifndef __kernel_long_t
typedef long __kernel_long_t; // typedef long __kernel_long_t;
typedef unsigned long __kernel_ulong_t; // typedef unsigned long __kernel_ulong_t;
#endif // #endif
typedef __kernel_long_t __kernel_time_t; // typedef __kernel_long_t __kernel_time_t;
struct timespec struct timespec
{ {
__kernel_time_t tv_sec; //__kernel_time_t tv_sec;
long tv_sec;
long tv_nsec; long tv_nsec;
}; };
#endif // __MES_STRUCT_TIMESPEC #endif // __MES_STRUCT_TIMESPEC
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_TIME_H #endif // __MES_TIME_H

View file

@ -20,14 +20,14 @@
#ifndef __MES_UNISTD_H #ifndef __MES_UNISTD_H
#define __MES_UNISTD_H 1 #define __MES_UNISTD_H 1
#if __GNUC__ && POSIX #if WITH_GLIBC
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
#undef __MES_UNISTD_H #undef __MES_UNISTD_H
#include_next <unistd.h> #include_next <unistd.h>
#else // ! (__GNUC__ && POSIX) #else // ! WITH_GLIBC
#ifndef NULL #ifndef NULL
#define NULL 0 #define NULL 0
@ -51,8 +51,20 @@ typedef unsigned long size_t;
typedef long ssize_t; typedef long ssize_t;
#endif #endif
#ifndef R_OK
#define F_OK 0
#define X_OK 1
#define W_OK 2
#define R_OK 4
#endif
int access (char const *s, int mode); int access (char const *s, int mode);
unsigned int alarm (unsigned int seconds);
#define alarm(x) {eputs ("alarm x="); eputs (itoa (x)); eputs ("\n"); kill (getpid (), 14);}
#define atexit(x) eputs ("atexit\n")
int close (int fd); int close (int fd);
int execv (char const *file_name, char *const argv[]);
int execve (char const *file, char *const argv[], char *const env[]); int execve (char const *file, char *const argv[], char *const env[]);
int execvp (char const *file, char *const argv[]); int execvp (char const *file, char *const argv[]);
int fork (); int fork ();
@ -62,6 +74,6 @@ off_t lseek (int fd, off_t offset, int whence);
int read (int fd, void* buf, size_t n); int read (int fd, void* buf, size_t n);
int unlink (char const *file_name); int unlink (char const *file_name);
int write (int fd, char const* s, int n); int write (int fd, char const* s, int n);
#endif // ! (__GNUC__ && POSIX) #endif // ! WITH_GLIBC
#endif // __MES_UNISTD_H #endif // __MES_UNISTD_H

View file

@ -157,8 +157,10 @@ strcspn (char const *string, char const *stopset)
char * char *
strncat (char *to, char const *from, size_t size) strncat (char *to, char const *from, size_t size)
{ {
if (size == 0)
return to;
char *p = strchr (to , '\0'); char *p = strchr (to , '\0');
while (*from && size--) while (*from && size-- > 1)
*p++ = *from++; *p++ = *from++;
*p = 0; *p = 0;
return to; return to;

61
lib/crt0.c Normal file
View file

@ -0,0 +1,61 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes 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; either version 3 of the License, or (at
* your option) any later version.
*
* Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
// no clue what crt0.o is and why gcc-2.6.3 needs it
// instead of calling main, it seems to call either _main or ___main,
// let's try _main first
char **environ = 0;
int _main (int argc, char *argv[]);
void
_start ()
{
asm (
"mov %%ebp,%%eax\n\t"
"addl $4,%%eax\n\t"
"movzbl (%%eax),%%eax\n\t"
"addl $3,%%eax\n\t"
"shl $2,%%eax\n\t"
"add %%ebp,%%eax\n\t"
"movl %%eax,%0\n\t"
: "=environ" (environ)
: //no inputs ""
);
asm (
"mov %%ebp,%%eax\n\t"
"addl $8,%%eax\n\t"
"push %%eax\n\t"
"mov %%ebp,%%eax\n\t"
"addl $4,%%eax\n\t"
"movzbl (%%eax),%%eax\n\t"
"push %%eax\n\t"
"call _main\n\t"
"mov %%eax,%%ebx\n\t"
"mov $1,%%eax\n\t"
"int $0x80\n\t"
"hlt \n\t"
:
);
}

48
lib/gcc.c Normal file
View file

@ -0,0 +1,48 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes 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; either version 3 of the License, or (at
* your option) any later version.
*
* Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>
FILE *
freopen (char const *file_name, char const *opentype, FILE *stream)
{
fclose (stream);
return fopen (file_name, opentype);
}
clock_t
times (struct tms *buffer)
{
eputs ("times stub\n");
return 0;
}
unsigned int
sleep (unsigned int seconds)
{
struct timespec requested_time;
struct timespec remaining;
requested_time.tv_sec = seconds;
requested_time.tv_nsec = 0;
return nanosleep (&requested_time, &remaining);
}

View file

@ -18,6 +18,9 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>. * along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <sys/time.h>
#include <libc+tcc.c> #include <libc+tcc.c>
#include <linux+gnu-gcc.c>
#include <m4.c> #include <m4.c>
#include <binutils.c> #include <binutils.c>
#include <gcc.c>

View file

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software * Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2018 Jeremiah Orians <jeremiah@pdp10.guru>
* Copyright (C) 2018 Han-Wen Nienhuys <hanwen@xs4all.nl> * Copyright (C) 2018 Han-Wen Nienhuys <hanwen@xs4all.nl>
* *
* This file is part of Mes. * This file is part of Mes.
@ -19,6 +20,8 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>. * along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h> #include <setjmp.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@ -57,13 +60,65 @@ dlopen (char const *filename, int flags)
return 0; return 0;
} }
int char *
execvp (char const *file, char *const argv[]) search_path (char const *file_name)
{ {
eputs ("execvp stub\n"); static char buf[256];
char *path = getenv ("PATH");
if (getenv ("MESC_DEBUG"))
{
eputs ("\n search-path: "); eputs (file_name); eputs ("\n");
}
while (*path)
{
char *end = strchr (path, ':');
if (!end)
end = strchr (path, '\0');
strncpy (buf, path, end - path);
buf[end - path] = 0;
if (getenv ("MESC_DEBUG"))
{
eputs (" dir: "); eputs (buf); eputs ("\n");
}
if (buf[end - path] != '/')
strcat (buf, "/");
strcat (buf, file_name);
if (!access (buf, X_OK))
{
if (getenv ("MESC_DEBUG"))
{
eputs (" found: "); eputs (buf); eputs ("\n");
}
return buf;
}
path = end + 1;
}
return 0; return 0;
} }
int
execvp (char const *file_name, char *const argv[])
{
if (file_name[0] != '/')
file_name = search_path (file_name);
if (!file_name)
{
errno = ENOENT;
return -1;
}
if (getenv ("MESC_DEBUG"))
{
eputs (" EXEC: "); eputs (file_name); eputs ("\n");
int i = 0;
while (argv[i])
{
eputs (" arg["); eputs (itoa (i)); eputs ("]: "); eputs (argv[i]); eputs ("\n");
i++;
}
}
return execve (file_name, argv, environ);
}
int int
fclose (FILE *stream) fclose (FILE *stream)
{ {
@ -110,7 +165,18 @@ fread (void *data, size_t size, size_t count, FILE *stream)
if (bytes > 0) if (bytes > 0)
return bytes/size; return bytes/size;
return bytes; return 0;
}
size_t
fwrite (void const *data, size_t size, size_t count, FILE *stream)
{
if (! size || !count)
return 0;
int bytes = write ((int)stream, data, size * count);
if (bytes > 0)
return bytes/size;
return 0;
} }
long long
@ -119,6 +185,31 @@ ftell (FILE *stream)
return lseek ((int)stream, 0, SEEK_CUR); return lseek ((int)stream, 0, SEEK_CUR);
} }
FILE*
fopen (char const *file_name, char const *opentype)
{
int fd;
if (opentype[0] == 'a')
{
fd = open (file_name, O_RDONLY);
if (fd > 0)
{
close (fd);
fd = open (file_name, O_RDWR);
lseek (fd, 0, SEEK_END);
return fd;
}
}
if (opentype[0] == 'w' || opentype[0] == 'a')
/* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
fd = open (file_name, 577 , 384);
else
/* Everything else is a read */
fd = open (file_name, 0, 0);
return (FILE*)fd;
}
int int
fseek (FILE *stream, long offset, int whence) fseek (FILE *stream, long offset, int whence)
{ {
@ -262,7 +353,6 @@ sscanf (char const *str, const char *template, ...)
int r = vsscanf (str, template, ap); int r = vsscanf (str, template, ap);
va_end (ap); va_end (ap);
return r; return r;
return 0;
} }
char * char *
@ -289,16 +379,18 @@ strchr (char const *s, int c)
} }
char * char *
strncpy (char *dest, char const *src, size_t length) strncpy (char *to, char const *from, size_t size)
{ {
char *p = dest; if (size == 0)
while (*src && length--) return to;
*p++ = *src++; char *p = to;
if (*src) while (*from && size--)
length++; *p++ = *from++;
while (length--) if (*from)
size++;
while (size--)
*p++ = 0; *p++ = 0;
return dest; return to;
} }
char * char *
@ -431,6 +523,58 @@ calloc (size_t nmemb, size_t size)
return p; return p;
} }
int
islower (int c)
{
return c >= 'a' && c <= 'z';
}
int
isupper (int c)
{
return c >= 'A' && c <= 'Z';
}
int
tolower (int c)
{
if (isupper (c))
return c + ('a' - 'A');
return c;
}
int
toupper (int c)
{
if (islower (c))
return c - ('a' - 'A');
return c;
}
char *
strlwr (char *string)
{
char *p = string;
while (*p)
{
*p = tolower (*p);
p++;
}
return string;
}
char *
strupr (char *string)
{
char *p = string;
while (*p)
{
*p = toupper (*p);
p++;
}
return string;
}
int int
vfprintf (FILE* f, char const* format, va_list ap) vfprintf (FILE* f, char const* format, va_list ap)
{ {
@ -443,12 +587,90 @@ vfprintf (FILE* f, char const* format, va_list ap)
{ {
p++; p++;
char c = *p; char c = *p;
int left_p = 0;
int precision_p = 0;
int width = -1;
if (c == 'l')
c = *++p;
if (c == '-')
{
left_p = 1;
c = *++p;
}
if (c == '.')
{
precision_p = 1;
c = *++p;
}
char pad = ' ';
if (c == '0')
{
pad = c;
c = *p++;
}
if (c >= '0' && c <= '9')
{
width = abtoi (&p, 10);
c = *p;
}
else if (c == '*')
{
width = va_arg (ap, int);
c = *++p;
}
if (c == 'l')
c = *++p;
switch (c) switch (c)
{ {
case '%': {fputc (*p, fd); break;} case '%': {fputc (*p, fd); break;}
case 'c': {char c; c = va_arg (ap, char); fputc (c, fd); break;} case 'c': {char c; c = va_arg (ap, int); fputc (c, fd); break;}
case 'd': {int d; d = va_arg (ap, int); fputs (itoa (d), fd); break;} case 'd':
case 's': {char *s; s = va_arg (ap, char *); fputs (s, fd); break;} case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
{
int d = va_arg (ap, int);
int base = c == 'o' ? 8
: c == 'x' || c == 'X' ? 16
: 10;
char const *s = number_to_ascii (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X')
strupr (s);
if (!precision_p && width >= 0)
width = width - strlen (s);
if (!left_p && !precision_p)
while (!precision_p && width-- > 0)
fputc (pad, f);
while (*s)
{
if (precision_p && width-- == 0)
break;
fputc (*s++, f);
}
while (!precision_p && width-- > 0)
fputc (pad, f);
break;
}
case 's':
{
char *s = va_arg (ap, char *);
if (!precision_p && width >= 0)
width = width - strlen (s);
if (!left_p && !precision_p)
while (!precision_p && width-- > 0)
fputc (pad, f);
while (*s)
{
if (precision_p && width-- == 0)
break;
fputc (*s++, f);
}
while (!precision_p && width-- > 0)
fputc (pad, f);
break;
}
default: default:
{ {
eputs ("vfprintf: not supported: %"); eputs ("vfprintf: not supported: %");
@ -474,6 +696,7 @@ vsscanf (char const *s, char const *template, va_list ap)
{ {
char const *p = s; char const *p = s;
char const *t = template; char const *t = template;
int count = 0;
while (*t && *p) while (*t && *p)
if (*t != '%') if (*t != '%')
{ {
@ -487,10 +710,22 @@ vsscanf (char const *s, char const *template, va_list ap)
switch (c) switch (c)
{ {
case '%': {p++; break;} case '%': {p++; break;}
case 'c': {char *c = va_arg (ap, char*); *c = *p++; break;} case 'c':
{
char *c = va_arg (ap, char*);
*c = *p++;
count++;
break;
}
case 'd': case 'd':
case 'i': case 'i':
case 'u': {int *d = va_arg (ap, int*); *d = abtoi (&p, 10); break;} case 'u':
{
int *d = va_arg (ap, int*);
*d = abtoi (&p, 10);
count++;
break;
}
default: default:
{ {
eputs ("vsscanf: not supported: %"); eputs ("vsscanf: not supported: %");
@ -503,7 +738,7 @@ vsscanf (char const *s, char const *template, va_list ap)
t++; t++;
} }
va_end (ap); va_end (ap);
return 0; return count;
} }
int int
@ -518,12 +753,20 @@ vsprintf (char *str, char const* format, va_list ap)
p++; p++;
char c = *p; char c = *p;
int left_p = 0; int left_p = 0;
int precision_p = 0;
int width = -1; int width = -1;
if (c == 'l')
c = *++p;
if (c == '-') if (c == '-')
{ {
left_p = 1; left_p = 1;
c = *++p; c = *++p;
} }
if (c == '.')
{
precision_p = 1;
c = *++p;
}
char pad = ' '; char pad = ' ';
if (c == '0') if (c == '0')
{ {
@ -535,28 +778,64 @@ vsprintf (char *str, char const* format, va_list ap)
width = abtoi (&p, 10); width = abtoi (&p, 10);
c = *p; c = *p;
} }
else if (c == '*')
{
width = va_arg (ap, int);
c = *++p;
}
if (c == 'l')
c = *++p;
switch (c) switch (c)
{ {
case '%': {*str++ = *p; break;} case '%': {*str++ = *p; break;}
case 'c': {char c; c = va_arg (ap, char); *str++ = c; break;} case 'c': {c = va_arg (ap, int); *str++ = c; break;}
case 'd': case 'd':
case 'i': case 'i':
case 'o':
case 'u': case 'u':
case 'x':
case 'X':
{ {
int d = va_arg (ap, int); int d = va_arg (ap, int);
char const *s = itoa (d); int base = c == 'o' ? 8
if (width >= 0) : c == 'x' || c == 'X' ? 16
: 10;
char const *s = number_to_ascii (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X')
strupr (s);
if (!precision_p && width >= 0)
width = width - strlen (s); width = width - strlen (s);
if (!left_p) if (!left_p && !precision_p)
while (width-- > 0) while (!precision_p && width-- > 0)
*str++ = pad; *str++ = pad;
while (*s) while (*s)
*str++ = *s++; {
while (width-- > 0) if (precision_p && width-- == 0)
break;
*str++ = *s++;
}
while (!precision_p && width-- > 0)
*str++ = pad;
break;
}
case 's':
{
char *s = va_arg (ap, char *);
if (!precision_p && width >= 0)
width = width - strlen (s);
if (!left_p && !precision_p)
while (!precision_p && width-- > 0)
*str++ = pad;
while (*s)
{
if (precision_p && width-- == 0)
break;
*str++ = *s++;
}
while (!precision_p && width-- > 0)
*str++ = pad; *str++ = pad;
break; break;
} }
case 's': {char *s; s = va_arg (ap, char *); while (*s) *str++ = *s++; break;}
default: default:
{ {
eputs ("vsprintf: not supported: %"); eputs ("vsprintf: not supported: %");

View file

@ -1,7 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software * Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2018 Jeremiah Orians <jeremiah@pdp10.guru>
* *
* This file is part of Mes. * This file is part of Mes.
* *
@ -36,7 +35,6 @@
#else // !__MESC__ #else // !__MESC__
#include <fcntl.h>
#include <assert.h> #include <assert.h>
#include <linux-gcc.c> #include <linux-gcc.c>
@ -81,20 +79,6 @@ putc (int c, FILE* stream)
return fdputc (c, (int)stream); return fdputc (c, (int)stream);
} }
FILE*
fopen (char const* file_name, char const* mode)
{
int fd;
if ('w' == mode[0])
/* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */
fd = open (file_name, 577 , 384);
else
/* Everything else is a read */
fd = open (file_name, 0, 0);
return (FILE*)fd;
}
void void
assert_fail (char* s) assert_fail (char* s)
{ {
@ -186,6 +170,8 @@ realloc (void *ptr, size_t size)
int int
strncmp (char const* a, char const* b, size_t size) strncmp (char const* a, char const* b, size_t size)
{ {
if (!size)
return 0;
while (*a && *b && *a == *b && --size) while (*a && *b && *a == *b && --size)
{ {
a++; a++;
@ -194,17 +180,6 @@ strncmp (char const* a, char const* b, size_t size)
return *a - *b; return *a - *b;
} }
size_t
fwrite (void const *data, size_t size, size_t count, FILE *stream)
{
if (! size || !count)
return 0;
int bytes = write ((int)stream, data, size * count);
if (bytes > 0)
return count;
return bytes;
}
char * char *
getenv (char const* s) getenv (char const* s)
{ {
@ -252,3 +227,9 @@ wait (int *status_ptr)
{ {
return waitpid (-1, status_ptr, 0); return waitpid (-1, status_ptr, 0);
} }
int
execv (char const *file_name, char *const argv[])
{
return execve (file_name, argv, environ);
}

96
lib/libg.c Normal file
View file

@ -0,0 +1,96 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes 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; either version 3 of the License, or (at
* your option) any later version.
*
* Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
// gcc/xgcc wants -lg with all these
// what's the story here?
#include <sys/time.h>
#define exit __exit
#define fprintf _fprintf
#define longjmp _longjmp
#define malloc _malloc
#define printf _printf
#define putchar _putchar
#define setjmp _setjmp
#define signal _signal
#define strcmp _strcmp
#define sprintf _sprintf
#define sscanf _sscanf
#include <libc+tcc.c>
#include <linux+gnu-gcc.c>
#include <m4.c>
#include <binutils.c>
#include <gcc.c>
int
__cleanup ()
{
eputs ("cleanup stub\n");
return 0;
}
int
_dprop ()
{
eputs ("dprop stub\n");
}
int
_edprop ()
{
eputs ("edprop stub\n");
}
int
_eldprop ()
{
eputs ("eldprop stub\n");
}
int
_iprop ()
{
eputs ("iprop stub\n");
}
int
_lprop ()
{
eputs ("lprop stub\n");
}
int
_ldprop ()
{
eputs ("ldprop stub\n");
}
int
_uiprop ()
{
eputs ("uiprop stub\n");
}
int
_ulprop ()
{
eputs ("ulprop stub\n");
}

View file

@ -84,7 +84,7 @@ atoi (char const *s)
} }
char const* char const*
itoa (int x) number_to_ascii (int x, int base, int signed_p)
{ {
static char itoa_buf[12]; static char itoa_buf[12];
char *p = itoa_buf + 11; char *p = itoa_buf + 11;
@ -92,7 +92,7 @@ itoa (int x)
int sign = 0; int sign = 0;
unsigned u = x; unsigned u = x;
if (x < 0) if (signed_p && x < 0)
{ {
sign = 1; sign = 1;
u = -x; u = -x;
@ -100,8 +100,9 @@ itoa (int x)
do do
{ {
*p-- = '0' + (u % 10); int i = u % base;
u = u / 10; *p-- = i > 9 ? 'a' + i - 10 : '0' + i;
u = u / base;
} while (u); } while (u);
if (sign && *(p + 1) != '0') if (sign && *(p + 1) != '0')
@ -113,29 +114,19 @@ itoa (int x)
char const* char const*
itoab (int x, int base) itoab (int x, int base)
{ {
static char itoa_buf[12]; return number_to_ascii (x, base, 1);
char *p = itoa_buf + 11; }
*p-- = 0;
int sign = 0; char const*
unsigned u = x; itoa (int x)
if (x < 0) {
{ return number_to_ascii (x, 10, 1);
sign = 1; }
u = -x;
}
do char const*
{ utoa (unsigned x)
int i = u % base; {
*p-- = i > 9 ? 'a' + i - 10 : '0' + i; return number_to_ascii (x, 10, 0);
x = u / base;
} while (u);
if (sign && *(p + 1) != '0')
*p-- = '-';
return p+1;
} }
int _ungetc_pos = -1; int _ungetc_pos = -1;
@ -187,7 +178,7 @@ fdungetc (int c, int fd)
return c; return c;
} }
#if POSIX #if POSIX || __x86_64__
#define STDERR 2 #define STDERR 2
int int
eputs (char const* s) eputs (char const* s)

179
lib/linux+gnu-gcc.c Normal file
View file

@ -0,0 +1,179 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes 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; either version 3 of the License, or (at
* your option) any later version.
*
* Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#define SYS_link "0x09"
#define SYS_rename "0x26"
#define SYS_mkdir "0x27"
#define SYS_dup "0x29"
#define SYS_pipe "0x2a"
#define SYS_lstat "0x6b"
#define SYS_fstat "0x6c"
#define SYS_kill 0x25
#define SYS_nanosleep 0xa2
int
link (char const *old_name, char const *new_name)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_link",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (old_name), "" (new_name)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
kill (pid_t pid, int signum)
{
return _sys_call2 (SYS_kill, pid, signum);
}
int
rename (char const *old_name, char const *new_name)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_rename",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (old_name), "" (new_name)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
mkdir (char const *s, mode_t mode)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_mkdir",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (s), "" (mode)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
dup (int old)
{
#if !__TINYC__
int r;
asm (
"mov %0,%%ebx\n\t"
"mov $"SYS_dup",%%eax\n\t"
"int $0x80"
: "=r" (r)
: "" (old)
);
return r;
#endif
}
int
pipe (int filedes[2])
{
#if !__TINYC__
int r;
asm (
"mov %0,%%ebx\n\t"
"mov $"SYS_pipe",%%eax\n\t"
"int $0x80"
: "=r" (r)
: "" (filedes)
);
return r;
#endif
}
int
lstat (char const *file_name, struct stat *statbuf)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_lstat",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (file_name), "" (statbuf)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
nanosleep (const struct timespec *requested_time,
struct timespec *remaining)
{
return _sys_call2 (SYS_execve, (int)requested_time, (int)remaining);
}
int
fstat (int fd, struct stat *statbuf)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_fstat",%%eax\n\t"
//"mov $"SYS_oldfstat",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (fd), "" (statbuf)
: "eax", "ebx", "ecx"
);
return r;
#endif
}

View file

@ -19,16 +19,10 @@
*/ */
#define SYS_close "0x06" #define SYS_close "0x06"
#define SYS_link "0x09"
#define SYS_unlink "0x0a"
#define SYS_lseek "0x13" #define SYS_lseek "0x13"
#define SYS_access "0x21" #define SYS_unlink "0x0a"
#define SYS_rename "0x26"
#define SYS_mkdir "0x27"
#define SYS_rmdir "0x28" #define SYS_rmdir "0x28"
#define SYS_stat "0x6a" #define SYS_stat "0x6a"
#define SYS_lstat "0x6b"
#define SYS_fstat "0x6c"
#define SYS_getcwd "0xb7" #define SYS_getcwd "0xb7"
int int
@ -47,43 +41,6 @@ close (int fd)
#endif #endif
} }
int
link (char const *old_name, char const *new_name)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_link",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (old_name), "" (new_name)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
unlink (char const *file_name)
{
#if !__TINYC__
int r;
asm (
"mov %0,%%ebx\n\t"
"mov $"SYS_unlink",%%eax\n\t"
"int $0x80"
: "=r" (r)
: "" (file_name)
);
return r;
#endif
}
off_t off_t
lseek (int fd, off_t offset, int whence) lseek (int fd, off_t offset, int whence)
{ {
@ -107,40 +64,16 @@ lseek (int fd, off_t offset, int whence)
} }
int int
rename (char const *old_name, char const *new_name) unlink (char const *file_name)
{ {
#if !__TINYC__ #if !__TINYC__
int r; int r;
asm ( asm (
"mov %1,%%ebx\n\t" "mov %0,%%ebx\n\t"
"mov %2,%%ecx\n\t" "mov $"SYS_unlink",%%eax\n\t"
"int $0x80"
"mov $"SYS_rename",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r) : "=r" (r)
: "" (old_name), "" (new_name) : "" (file_name)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
mkdir (char const *s, mode_t mode)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_mkdir",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (s), "" (mode)
: "eax", "ebx", "ecx"
); );
return r; return r;
#endif #endif
@ -179,49 +112,8 @@ stat (char const *file_name, struct stat *statbuf)
: "" (file_name), "" (statbuf) : "" (file_name), "" (statbuf)
: "eax", "ebx", "ecx" : "eax", "ebx", "ecx"
); );
return r; if (r < 0)
#endif errno = -r;
}
int
lstat (char const *file_name, struct stat *statbuf)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_lstat",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (file_name), "" (statbuf)
: "eax", "ebx", "ecx"
);
return r;
#endif
}
int
fstat (int fd, struct stat *statbuf)
{
#if !__TINYC__
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov $"SYS_fstat",%%eax\n\t"
//"mov $"SYS_oldfstat",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (fd), "" (statbuf)
: "eax", "ebx", "ecx"
);
return r; return r;
#endif #endif
} }

View file

@ -43,7 +43,7 @@ rmdir (char const *file_name)
{ {
asm ("mov____0x8(%ebp),%ebx !8"); asm ("mov____0x8(%ebp),%ebx !8");
asm ("mov____$i32,%eax SYS_unlink"); asm ("mov____$i32,%eax SYS_rmdir");
asm ("int____$0x80"); asm ("int____$0x80");
} }

View file

@ -18,6 +18,7 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>. * along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <libmes.h> #include <libmes.h>
#include <stdlib.h> #include <stdlib.h>
@ -29,13 +30,61 @@
#define SYS_read "0x03" #define SYS_read "0x03"
#define SYS_open "0x05" #define SYS_open "0x05"
#define SYS_waitpid "0x07" #define SYS_waitpid "0x07"
#define SYS_execve "0x0b" #define SYS_execve 0x0b
#define SYS_chmod "0x0f" #define SYS_chmod "0x0f"
#define SYS_access "0x21" #define SYS_access "0x21"
#define SYS_brk "0x2d" #define SYS_brk "0x2d"
#define SYS_ioctl "0x36" #define SYS_ioctl "0x36"
#define SYS_fsync "0x76" #define SYS_fsync "0x76"
#define xSYS_execve "0x0b"
int
_sys_call2 (int sys_call, int one, int two)
{
#if !__TINYC__
int r;
asm (
"mov %2,%%ebx\n\t"
"mov %3,%%ecx\n\t"
"mov %1,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (sys_call), "" (one), "" (two)
: "eax", "ebx", "ecx"
);
if (r < 0)
errno = -r;
return r;
#endif
}
int
_sys_call3 (int sys_call, int one, int two, int three)
{
#if !__TINYC__
int r;
asm (
"mov %2,%%ebx\n\t"
"mov %3,%%ecx\n\t"
"mov %4,%%edx\n\t"
"mov %1,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (sys_call), "" (one), "" (two), "" (three)
: "eax", "ebx", "ecx", "edx"
);
if (r < 0)
errno = -r;
return r;
#endif
}
int int
fork () fork ()
{ {
@ -131,23 +180,7 @@ waitpid (pid_t pid, int *status_ptr, int options)
int int
execve (char const* file_name, char *const argv[], char *const env[]) execve (char const* file_name, char *const argv[], char *const env[])
{ {
#if !__TINYC__ return _sys_call3 (SYS_execve, (int)file_name, (int)argv, (int)env);
int r;
asm (
"mov %1,%%ebx\n\t"
"mov %2,%%ecx\n\t"
"mov %3,%%edx\n\t"
"mov $"SYS_execve",%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
: "" (file_name), "" (argv), "" (env)
: "eax", "ebx", "ecx", "edx"
);
return r;
#endif
} }
int int

View file

@ -100,12 +100,6 @@ iscntrl (int c)
return c >= 0 && c < 32; return c >= 0 && c < 32;
} }
int
islower (int c)
{
return c >= 'a' && c <= 'z';
}
int int
isprint (int c) isprint (int c)
{ {
@ -118,17 +112,17 @@ ispunct (int c)
return isprint (c) && !isspace (c) && !isalnum (c); return isprint (c) && !isspace (c) && !isalnum (c);
} }
int
isupper (int c)
{
return c >= 'A' && c <= 'Z';
}
char * char *
mktemp (char *template) mktemp (char *template)
{ {
char *p = strchr (template, '0'); char *p = strchr (template, '\0');
*--p = &p; int q = (int)template;
*--p = ((unsigned char)(q >> 4)) % 26 + 'a';
*--p = ((unsigned char)(q >> 8)) % 26 + 'a';
*--p = ((unsigned char)(q >> 12)) % 26 + 'a';
*--p = ((unsigned char)(q >> 16)) % 26 + 'a';
*--p = ((unsigned char)(q >> 20)) % 26 + 'a';
*--p = ((unsigned char)(q >> 24)) % 26 + 'a';
return template; return template;
} }
@ -193,19 +187,3 @@ system (int x)
eputs ("system stub\n"); eputs ("system stub\n");
return 0; return 0;
} }
int
tolower (int c)
{
if (isupper (c))
return c + ('a' - 'A');
return c;
}
int
toupper (int c)
{
if (islower (c))
return c - ('a' - 'A');
return c;
}

View file

@ -217,6 +217,7 @@ DEFINE movzwl_0x8(%ebp),%eax 0fb745
DEFINE SYS_exit 01000000 DEFINE SYS_exit 01000000
DEFINE SYS_fork 02000000 DEFINE SYS_fork 02000000
DEFINE SYS_read 03000000 DEFINE SYS_read 03000000
DEFINE SYS_rmdir 28000000
DEFINE SYS_write 04000000 DEFINE SYS_write 04000000
DEFINE SYS_open 05000000 DEFINE SYS_open 05000000
DEFINE SYS_close 06000000 DEFINE SYS_close 06000000

View file

@ -23,6 +23,22 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if __i386__
#define strncmp xstrncmp
int
strncmp (char const* a, char const* b, size_t size)
{
if (!size)
return 0;
while (*a && *b && *a == *b && --size)
{
a++;
b++;
}
return *a - *b;
}
#endif
int int
test () test ()
{ {
@ -69,7 +85,7 @@ test ()
if (!strncmp ("abc", "x", 1)) if (!strncmp ("abc", "x", 1))
return 10; return 10;
if (!strncmp ("abc", "", 0)) if (strncmp ("abc", "", 0))
return 11; return 11;
return 0; return 0;

View file

@ -21,6 +21,7 @@
#include "30-test.i" #include "30-test.i"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
int int
test () test ()
@ -66,5 +67,72 @@ test ()
if (strcmp (buf, ">44<")) if (strcmp (buf, ">44<"))
return 7; return 7;
printf (">>%.*s<<\n", 5, "hello, world");
printf (">>%.*s<<\n", 20, "hello, world");
printf (">>%.*s<<\n", 10, "foo");
printf (">>%*s<<\n", 10, "bar");
printf (">>%-*s<<\n", 10, "baz");
sprintf (buf, "%ld", 42);
eputs ("buf="); eputs (buf); eputs ("\n");
if (strcmp (buf, "42"))
return 8;
sprintf (buf, "%u", -1);
eputs ("buf="); eputs (buf); eputs ("\n");
if (strcmp (buf, "4294967295"))
return 9;
sprintf (buf, ">>%.5s<<\n", "hello, world");
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>hello<<\n"))
return 10;
sprintf (buf, ">>%.*s<<\n", 5, "hello, world");
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>hello<<\n"))
return 11;
sprintf (buf, ">>%.*s<<\n", 20, "hello, world");
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>hello, world<<\n"))
return 12;
sprintf (buf, ">>%.*s<<\n", 10, "foo");
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>foo<<\n"))
return 13;
sprintf (buf, ">>%*s<<\n", 10, "bar");
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">> bar<<\n"))
return 14;
sprintf (buf, ">>%-*s<<\n", 10, "baz");
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>baz <<\n"))
return 15;
sprintf (buf, ">>%ld<<\n", 12);
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>12<<\n"))
return 16;
sprintf (buf, ">>%o<<\n", 12);
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>14<<\n"))
return 17;
sprintf (buf, ">>%x<<\n", 12);
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>c<<\n"))
return 18;
sprintf (buf, ">>%X<<\n", 12);
eputs ("buf="); eputs (buf);
if (strcmp (buf, ">>C<<\n"))
return 19;
return 0; return 0;
} }

View file

@ -26,14 +26,14 @@ test ()
{ {
int i; int i;
int r = sscanf ("42", "%d", &i); int r = sscanf ("42", "%d", &i);
if (r) if (r != 1)
return 1; return 1;
if (i != 42) if (i != 42)
return 2; return 2;
char c; char c;
r = sscanf ("foo bar", "foo%cbar", &c); r = sscanf ("foo bar", "foo%cbar", &c);
if (r) if (r != 1)
return 3; return 3;
if (c != ' ') if (c != ' ')
return 4; return 4;

View file

@ -284,7 +284,7 @@ execl_ (SCM file_name, SCM args) ///((name . "execl"))
args = CDR (args); args = CDR (args);
} }
c_argv[i] = 0; c_argv[i] = 0;
return MAKE_NUMBER (execve (c_argv[0], c_argv, environ)); return MAKE_NUMBER (execv (c_argv[0], c_argv));
} }
SCM SCM