1 /* -*-comment-start: "//";comment-end:""-*-
2 * GNU Mes --- Maxwell Equations of Software
3 * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of GNU Mes.
7 * GNU Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
31 #if __MESC__ && __i386__
32 #include <linux/x86-mes/mes.c>
33 #elif __MESC__ && __x86_64__
34 #include <linux/x86_64-mes/mes.c>
36 #include <linux/x86-mes-gcc/mes.c>
38 #include <linux/x86_64-mes-gcc/mes.c>
40 #error arch not supported
46 return _sys_call (SYS_fork);
50 read (int filedes, void *buffer, size_t size)
52 ssize_t bytes = _sys_call3 (SYS_read, (int)filedes, (long)buffer, (long)size);
53 if (__mes_debug () > 3)
57 eputs ("read fd="); eputs (itoa ((int)filedes)); eputs (" c="); eputc (*(char*)buffer); eputs ("\n");
61 eputs ("read fd="); eputs (itoa ((int)filedes));
62 eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n");
69 _open3 (char const *file_name, int flags, int mask)
78 int r = _sys_call3 (SYS_open, (long)file_name, (int)flags, (int)mask);
83 _open2 (char const *file_name, int flags)
86 return _open3 (file_name, flags, mask);
90 open (char const *file_name, int flags, ...)
94 int mask = va_arg (ap, int);
95 int r = _open3 (file_name, flags, mask);
101 waitpid (pid_t pid, int *status_ptr, int options)
104 return _sys_call3 (SYS_waitpid, (long)pid, (long)status_ptr, (int)options);
106 return _sys_call4 (SYS_wait4, (long)pid, (long)status_ptr, (int)options, 0);
108 #error arch not supported
113 execve (char const* file_name, char *const argv[], char *const env[])
115 return _sys_call3 (SYS_execve, (long)file_name, (long)argv, (long)env);
119 chmod (char const *file_name, mode_t mask)
121 return _sys_call2 (SYS_chmod, (long)file_name, (long)mask);
125 access (char const *file_name, int how)
127 return _sys_call2 (SYS_access, (long)file_name, (int)how);
133 return _sys_call1 (SYS_brk, (long)addr);
137 ioctl (int filedes, unsigned long command, ...)
140 va_start (ap, command);
141 int data = va_arg (ap, int);
142 int r = _sys_call3 (SYS_ioctl, (int)filedes, (long)command, (int)data);
150 return _sys_call1 (SYS_fsync, (int)filedes);
154 getcwd (char *buffer, size_t size)
156 int r = _sys_call2 (SYS_getcwd, (long)buffer, (long)size);
165 return _sys_call1 (SYS_dup, (int)old);
169 dup2 (int old, int new)
171 return _sys_call2 (SYS_dup2, (int)old, (int)new);
174 #include "linux/clock_gettime.c"
175 #include "linux/gettimeofday.c"
176 #include "linux/time.c"