summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-11-12 15:36:49 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-11-12 15:36:49 +0000
commitf06e5a86b194219cf631cb10a09ba5046362bf7d (patch)
treebcdaf05e5094844ec8f4c4aa0ab96cc212bd9bc7 /cpukit
parent2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-f06e5a86b194219cf631cb10a09ba5046362bf7d.tar.bz2
2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/Makefile.am: Add getrusage(). * libcsupport/src/getrusage.c: New file.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/ChangeLog5
-rw-r--r--cpukit/libcsupport/Makefile.am2
-rw-r--r--cpukit/libcsupport/src/getrusage.c51
3 files changed, 57 insertions, 1 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 0ccea9d589..c21156e99c 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,5 +1,10 @@
2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+ * libcsupport/Makefile.am: Add getrusage().
+ * libcsupport/src/getrusage.c: New file.
+
+2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
* score/src/timespecaddto.c: Fix typo.
2008-11-07 Joel Sherrill <joel.sherrill@oarcorp.com>
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index f1361cfefe..d2d4621e10 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -110,7 +110,7 @@ else
libcsupport_a_SOURCES += $(LIBC_GLUE_C_FILES) $(PASSWORD_GROUP_C_FILES) \
$(TERMINAL_IDENTIFICATION_C_FILES) $(SYSTEM_CALL_C_FILES) \
$(DIRECTORY_SCAN_C_FILES) $(ID_C_FILES) src/envlock.c \
- $(TERMIOS_C_FILES) src/getpagesize.c
+ $(TERMIOS_C_FILES) src/getpagesize.c src/getrusage.c
endif
EXTRA_DIST = src/TODO src/CASES src/README src/malloc_p.h
diff --git a/cpukit/libcsupport/src/getrusage.c b/cpukit/libcsupport/src/getrusage.c
new file mode 100644
index 0000000000..3e57139e99
--- /dev/null
+++ b/cpukit/libcsupport/src/getrusage.c
@@ -0,0 +1,51 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/resource.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/seterr.h>
+
+int getrusage(int who, struct rusage *usage)
+{
+ struct timespec uptime;
+ struct timeval rtime;
+
+ if ( !usage )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ /*
+ * RTEMS only has a single process so there are no children.
+ * The single process has been running since the system
+ * was booted and since there is no distinction between system
+ * and user time, we will just report the uptime.
+ */
+ if (who == RUSAGE_SELF) {
+ rtems_clock_get_uptime( &uptime );
+
+ rtime.tv_sec = uptime.tv_sec;
+ rtime.tv_usec = uptime.tv_nsec / 1000;
+
+ usage->ru_utime = rtime;
+ usage->ru_stime = rtime;
+
+ return 0;
+ } else if (who == RUSAGE_CHILDREN) {
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+ }
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
+