From 8b9d51e4a418fca8ece711aa5e26fa6cbe7913af Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 26 Aug 2018 22:41:52 +0200 Subject: [PATCH] mescc: Mes C Library: Support make: Add chdir, getlogin, setvbuf, sigblock. * lib/stub/getlogin.c: New file. * lib/stub/setvbuf.c: New file. * lib/stub/sigblock.c: New file. * lib/libc+gnu.c: Include them. * include/linux/x86/syscall.h (SYS_chdir): New macro. * include/linux/x86_64/syscall.h (SYS_chdir): New macro. * include/stdio.h (_IOFBF, _IOLBF, _IONBF): New macro. * include/errno.h (ENOEXEC, ECHILD): New macro. * include/sys/wait.h (WNOHANG): New macro. * lib/linux/gnu.c (chdir): New function. * include/ar.h: New file. --- include/ar.h | 56 ++++++++++++++++++++++++++++++++++ include/errno.h | 4 ++- include/linux/x86/syscall.h | 1 + include/linux/x86_64/syscall.h | 1 + include/stdio.h | 8 +++++ include/string.h | 1 - include/sys/wait.h | 2 ++ lib/libc+gnu.c | 6 ++++ lib/linux/gnu.c | 6 ++++ lib/stub/getlogin.c | 33 ++++++++++++++++++++ lib/stub/setvbuf.c | 32 +++++++++++++++++++ lib/stub/sigblock.c | 28 +++++++++++++++++ 12 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 include/ar.h create mode 100644 lib/stub/getlogin.c create mode 100644 lib/stub/setvbuf.c create mode 100644 lib/stub/sigblock.c diff --git a/include/ar.h b/include/ar.h new file mode 100644 index 00000000..bcefb3d0 --- /dev/null +++ b/include/ar.h @@ -0,0 +1,56 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright (C) 1996 Free Software Foundation, Inc. + * Copyright © 2018 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 . + */ +#ifndef __MES_AR_H +#define __MES_AR_H 1 + +#if WITH_GLIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_AR_H +#include_next + +#else // ! WITH_GLIBC + +// Taken from GNU C Library 2.2.5 + +/* Archive files start with the ARMAG identifying string. Then follows a + `struct ar_hdr', and as many bytes of member file data as its `ar_size' + member indicates, for each member file. */ + +#define ARMAG "!\n" /* String that begins an archive file. */ +#define SARMAG 8 /* Size of that string. */ + +#define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ + +struct ar_hdr + { + char ar_name[16]; /* Member file name, sometimes / terminated. */ + char ar_date[12]; /* File date, decimal seconds since Epoch. */ + char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ + char ar_mode[8]; /* File mode, in ASCII octal. */ + char ar_size[10]; /* File size, in ASCII decimal. */ + char ar_fmag[2]; /* Always contains ARFMAG. */ + }; + +#endif // ! WITH_GLIBC + +#endif // __MES_ARGZ_H diff --git a/include/errno.h b/include/errno.h index c1453785..fe3c78c2 100644 --- a/include/errno.h +++ b/include/errno.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -39,7 +39,9 @@ int errno; #define EINTR 4 #define EIO 5 #define E2BIG 7 +#define ENOEXEC 8 #define EBADF 9 +#define ECHILD 10 #define EAGAIN 11 #define ENOMEM 12 #define EEXIST 17 diff --git a/include/linux/x86/syscall.h b/include/linux/x86/syscall.h index e9fc52dc..fb4cd9cf 100644 --- a/include/linux/x86/syscall.h +++ b/include/linux/x86/syscall.h @@ -46,6 +46,7 @@ #define SYS_getcwd 0xb7 // libc+gnu +#define SYS_chdir 0x0c #define SYS_link 0x09 #define SYS_getpid 0x14 #define SYS_getuid 0x18 diff --git a/include/linux/x86_64/syscall.h b/include/linux/x86_64/syscall.h index be5f23a9..11021826 100644 --- a/include/linux/x86_64/syscall.h +++ b/include/linux/x86_64/syscall.h @@ -46,6 +46,7 @@ #define SYS_getcwd 0x4f // libc+gnu +#define SYS_chdir 0x50 #define SYS_link 0x56 #define SYS_getpid 0x27 #define SYS_getuid 0x66 diff --git a/include/stdio.h b/include/stdio.h index 10001845..36b33672 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -45,6 +45,12 @@ int g_stdout; #else // ! WITH_GLIBC +#ifndef _IOFBF +#define _IOFBF 0 /* Fully buffered. */ +#define _IOLBF 1 /* Line buffered. */ +#define _IONBF 2 /* No buffering. */ +#endif + #ifndef BUFSIZ #define BUFSIZ 256 #endif @@ -80,11 +86,13 @@ int fputs (char const* s, FILE *stream); int fseek (FILE *stream, long offset, int whence); int getc (FILE *stream); int getchar (void); +char *getlogin (void); int printf (char const* format, ...); int putc (int c, FILE* stream); int putchar (int c); int puts (char const* s); int remove (char const *file_name); +int setvbuf (FILE *stream, char *buf, int mode, size_t size); int snprintf(char *str, size_t size, char const *format, ...); int sprintf (char *str, char const* format, ...); int sscanf (char const *str, const char *format, ...); diff --git a/include/string.h b/include/string.h index bf34011d..450c6235 100644 --- a/include/string.h +++ b/include/string.h @@ -58,7 +58,6 @@ int strcmp (char const*, char const*); char *strcpy (char *dest, char const *src); size_t strlen (char const*); char *strncpy (char *to, char const *from, size_t size); -int strncasecmp (char const *s1, char const *s2, size_t size); int strncmp (char const*, char const*, size_t); char *strrchr (char const *s, int c); char *strstr (char const *haystack, char const *needle); diff --git a/include/sys/wait.h b/include/sys/wait.h index b809ca77..73f7035a 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -30,6 +30,8 @@ typedef int pid_t; #endif +#define WNOHANG 1 + pid_t waitpid (pid_t pid, int *status_ptr, int options); pid_t wait (int *status_ptr); diff --git a/lib/libc+gnu.c b/lib/libc+gnu.c index 2d280bb5..9fb90018 100644 --- a/lib/libc+gnu.c +++ b/lib/libc+gnu.c @@ -104,4 +104,10 @@ #include #include +// diffutils #include + +// make +#include +#include +#include diff --git a/lib/linux/gnu.c b/lib/linux/gnu.c index 5fc30f96..16237c50 100644 --- a/lib/linux/gnu.c +++ b/lib/linux/gnu.c @@ -20,6 +20,12 @@ #include +int +chdir (char const *file_name) +{ + return _sys_call1 (SYS_chdir, (long)file_name); +} + int link (char const *old_name, char const *new_name) { diff --git a/lib/stub/getlogin.c b/lib/stub/getlogin.c new file mode 100644 index 00000000..725929f7 --- /dev/null +++ b/lib/stub/getlogin.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 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 + +char * +getlogin (void) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("getlogin stub\n"); + stub = 1; + errno = 0; + return 0; +} diff --git a/lib/stub/setvbuf.c b/lib/stub/setvbuf.c new file mode 100644 index 00000000..1abe6639 --- /dev/null +++ b/lib/stub/setvbuf.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 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 +setvbuf (FILE *stream, char *buf, int mode, size_t size) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("setvbuf stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/sigblock.c b/lib/stub/sigblock.c new file mode 100644 index 00000000..766b1c87 --- /dev/null +++ b/lib/stub/sigblock.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 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 +sigblock (int mask) +{ + return 0; +}