mescc: Mes C Library: Explode linux/libc.c.

* lib/linux/access.c: New file.
* lib/linux/brk.c: New file.
* lib/linux/chmod.c: New file.
* lib/linux/dup.c: New file.
* lib/linux/dup2.c: New file.
* lib/linux/execve.c: New file.
* lib/linux/fork.c: New file.
* lib/linux/fsync.c: New file.
* lib/linux/getcwd.c: New file.
* lib/linux/ioctl.c: New file.
* lib/linux/libc.c: New file.
* lib/linux/open.c: New file.
* lib/linux/read.c: New file.
* lib/linux/unlink.c: New file.
* lib/linux/waitpid.c: New file.
* lib/linux/libc.c: Include them.
(access, brk, chmod, dup, dup2, execve, fork, fsync, getcwd, ioctl,
libc, open, read, unlink, waitpid): Remove.
This commit is contained in:
Jan Nieuwenhuizen 2019-05-13 00:09:50 +02:00
parent 3a12301a25
commit ad46264879
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
15 changed files with 426 additions and 146 deletions

25
lib/linux/access.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
access (char const *file_name, int how)
{
return _sys_call2 (SYS_access, (long)file_name, (int)how);
}

25
lib/linux/brk.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
long
brk (void *addr)
{
return _sys_call1 (SYS_brk, (long)addr);
}

25
lib/linux/chmod.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
chmod (char const *file_name, mode_t mask)
{
return _sys_call2 (SYS_chmod, (long)file_name, (long)mask);
}

25
lib/linux/dup.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
dup (int old)
{
return _sys_call1 (SYS_dup, (int)old);
}

25
lib/linux/dup2.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
dup2 (int old, int new)
{
return _sys_call2 (SYS_dup2, (int)old, (int)new);
}

25
lib/linux/execve.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
execve (char const* file_name, char *const argv[], char *const env[])
{
return _sys_call3 (SYS_execve, (long)file_name, (long)argv, (long)env);
}

25
lib/linux/fork.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
fork ()
{
return _sys_call (SYS_fork);
}

25
lib/linux/fsync.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
fsync (int filedes)
{
return _sys_call1 (SYS_fsync, (int)filedes);
}

37
lib/linux/getcwd.c Normal file
View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
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);
}

30
lib/linux/ioctl.c Normal file
View File

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
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;
}

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <linux/access.c>
#include <linux/brk.c>
#include <linux/chmod.c>
#include <linux/clock_gettime.c>
#include <linux/dup.c>
#include <linux/dup2.c>
#include <linux/execve.c>
#include <linux/fork.c>
#include <linux/fsync.c>
#include <linux/getcwd.c>
#include <linux/gettimeofday.c>
#include <linux/ioctl.c>
#include <linux/open.c>
#include <linux/read.c>
#include <linux/time.c>
#include <linux/unlink.c>
#include <linux/waitpid.c>

47
lib/linux/open.c Normal file
View File

@ -0,0 +1,47 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
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;
}

38
lib/linux/read.c Normal file
View File

@ -0,0 +1,38 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
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;
}

25
lib/linux/unlink.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
int
unlink (char const *file_name)
{
return _sys_call1 (SYS_unlink, (long)file_name);
}

31
lib/linux/waitpid.c Normal file
View File

@ -0,0 +1,31 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 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/>.
*/
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
}