diff --git a/lib/linux/access.c b/lib/linux/access.c new file mode 100644 index 00000000..22907808 --- /dev/null +++ b/lib/linux/access.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +access (char const *file_name, int how) +{ + return _sys_call2 (SYS_access, (long)file_name, (int)how); +} diff --git a/lib/linux/brk.c b/lib/linux/brk.c new file mode 100644 index 00000000..e727e73e --- /dev/null +++ b/lib/linux/brk.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +long +brk (void *addr) +{ + return _sys_call1 (SYS_brk, (long)addr); +} diff --git a/lib/linux/chmod.c b/lib/linux/chmod.c new file mode 100644 index 00000000..a2380f78 --- /dev/null +++ b/lib/linux/chmod.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +chmod (char const *file_name, mode_t mask) +{ + return _sys_call2 (SYS_chmod, (long)file_name, (long)mask); +} diff --git a/lib/linux/dup.c b/lib/linux/dup.c new file mode 100644 index 00000000..f7c8c512 --- /dev/null +++ b/lib/linux/dup.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +dup (int old) +{ + return _sys_call1 (SYS_dup, (int)old); +} diff --git a/lib/linux/dup2.c b/lib/linux/dup2.c new file mode 100644 index 00000000..36cf5460 --- /dev/null +++ b/lib/linux/dup2.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +dup2 (int old, int new) +{ + return _sys_call2 (SYS_dup2, (int)old, (int)new); +} diff --git a/lib/linux/execve.c b/lib/linux/execve.c new file mode 100644 index 00000000..fe747322 --- /dev/null +++ b/lib/linux/execve.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +execve (char const* file_name, char *const argv[], char *const env[]) +{ + return _sys_call3 (SYS_execve, (long)file_name, (long)argv, (long)env); +} diff --git a/lib/linux/fork.c b/lib/linux/fork.c new file mode 100644 index 00000000..d87560a5 --- /dev/null +++ b/lib/linux/fork.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +fork () +{ + return _sys_call (SYS_fork); +} diff --git a/lib/linux/fsync.c b/lib/linux/fsync.c new file mode 100644 index 00000000..afe12693 --- /dev/null +++ b/lib/linux/fsync.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +fsync (int filedes) +{ + return _sys_call1 (SYS_fsync, (int)filedes); +} diff --git a/lib/linux/getcwd.c b/lib/linux/getcwd.c new file mode 100644 index 00000000..91ded19e --- /dev/null +++ b/lib/linux/getcwd.c @@ -0,0 +1,37 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +char * +_getcwd (char *buffer, size_t size) +{ + int r = _sys_call2 (SYS_getcwd, (long)buffer, (long)size); + if (r >= 0) + return buffer; + return 0; +} + +char * +getcwd (char *buffer, size_t size) +{ + static char buf[PATH_MAX]; + if (buffer) + return _getcwd (buffer, size); + return _getcwd (buf, PATH_MAX); +} diff --git a/lib/linux/ioctl.c b/lib/linux/ioctl.c new file mode 100644 index 00000000..9c9dfede --- /dev/null +++ b/lib/linux/ioctl.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +ioctl (int filedes, unsigned long command, ...) +{ + va_list ap; + va_start (ap, command); + int data = va_arg (ap, int); + int r = _sys_call3 (SYS_ioctl, (int)filedes, (long)command, (int)data); + va_end (ap); + return r; +} diff --git a/lib/linux/libc.c b/lib/linux/libc.c index b08db6ba..8f7c6ee5 100644 --- a/lib/linux/libc.c +++ b/lib/linux/libc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -41,148 +41,20 @@ #error arch not supported #endif -int -fork () -{ - return _sys_call (SYS_fork); -} - -ssize_t -read (int filedes, void *buffer, size_t size) -{ - ssize_t bytes = _sys_call3 (SYS_read, (int)filedes, (long)buffer, (long)size); - if (__mes_debug () > 3) - { - if (bytes == 1) - { - eputs ("read fd="); eputs (itoa ((int)filedes)); eputs (" c="); eputc (*(char*)buffer); eputs ("\n"); - } - else - { - eputs ("read fd="); eputs (itoa ((int)filedes)); - eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); - } - } - return bytes; -} - -int -_open3 (char const *file_name, int flags, int mask) -{ - int r = _sys_call3 (SYS_open, (long)file_name, (int)flags, (int)mask); - __ungetc_init (); - if (r > 2) - __ungetc_buf[r] = -1; - return r; -} - -int -_open2 (char const *file_name, int flags) -{ - int mask = 0777; - return _open3 (file_name, flags, mask); -} - -int -open (char const *file_name, int flags, ...) -{ - va_list ap; - va_start (ap, flags); - int mask = va_arg (ap, int); - int r = _open3 (file_name, flags, mask); - va_end (ap); - return r; -} - -pid_t -waitpid (pid_t pid, int *status_ptr, int options) -{ -#if __i386__ - return _sys_call3 (SYS_waitpid, (long)pid, (long)status_ptr, (int)options); -#elif __x86_64__ - return _sys_call4 (SYS_wait4, (long)pid, (long)status_ptr, (int)options, 0); -#else -#error arch not supported -#endif -} - -int -execve (char const* file_name, char *const argv[], char *const env[]) -{ - return _sys_call3 (SYS_execve, (long)file_name, (long)argv, (long)env); -} - -int -chmod (char const *file_name, mode_t mask) -{ - return _sys_call2 (SYS_chmod, (long)file_name, (long)mask); -} - -int -access (char const *file_name, int how) -{ - return _sys_call2 (SYS_access, (long)file_name, (int)how); -} - -long -brk (void *addr) -{ - return _sys_call1 (SYS_brk, (long)addr); -} - -int -ioctl (int filedes, unsigned long command, ...) -{ - va_list ap; - va_start (ap, command); - int data = va_arg (ap, int); - int r = _sys_call3 (SYS_ioctl, (int)filedes, (long)command, (int)data); - va_end (ap); - return r; -} - -int -fsync (int filedes) -{ - return _sys_call1 (SYS_fsync, (int)filedes); -} - -char * -_getcwd (char *buffer, size_t size) -{ - int r = _sys_call2 (SYS_getcwd, (long)buffer, (long)size); - if (r >= 0) - return buffer; - return 0; -} - -char * -getcwd (char *buffer, size_t size) -{ - static char buf[PATH_MAX]; - if (buffer) - return _getcwd (buffer, size); - return _getcwd (buf, PATH_MAX); -} - -int -dup (int old) -{ - return _sys_call1 (SYS_dup, (int)old); -} - -int -dup2 (int old, int new) -{ - return _sys_call2 (SYS_dup2, (int)old, (int)new); -} - -int -unlink (char const *file_name) -{ - return _sys_call1 (SYS_unlink, (long)file_name); -} - -#include "linux/clock_gettime.c" -#include "linux/gettimeofday.c" -#include "linux/time.c" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/lib/linux/open.c b/lib/linux/open.c new file mode 100644 index 00000000..5eca8c35 --- /dev/null +++ b/lib/linux/open.c @@ -0,0 +1,47 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +_open3 (char const *file_name, int flags, int mask) +{ + int r = _sys_call3 (SYS_open, (long)file_name, (int)flags, (int)mask); + __ungetc_init (); + if (r > 2) + __ungetc_buf[r] = -1; + return r; +} + +int +_open2 (char const *file_name, int flags) +{ + int mask = 0777; + return _open3 (file_name, flags, mask); +} + +int +open (char const *file_name, int flags, ...) +{ + va_list ap; + va_start (ap, flags); + int mask = va_arg (ap, int); + int r = _open3 (file_name, flags, mask); + va_end (ap); + return r; +} diff --git a/lib/linux/read.c b/lib/linux/read.c new file mode 100644 index 00000000..8547a6ca --- /dev/null +++ b/lib/linux/read.c @@ -0,0 +1,38 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +ssize_t +read (int filedes, void *buffer, size_t size) +{ + ssize_t bytes = _sys_call3 (SYS_read, (int)filedes, (long)buffer, (long)size); + if (__mes_debug () > 3) + { + if (bytes == 1) + { + eputs ("read fd="); eputs (itoa ((int)filedes)); eputs (" c="); eputc (*(char*)buffer); eputs ("\n"); + } + else + { + eputs ("read fd="); eputs (itoa ((int)filedes)); + eputs (" bytes="); eputs (itoa (bytes)); eputs ("\n"); + } + } + return bytes; +} diff --git a/lib/linux/unlink.c b/lib/linux/unlink.c new file mode 100644 index 00000000..989c198a --- /dev/null +++ b/lib/linux/unlink.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +unlink (char const *file_name) +{ + return _sys_call1 (SYS_unlink, (long)file_name); +} diff --git a/lib/linux/waitpid.c b/lib/linux/waitpid.c new file mode 100644 index 00000000..048a5ac8 --- /dev/null +++ b/lib/linux/waitpid.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +pid_t +waitpid (pid_t pid, int *status_ptr, int options) +{ +#if __i386__ + return _sys_call3 (SYS_waitpid, (long)pid, (long)status_ptr, (int)options); +#elif __x86_64__ + return _sys_call4 (SYS_wait4, (long)pid, (long)status_ptr, (int)options, 0); +#else +#error arch not supported +#endif +}