From 93cb6375ae6e4cbd9fdef62719878b5cc260ef27 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 7 Jun 2018 08:02:32 +0200 Subject: [PATCH] mescc: Support gcc-3.0: Implement dup2, fcntl, getrusage. * include/sys/resource.h: New file. * lib/linux+gnu.c (fcntl, dup2, getrusage): New function. * lib/binutils.c (fcntl): Remove stub. --- include/fcntl.h | 4 +++ include/sys/resource.h | 56 ++++++++++++++++++++++++++++++++++++++++++ lib/binutils.c | 7 ------ lib/linux+gnu.c | 26 ++++++++++++++++++++ 4 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 include/sys/resource.h diff --git a/include/fcntl.h b/include/fcntl.h index deefe3e7..27666185 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -41,7 +41,11 @@ #define F_GETFL 3 #define F_SETFL 4 +int dup (int old); +int dup2 (int old, int new); +int fcntl (int filedes, int command, ...); int open (char const *s, int flags, ...); + #endif // ! WITH_GLIBC #endif // __MES_FCNTL_H diff --git a/include/sys/resource.h b/include/sys/resource.h new file mode 100644 index 00000000..29c359f3 --- /dev/null +++ b/include/sys/resource.h @@ -0,0 +1,56 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ +#ifndef __MES_SYS_RESOURCE_H +#define __MES_SYS_RESOURCE_H 1 + +#if WITH_GLIBC +#undef __MES_SYS_RESOURCE_H +#include_next + +#else // ! WITH_GLIBC + +struct rusage +{ + struct timeval ru_utime; + struct timeval ru_stime; + long int ru_maxrss; + long int ru_ixrss; + long int ru_idrss; + long int ru_isrss; + long int ru_minflt; + long int ru_majflt; + long int ru_nswap; + long int ru_inblock; + long int ru_oublock; + long int ru_msgsnd; + long int ru_msgrcv; + long int ru_nsignals; + long int ru_nvcsw; + long int ru_nivcsw; +}; + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 + +int getrusage (int processes, struct rusage *rusage); + +#endif // ! WITH_GLIBC + +#endif // __MES_SYS_RESOURCE_H diff --git a/lib/binutils.c b/lib/binutils.c index 909af6f6..77d49c95 100644 --- a/lib/binutils.c +++ b/lib/binutils.c @@ -44,13 +44,6 @@ ctime (int x) return 0; } -int -fcntl (int x) -{ - eputs ("fcntl stub\n"); - return 0; -} - char * fdgets (char *s, int count, int fd) { diff --git a/lib/linux+gnu.c b/lib/linux+gnu.c index ca2c293c..801b531f 100644 --- a/lib/linux+gnu.c +++ b/lib/linux+gnu.c @@ -28,6 +28,9 @@ #define SYS_pipe 0x2a #define SYS_getgid 0x2f #define SYS_signal 0x30 +#define SYS_fcntl 0x37 +#define SYS_dup2 0x3f +#define SYS_getrusage 0x4d #define SYS_lstat 0x6b #define SYS_fstat 0x6c #define SYS_nanosleep 0xa2 @@ -92,12 +95,35 @@ signal (int signum, sighandler_t action) return _sys_call2 (SYS_signal, signum, action); } +int +fcntl (int filedes, int command, ...) +{ + va_list ap; + va_start (ap, command); + int data = va_arg (ap, int); + int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data); + va_end (ap); + return r; +} + int pipe (int filedes[2]) { return _sys_call1 (SYS_pipe, (int)filedes); } +int +dup2 (int old, int new) +{ + return _sys_call2 (SYS_dup2, (int)old, (int)new); +} + +int +getrusage (int processes, struct rusage *rusage) +{ + return _sys_call2 (SYS_getrusage, (int)processes, (int)rusage); +} + int lstat (char const *file_name, struct stat *statbuf) {