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.
This commit is contained in:
Jan Nieuwenhuizen 2018-06-07 08:02:32 +02:00
parent b7c35dad69
commit 93cb6375ae
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
4 changed files with 86 additions and 7 deletions

View file

@ -41,7 +41,11 @@
#define F_GETFL 3 #define F_GETFL 3
#define F_SETFL 4 #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, ...); int open (char const *s, int flags, ...);
#endif // ! WITH_GLIBC #endif // ! WITH_GLIBC
#endif // __MES_FCNTL_H #endif // __MES_FCNTL_H

56
include/sys/resource.h Normal file
View file

@ -0,0 +1,56 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_SYS_RESOURCE_H
#define __MES_SYS_RESOURCE_H 1
#if WITH_GLIBC
#undef __MES_SYS_RESOURCE_H
#include_next <sys/resource.h>
#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

View file

@ -44,13 +44,6 @@ ctime (int x)
return 0; return 0;
} }
int
fcntl (int x)
{
eputs ("fcntl stub\n");
return 0;
}
char * char *
fdgets (char *s, int count, int fd) fdgets (char *s, int count, int fd)
{ {

View file

@ -28,6 +28,9 @@
#define SYS_pipe 0x2a #define SYS_pipe 0x2a
#define SYS_getgid 0x2f #define SYS_getgid 0x2f
#define SYS_signal 0x30 #define SYS_signal 0x30
#define SYS_fcntl 0x37
#define SYS_dup2 0x3f
#define SYS_getrusage 0x4d
#define SYS_lstat 0x6b #define SYS_lstat 0x6b
#define SYS_fstat 0x6c #define SYS_fstat 0x6c
#define SYS_nanosleep 0xa2 #define SYS_nanosleep 0xa2
@ -92,12 +95,35 @@ signal (int signum, sighandler_t action)
return _sys_call2 (SYS_signal, signum, 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 int
pipe (int filedes[2]) pipe (int filedes[2])
{ {
return _sys_call1 (SYS_pipe, (int)filedes); 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 int
lstat (char const *file_name, struct stat *statbuf) lstat (char const *file_name, struct stat *statbuf)
{ {