mescc: Mes C Library: Support make: Implement clock_gettime, time.

* include/linux/x86/syscall.h (SYS_time, SYS_clock_gettime,
SYS_gettimeofday): New macro.
* include/linux/x86_64/syscall.h (SYS_time, SYS_clock_gettime,
SYS_gettimeofday): New macro.
* lib/linux/tcc.c (gettimeofday, time): New function.
* lib/linux/gnu.c (clock_gettime): New function.
* include/time.h: Declare it.
* lib/stub/gettimeofday.c: Remove.
* lib/stub/time.c: Remove.
This commit is contained in:
Jan Nieuwenhuizen 2018-08-27 00:34:13 +02:00
parent 2fe2e556e8
commit 06e9dd4bce
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
8 changed files with 42 additions and 82 deletions

View file

@ -39,13 +39,16 @@
// libc+tcc
#define SYS_close 0x06
#define SYS_time 0x0d
#define SYS_lseek 0x13
#define SYS_unlink 0x0a
#define SYS_rmdir 0x28
#define SYS_gettimeofday 0x4e
#define SYS_stat 0x6a
#define SYS_getcwd 0xb7
// libc+gnu
#define SYS_chdir 0x0c
#define SYS_link 0x09
#define SYS_getpid 0x14
@ -68,5 +71,6 @@
#define SYS_fstat 0x6c
#define SYS_nanosleep 0xa2
#define SYS_getdents 0x8d
#define SYS_clock_gettime 0x109
#endif // __MES_LINUX_X86_SYSCALL_H

View file

@ -39,9 +39,11 @@
// libc+tcc
#define SYS_close 0x03
#define SYS_time 0xc9
#define SYS_lseek 0x08
#define SYS_unlink 0x57
#define SYS_rmdir 0x54
#define SYS_gettimeofday 0x60
#define SYS_stat 0x04
#define SYS_getcwd 0x4f
@ -65,5 +67,6 @@
#define SYS_fstat 0x05
#define SYS_nanosleep 0x33
#define SYS_getdents 0x4e
#define SYS_clock_gettime 0xe4
#endif // __MES_LINUX_X86_64_SYSCALL_H

View file

@ -27,7 +27,8 @@
#ifndef __MES_TIME_T
#define __MES_TIME_T 1
typedef int time_t;
typedef long int clockid_t;
typedef long int time_t;
#endif
struct tm {
@ -42,11 +43,6 @@ struct tm {
int tm_isdst;
};
struct tm *localtime (time_t const *timep);
struct tm *gmtime (time_t const *time);
time_t time (time_t *tloc);
#ifndef __MES_STRUCT_TIMESPEC
#define __MES_STRUCT_TIMESPEC
@ -58,6 +54,12 @@ struct timespec
#endif // __MES_STRUCT_TIMESPEC
int clock_gettime (clockid_t clk_id, struct timespec *tp);
struct tm *localtime (time_t const *timep);
struct tm *gmtime (time_t const *time);
time_t time (time_t *tloc);
#endif // ! WITH_GLIBC
#endif // __MES_TIME_H

View file

@ -98,9 +98,7 @@
#include <string/strrchr.c>
#include <string/strstr.c>
#include <string/strupr.c>
#include <stub/time.c>
#include <stub/sigaction.c>
#include <stub/gettimeofday.c>
#include <stub/ldexp.c>
#include <stub/mprotect.c>
#include <stub/localtime.c>

View file

@ -19,12 +19,7 @@
*/
#include <sys/resource.h>
int
chdir (char const *file_name)
{
return _sys_call1 (SYS_chdir, (long)file_name);
}
#include <time.h>
int
link (char const *old_name, char const *new_name)
@ -157,3 +152,15 @@ getdents (long filedes, char *buffer, size_t nbytes)
{
return _sys_call3 (SYS_getdents, (long)filedes, (long)buffer, (long)nbytes);
}
int
chdir (char const *file_name)
{
return _sys_call1 (SYS_chdir, (long)file_name);
}
int
clock_gettime (clockid_t clk_id, struct timespec *tp)
{
return _sys_call2 (SYS_clock_gettime, (long)clk_id, (long)tp);
}

View file

@ -18,6 +18,8 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <time.h>
int
close (int filedes)
{
@ -58,3 +60,15 @@ getcwd (char *buffer, size_t size)
{
return _sys_call2 (SYS_getcwd, (long)buffer, (long)size);
}
time_t
time (time_t *result)
{
return _sys_call1 (SYS_time, (long)result);
}
int
gettimeofday (struct timeval *tv, struct timezone *tz)
{
return _sys_call2 (SYS_gettimeofday, (long)tv, (long)tz);
}

View file

@ -1,34 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU 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.
*
* GNU 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <time.h>
#include <sys/time.h>
int
gettimeofday (struct timeval *tv, struct timezone *tz)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("gettimeofday stub\n");
stub = 1;
errno = 0;
return 0;
}

View file

@ -1,34 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU 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.
*
* GNU 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <time.h>
#include <sys/time.h>
time_t
time (time_t *tloc)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("time stub\n");
stub = 1;
errno = 0;
return 0;
}