From 07a9e7aac7fddfffa1b057ec2bd68fcb7476489d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 3 Jan 2019 00:07:19 +0100 Subject: [PATCH] mescc: Mes C Library: Support GNU Tar: Add readlink, readlink. * lib/linux/gnu.c (readlink, symlink): New function. * include/unistd.h (readlink, symlink): Declare. * include/linux/x86/syscall.h (SYS_readlink, SYS_symlink): New macro. * include/linux/x86_64/syscall.h (SYS_symlink, SYS_readlink): New macro. --- build-aux/configure-lib.sh | 2 ++ include/linux/x86/syscall.h | 4 ++++ include/linux/x86_64/syscall.h | 4 ++++ include/unistd.h | 4 +++- lib/linux/readlink.c | 29 +++++++++++++++++++++++++++++ lib/linux/symlink.c | 29 +++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 lib/linux/readlink.c create mode 100644 lib/linux/symlink.c diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index b821b29e..2bfc0570 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -306,12 +306,14 @@ lib/linux/lstat.c lib/linux/mkdir.c lib/linux/nanosleep.c lib/linux/pipe.c +lib/linux/readlink.c lib/linux/rename.c lib/linux/setgid.c lib/linux/settimer.c lib/linux/setuid.c lib/linux/signal.c lib/linux/sigprogmask.c +lib/linux/symlink.c " fi diff --git a/include/linux/x86/syscall.h b/include/linux/x86/syscall.h index eb776be0..620a8b7d 100644 --- a/include/linux/x86/syscall.h +++ b/include/linux/x86/syscall.h @@ -83,4 +83,8 @@ // make+POSIX #define SYS_sigprocmask 0x7e +// tar +#define SYS_symlink 0x53 +#define SYS_readlink 0x55 + #endif // __MES_LINUX_X86_SYSCALL_H diff --git a/include/linux/x86_64/syscall.h b/include/linux/x86_64/syscall.h index 5cd8477d..10c3f31b 100644 --- a/include/linux/x86_64/syscall.h +++ b/include/linux/x86_64/syscall.h @@ -80,4 +80,8 @@ // make+SYSTEM_LIBC #define SYS_rt_sigprocmask 0x0e +// tar +#define SYS_symlink 0x58 +#define SYS_readlink 0x59 + #endif // __MES_LINUX_X86_64_SYSCALL_H diff --git a/include/unistd.h b/include/unistd.h index 53c68561..52820b15 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -77,15 +77,17 @@ gid_t getegid (void); pid_t getpid (void); pid_t getppid (void); int isatty (int fd); -int link (char const *oldname, char const *newname); +int link (char const *old_name, char const *new_name); off_t lseek (int fd, off_t offset, int whence); ssize_t read (int fd, void *buffer, size_t size); +ssize_t readlink (char const *file_name, char *buffer, size_t size); #if __SBRK_CHAR_PTRDIFF /* xmalloc in binutils <= 2.10.1 uses this old prototype */ char *sbrk (ptrdiff_t delta); #else void *sbrk (intptr_t delta); #endif +int symlink (char const *old_name, char const *new_name); int unlink (char const *file_name); ssize_t write (int filedes, void const *buffer, size_t size); pid_t getpid (void); diff --git a/lib/linux/readlink.c b/lib/linux/readlink.c new file mode 100644 index 00000000..9990b50f --- /dev/null +++ b/lib/linux/readlink.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 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 + +ssize_t +readlink (char const *file_name, char *buffer, size_t size) +{ + return _sys_call3 (SYS_readlink, (long) file_name, (long) buffer, (long) size); +} diff --git a/lib/linux/symlink.c b/lib/linux/symlink.c new file mode 100644 index 00000000..53f99fb7 --- /dev/null +++ b/lib/linux/symlink.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 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 + +int +symlink (char const *old_name, char const *new_name) +{ + return _sys_call2 (SYS_symlink, (long) old_name, (long) new_name); +}