From b562179c9c9da53cef731ec561045807452baa4d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 25 Jun 2019 01:58:15 +0200 Subject: [PATCH] mescc: Mes C Library: Move posix bits to read. * lib/linux/_read.c: Rename from read. * lib/posix/read.c: New file. * build-aux/build-lib.sh (libc_SOURCES): Update. * include/mes/lib.h (_read): Declare. --- build-aux/build-lib.sh | 3 ++- include/mes/lib.h | 1 + lib/linux/_read.c | 30 ++++++++++++++++++++++++++ lib/posix/read.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 lib/linux/_read.c create mode 100644 lib/posix/read.c diff --git a/build-aux/build-lib.sh b/build-aux/build-lib.sh index bf498547..22caf6e9 100755 --- a/build-aux/build-lib.sh +++ b/build-aux/build-lib.sh @@ -88,6 +88,7 @@ lib/mes/__mes_debug.c lib/posix/execv.c lib/posix/getenv.c lib/posix/isatty.c +lib/posix/read.c lib/posix/setenv.c lib/posix/wait.c lib/stdio/fgetc.c @@ -125,7 +126,7 @@ lib/linux/getcwd.c lib/linux/gettimeofday.c lib/linux/ioctl.c lib/linux/open.c -lib/linux/read.c +lib/linux/_read.c lib/linux/time.c lib/linux/unlink.c lib/linux/waitpid.c diff --git a/include/mes/lib.h b/include/mes/lib.h index 4af3da00..7145dab1 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -48,6 +48,7 @@ int _open3 (char const *file_name, int flags, int mask); int oputc (int c); int oputs (char const *s); char *search_path (char const *file_name); +ssize_t _read (int fd, void *buffer, size_t size); extern char *__brk; extern void (*__call_at_exit) (void); diff --git a/lib/linux/_read.c b/lib/linux/_read.c new file mode 100644 index 00000000..6c5ff42f --- /dev/null +++ b/lib/linux/_read.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 . + */ + +#include +#include +#include +#include + +ssize_t +_read (int filedes, void *buffer, size_t size) +{ + return _sys_call3 (SYS_read, (int) filedes, (long) buffer, (long) size); +} diff --git a/lib/posix/read.c b/lib/posix/read.c new file mode 100644 index 00000000..5fbda534 --- /dev/null +++ b/lib/posix/read.c @@ -0,0 +1,48 @@ +/* -*-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 . + */ + +#include +#include + +ssize_t +read (int filedes, void *buffer, size_t size) +{ + ssize_t bytes = _read (filedes, buffer, size); + if (__mes_debug () > 4) + { + 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; +}