From fca14d27ad191ffc40bef1116f152a4020e5a8b4 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 29 Dec 2020 18:41:45 +0100 Subject: [PATCH] Mes C Library: m2/ioctl.c: Remove specialization. * lib/stub/ioctl.c (ioctl3): Move to... * lib/stub/ioctl3.c: ...new file. * lib/m2/ioctl3.c: Move to... * lib/linux/ioctl3.c: ...here. * include/mes/lib.h (ioctl3): Declare it. * lib/m2/isatty.c (isatty): Use it. * build-aux/configure-lib.sh (libc_SOURCES): Include it; move lib/linux/ioctl.c to ... (libc_gnu_SOURCES): ... here. * kaem.run: Update accordingly. * simple.make (M2_SOURCES): Likewise. * simple.sh (compiler): Likewise. --- build-aux/configure-lib.sh | 5 +++-- include/mes/lib.h | 3 ++- kaem.run | 2 +- lib/linux/ioctl.c | 9 +------- lib/{m2/ioctl.c => linux/ioctl3.c} | 13 +++++------- lib/m2/isatty.c | 2 +- lib/stub/ioctl.c | 13 +----------- lib/stub/ioctl3.c | 33 ++++++++++++++++++++++++++++++ simple.make | 2 +- simple.sh | 2 +- 10 files changed, 49 insertions(+), 35 deletions(-) rename lib/{m2/ioctl.c => linux/ioctl3.c} (71%) create mode 100644 lib/stub/ioctl3.c diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index b58afc3c..2e561d02 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -188,7 +188,7 @@ lib/stub/execve.c lib/stub/fork.c lib/stub/_getcwd.c lib/stub/gettimeofday.c -lib/stub/ioctl.c +lib/stub/ioctl3.c lib/stub/time.c lib/stub/unlink.c lib/stub/waitpid.c @@ -208,7 +208,7 @@ lib/linux/fork.c lib/linux/fsync.c lib/linux/_getcwd.c lib/linux/gettimeofday.c -lib/linux/ioctl.c +lib/linux/ioctl3.c lib/linux/_open3.c lib/linux/malloc.c lib/linux/_read.c @@ -413,6 +413,7 @@ lib/linux/getgid.c lib/linux/getppid.c lib/linux/getrusage.c lib/linux/getuid.c +lib/linux/ioctl.c lib/linux/link.c lib/linux/lstat.c lib/linux/mkdir.c diff --git a/include/mes/lib.h b/include/mes/lib.h index 6074d0c9..3504207f 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -49,7 +49,8 @@ char * fdgets (char *s, int count, int fd); int fdputc (int c, int fd); int fdputs (char const *s, int fd); int fdungetc (int c, int fd); -char * _getcwd (char *buffer, size_t size); +char *_getcwd (char *buffer, size_t size); +int ioctl3 (int filedes, size_t command, long data); int isnumber (int c, int base); int mes_open (char const *file_name, int flags, int mask); int _open2 (char const *file_name, int flags); diff --git a/kaem.run b/kaem.run index 7451c922..61a09bb0 100644 --- a/kaem.run +++ b/kaem.run @@ -80,7 +80,7 @@ M2-Planet \ -f lib/posix/setenv.c \ -f lib/linux/access.c \ -f lib/m2/chmod.c \ - -f lib/m2/ioctl.c \ + -f lib/linux/ioctl3.c \ -f lib/m2/isatty.c \ -f lib/linux/fork.c \ -f lib/m2/execve.c \ diff --git a/lib/linux/ioctl.c b/lib/linux/ioctl.c index 7df28a0b..0e6e14ac 100644 --- a/lib/linux/ioctl.c +++ b/lib/linux/ioctl.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -33,10 +33,3 @@ ioctl (int filedes, unsigned long command, ...) va_end (ap); return r; } - -int -ioctl3 (int filedes, unsigned long command, long data) -{ - int r = _sys_call3 (SYS_ioctl, filedes, command, data); - return r; -} diff --git a/lib/m2/ioctl.c b/lib/linux/ioctl3.c similarity index 71% rename from lib/m2/ioctl.c rename to lib/linux/ioctl3.c index 35654531..3f759d06 100644 --- a/lib/m2/ioctl.c +++ b/lib/linux/ioctl3.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -20,15 +20,12 @@ #include #include -#include -#include +#include int -ioctl (int filedes, long command, int data) +ioctl3 (int filedes, size_t command, long data) { - long long_filedes = filedes; - long long_command = command; - long long_data = data; - int r = _sys_call3 (SYS_ioctl, long_filedes, long_command, long_data); + long long_filedes = cast_int_to_long (filedes); + int r = _sys_call3 (SYS_ioctl, long_filedes, command, data); return r; } diff --git a/lib/m2/isatty.c b/lib/m2/isatty.c index babde375..fbe50ead 100644 --- a/lib/m2/isatty.c +++ b/lib/m2/isatty.c @@ -46,6 +46,6 @@ isatty (int filedes) { if (__isatty_kernel_termios == 0) __isatty_kernel_termios = malloc (sizeof (struct ktermios)); - int r = ioctl (filedes, TCGETS, __isatty_kernel_termios); + int r = ioctl3 (filedes, TCGETS, __isatty_kernel_termios); return r == 0; } diff --git a/lib/stub/ioctl.c b/lib/stub/ioctl.c index 1d6e63b7..91673566 100644 --- a/lib/stub/ioctl.c +++ b/lib/stub/ioctl.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -32,14 +32,3 @@ ioctl (int filedes, unsigned long command, ...) errno = 0; return 0; } - -int -ioctl3 (int filedes, unsigned long command, long data) -{ - static int stub = 0; - if (__mes_debug () && !stub) - eputs ("ioctl3 stub\n"); - stub = 1; - errno = 0; - return 0; -} diff --git a/lib/stub/ioctl3.c b/lib/stub/ioctl3.c new file mode 100644 index 00000000..a7778cdf --- /dev/null +++ b/lib/stub/ioctl3.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019,2020 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 + +int +ioctl3 (int filedes, unsigned long command, long data) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("ioctl3 stub\n"); + stub = 1; + errno = 0; + return 0; +} diff --git a/simple.make b/simple.make index f26c7df8..b40dd0ce 100644 --- a/simple.make +++ b/simple.make @@ -119,7 +119,7 @@ M2_SOURCES = \ lib/posix/setenv.c \ lib/linux/access.c \ lib/m2/chmod.c \ - lib/m2/ioctl.c \ + lib/linux/ioctl3.c \ lib/m2/isatty.c \ lib/linux/fork.c \ lib/m2/execve.c \ diff --git a/simple.sh b/simple.sh index cd1c0fd0..95ee4d11 100755 --- a/simple.sh +++ b/simple.sh @@ -247,7 +247,7 @@ $CC -g -D HAVE_CONFIG_H=1 -I include -I include/$mes_kernel/$mes_cpu\ lib/linux/fsync.c\ lib/linux/_getcwd.c\ lib/linux/gettimeofday.c\ - lib/linux/ioctl.c\ + lib/linux/ioctl3.c\ lib/linux/_open3.c\ lib/linux/read.c\ lib/linux/_read.c\