From 08c85f76069f050899141d2ec6ae8c6c42a1ae78 Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Sun, 3 Sep 2017 22:19:40 +0200 Subject: [PATCH] jehanne: add sys/resource.h and getrusage --- newlib/libc/sys/jehanne/Makefile.am | 4 +-- newlib/libc/sys/jehanne/Makefile.in | 12 ++++++-- newlib/libc/sys/jehanne/getrusage.c | 40 ++++++++++++++++++++++++++ newlib/libc/sys/jehanne/sys/resource.h | 17 +++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 newlib/libc/sys/jehanne/getrusage.c create mode 100644 newlib/libc/sys/jehanne/sys/resource.h diff --git a/newlib/libc/sys/jehanne/Makefile.am b/newlib/libc/sys/jehanne/Makefile.am index a357131ee..504c67d31 100644 --- a/newlib/libc/sys/jehanne/Makefile.am +++ b/newlib/libc/sys/jehanne/Makefile.am @@ -5,7 +5,7 @@ AM_CCASFLAGS = $(INCLUDES) noinst_LIBRARIES = lib.a if MAY_SUPPLY_SYSCALLS -extra_objs = syscalls.o libposix_conf.o chown.o +extra_objs = syscalls.o libposix_conf.o chown.o getrusage.o else extra_objs = endif @@ -14,7 +14,7 @@ lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \ calloc.c callocr.c realloc.c reallocr.c lib_a_LIBADD = $(extra_objs) -EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c +EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c lib_a_DEPENDENCIES = $(extra_objs) lib_a_CCASFLAGS = $(AM_CCASFLAGS) lib_a_CFLAGS = $(AM_CFLAGS) diff --git a/newlib/libc/sys/jehanne/Makefile.in b/newlib/libc/sys/jehanne/Makefile.in index 000d68c2c..eac06959f 100644 --- a/newlib/libc/sys/jehanne/Makefile.in +++ b/newlib/libc/sys/jehanne/Makefile.in @@ -52,7 +52,7 @@ LIBRARIES = $(noinst_LIBRARIES) ARFLAGS = cru lib_a_AR = $(AR) $(ARFLAGS) @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = syscalls.o \ -@MAY_SUPPLY_SYSCALLS_TRUE@ libposix_conf.o chown.o +@MAY_SUPPLY_SYSCALLS_TRUE@ libposix_conf.o chown.o getrusage.o am_lib_a_OBJECTS = lib_a-getenv_r.$(OBJEXT) lib_a-getenv.$(OBJEXT) \ lib_a-malloc.$(OBJEXT) lib_a-mallocr.$(OBJEXT) \ lib_a-free.$(OBJEXT) lib_a-freer.$(OBJEXT) \ @@ -177,12 +177,12 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) AM_CCASFLAGS = $(INCLUDES) noinst_LIBRARIES = lib.a @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = -@MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = syscalls.o libposix_conf.o chown.o +@MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = syscalls.o libposix_conf.o chown.o getrusage.o lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \ calloc.c callocr.c realloc.c reallocr.c lib_a_LIBADD = $(extra_objs) -EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c +EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c lib_a_DEPENDENCIES = $(extra_objs) lib_a_CCASFLAGS = $(AM_CCASFLAGS) lib_a_CFLAGS = $(AM_CFLAGS) @@ -328,6 +328,12 @@ lib_a-chown.o: chown.c lib_a-chown.obj: chown.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-chown.obj `if test -f 'chown.c'; then $(CYGPATH_W) 'chown.c'; else $(CYGPATH_W) '$(srcdir)/chown.c'; fi` +lib_a-getrusage.o: getrusage.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrusage.o `test -f 'getrusage.c' || echo '$(srcdir)/'`getrusage.c + +lib_a-getrusage.obj: getrusage.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getrusage.obj `if test -f 'getrusage.c'; then $(CYGPATH_W) 'getrusage.c'; else $(CYGPATH_W) '$(srcdir)/getrusage.c'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/newlib/libc/sys/jehanne/getrusage.c b/newlib/libc/sys/jehanne/getrusage.c new file mode 100644 index 000000000..b3e29747e --- /dev/null +++ b/newlib/libc/sys/jehanne/getrusage.c @@ -0,0 +1,40 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 Giacomo Tesio + * + * Jehanne 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, version 2 of the License. + * + * Jehanne 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 Jehanne. If not, see . + */ +#include +#include +#include +#include + +int +getrusage(int who, struct rusage *r_usage) +{ + PosixRUsages u; + int *errnop = &_REENT->_errno; + switch(who){ + case 0: + u = PosixRUsageSelf; + break; + case 1: + u = PosixRUsageChildren; + break; + default: + u = PosixRUsageUnknown; + break; + } + return POSIX_getrusage(errnop, u, r_usage); +} diff --git a/newlib/libc/sys/jehanne/sys/resource.h b/newlib/libc/sys/jehanne/sys/resource.h new file mode 100644 index 000000000..f20fae6d1 --- /dev/null +++ b/newlib/libc/sys/jehanne/sys/resource.h @@ -0,0 +1,17 @@ +#ifndef _SYS_RESOURCE_H_ +#define _SYS_RESOURCE_H_ + +#include + +#define RUSAGE_SELF 0 /* calling process */ +#define RUSAGE_CHILDREN 1 /* terminated child processes */ + +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ +}; + +extern int getrusage(int, struct rusage *); + +#endif +