scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit bf6ef5c8f08b77bc3f2b0cca055524c29fa162bc
parent cde329014490fa4c73da1f81104fa5b9d46d308e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 14 Sep 2021 13:30:05 +0200

libc: Fix arch/posix

As part of the big integration some of the functions located in
arch/posix were broken. This patch solves the problem and makes
a better separation between portable and not portable parts  of
the code.

Diffstat:
Minclude/bits/darwin/sys.h | 1+
Minclude/bits/dragonfly/sys.h | 1+
Minclude/bits/linux/sys.h | 1+
Minclude/bits/netbsd/sys.h | 1+
Minclude/bits/openbsd/sys.h | 1+
Asrc/libc/arch/posix/Makefile | 20++++++++++++++++++++
Msrc/libc/arch/posix/_open.c | 6+++---
Asrc/libc/arch/posix/_systime.c | 21+++++++++++++++++++++
Msrc/libc/arch/posix/clock.c | 2+-
Asrc/libc/arch/posix/deps.mk | 7+++++++
Msrc/libc/arch/posix/getenv.c | 1+
Msrc/libc/arch/posix/raise.c | 2+-
Msrc/libc/arch/posix/signal.c | 9+++++----
Msrc/libc/arch/posix/time.c | 5+++--
Asrc/libc/arch/posix/time.h | 4++++
15 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/include/bits/darwin/sys.h b/include/bits/darwin/sys.h @@ -6,6 +6,7 @@ #define O_APPEND 0x00000008 #define O_CREAT 0x00000200 +#define AT_FDCWD -100 #define CLOCKS_PER_SEC ((clock_t) 1000000) #define RUSAGE_SELF 0 diff --git a/include/bits/dragonfly/sys.h b/include/bits/dragonfly/sys.h @@ -6,6 +6,7 @@ #define O_APPEND 0x00000008 #define O_CREAT 0x00000200 +#define AT_FDCWD -100 #define CLOCKS_PER_SEC ((clock_t) 128) #define RUSAGE_SELF 0 diff --git a/include/bits/linux/sys.h b/include/bits/linux/sys.h @@ -6,6 +6,7 @@ #define O_APPEND 0x00000400 #define O_CREAT 0x00000040 +#define AT_FDCWD -100 #define CLOCKS_PER_SEC ((clock_t) 1000000) #define RUSAGE_SELF 0 diff --git a/include/bits/netbsd/sys.h b/include/bits/netbsd/sys.h @@ -6,6 +6,7 @@ #define O_APPEND 0x00000008 #define O_CREAT 0x00000200 +#define AT_FDCWD -100 #define CLOCKS_PER_SEC ((clock_t) 100) #define RUSAGE_SELF 0 diff --git a/include/bits/openbsd/sys.h b/include/bits/openbsd/sys.h @@ -6,6 +6,7 @@ #define O_APPEND 0x00000008 #define O_CREAT 0x00000200 +#define AT_FDCWD -100 #define CLOCKS_PER_SEC ((clock_t) 100) #define RUSAGE_SELF 0 diff --git a/src/libc/arch/posix/Makefile b/src/libc/arch/posix/Makefile @@ -0,0 +1,20 @@ +.POSIX: +PROJECTDIR =../../../.. +RULES = user +include $(PROJECTDIR)/scripts/rules.mk +include $(SRCDIR)/libc/rules.mk + +OBJS=\ + _getheap.$O\ + _open.$O\ + _systime.$O\ + _tzone.$O\ + clock.$O\ + getenv.$O\ + raise.$O\ + signal.$O\ + time.$O\ + +all: $(OBJS) + +include deps.mk diff --git a/src/libc/arch/posix/_open.c b/src/libc/arch/posix/_open.c @@ -1,10 +1,10 @@ #include <stddef.h> -#include "../../../syscall.h" +#include <sys.h> -#define AT_FDCWD -100 +#include "../../syscall.h" -extern int _openat(int fd, const char *fname, int flags, int mode); +extern int _openat(int, const char *, int, int); int _open(const char *fname, int flags, int mode) diff --git a/src/libc/arch/posix/_systime.c b/src/libc/arch/posix/_systime.c @@ -0,0 +1,21 @@ +#include <time.h> + +#include "../../libc.h" + +time_t +_systime(struct tm *tm) +{ + time_t t = 0; + int year = tm->tm_year + MINYEAR; + + for (int i = EPOCH; i < year; ++i) + t += _daysyear(i) * SECDAY; + for (int i = 0; i < tm->tm_mon; ++i) + t += _daysmon[i] * SECDAY; + + t += tm->tm_sec; + t += tm->tm_min * SECMIN; + t += tm->tm_hour * SECHOUR; + t += (tm->tm_mday-1) * SECDAY; + return t; +} diff --git a/src/libc/arch/posix/clock.c b/src/libc/arch/posix/clock.c @@ -36,5 +36,5 @@ clock(void) if (_getrusage(RUSAGE_SELF, &ru)) return -1; - return TOCLOCK(ru.ru_utime) + TOCLOCK(ru_ru_stime); + return TOCLOCK(ru.ru_utime) + TOCLOCK(ru.ru_stime); } diff --git a/src/libc/arch/posix/deps.mk b/src/libc/arch/posix/deps.mk @@ -0,0 +1,7 @@ +#deps +./_getheap.o: ./../../libc.h +./_open.o: ./../../syscall.h +./_systime.o: ./../../libc.h +./_tzone.o: ./../../libc.h +./clock.o: ./time.h +./time.o: ./time.h diff --git a/src/libc/arch/posix/getenv.c b/src/libc/arch/posix/getenv.c @@ -1,5 +1,6 @@ #include <stdlib.h> #include <string.h> + #undef getenv extern char **_environ; diff --git a/src/libc/arch/posix/raise.c b/src/libc/arch/posix/raise.c @@ -1,5 +1,5 @@ -#include <stddef.h> #include <signal.h> + #include <sys.h> #undef raise diff --git a/src/libc/arch/posix/signal.c b/src/libc/arch/posix/signal.c @@ -1,17 +1,18 @@ -#include <stddef.h> #include <signal.h> + #include <sys.h> + #undef signal void (*signal(int signum, void (*func)(int)))(int) { - struct sigaction sa = { + struct sigaction osa, sa = { .sa_handler = func, }; - if (_sigaction(signum, &sa, &sa) < 0) + if (_sigaction(signum, &sa, &osa) < 0) return SIG_ERR; - return sa.sa_handler; + return osa.sa_handler; } diff --git a/src/libc/arch/posix/time.c b/src/libc/arch/posix/time.c @@ -1,7 +1,8 @@ #include <time.h> -int -_gettimeofday(struct timeval *restrict, void *tzp); +#include "time.h" + +extern int _gettimeofday(struct timeval *restrict, void *); time_t time(time_t *t) diff --git a/src/libc/arch/posix/time.h b/src/libc/arch/posix/time.h @@ -0,0 +1,4 @@ +struct timeval { + time_t tv_sec; + __suseconds_t tv_usec; +};