diff --git a/include/sys/times.h b/include/sys/times.h new file mode 100644 index 0000000000..b2d99d5c13 --- /dev/null +++ b/include/sys/times.h @@ -0,0 +1,81 @@ +/**************************************************************************** + * include/sys/times.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SYS_TIMES_H +#define __INCLUDE_SYS_TIMES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Structure describing CPU time used by a process and its children. */ + +struct tms +{ + clock_t tms_utime; /* User CPU time. */ + clock_t tms_stime; /* System CPU time. */ + clock_t tms_cutime; /* User CPU time of dead children. */ + clock_t tms_cstime; /* System CPU time of dead children. */ +}; + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: times + * + * Description: + * The times() function shall fill the tms structure pointed to by buffer + * with time-accounting information. + * + * Returned Value: + * Upon successful completion, times() shall return the elapsed real time, + * in clock ticks, since an arbitrary point in the past (for example, + * system start-up time). This point does not change from one invocation + * of times() within the process to another. The return value may overflow + * the possible range of type clock_t. If times() fails, (clock_t)-1 shall + * be returned and errno set to indicate the error. + * + ****************************************************************************/ + +clock_t times(FAR struct tms *buffer); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_SYS_TIMES_H */ diff --git a/libs/libc/unistd/Make.defs b/libs/libc/unistd/Make.defs index cba837d9cd..dd34465791 100644 --- a/libs/libc/unistd/Make.defs +++ b/libs/libc/unistd/Make.defs @@ -23,7 +23,7 @@ CSRCS += lib_access.c lib_daemon.c lib_swab.c lib_pathconf.c lib_sysconf.c CSRCS += lib_getopt_common.c lib_getopt.c lib_getopt_long.c CSRCS += lib_getopt_longonly.c lib_getoptvars.c lib_getoptargp.c -CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c +CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c lib_times.c CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c CSRCS += lib_usleep.c lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c CSRCS += lib_setreuid.c lib_setregid.c lib_getrusage.c lib_utime.c lib_utimes.c diff --git a/libs/libc/unistd/lib_times.c b/libs/libc/unistd/lib_times.c new file mode 100644 index 0000000000..7d40a608f6 --- /dev/null +++ b/libs/libc/unistd/lib_times.c @@ -0,0 +1,61 @@ +/**************************************************************************** + * libs/libc/unistd/lib_times.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: times + * + * Description: + * The times() function shall fill the tms structure pointed to by buffer + * with time-accounting information. + * + * Returned Value: + * Upon successful completion, times() shall return the elapsed real time, + * in clock ticks, since an arbitrary point in the past (for example, + * system start-up time). This point does not change from one invocation + * of times() within the process to another. The return value may overflow + * the possible range of type clock_t. If times() fails, (clock_t)-1 shall + * be returned and errno set to indicate the error. + * + ****************************************************************************/ + +clock_t times(FAR struct tms *buffer) +{ + if (buffer == NULL) + { + set_errno(EINVAL); + return -1; + } + + memset(buffer, 0, sizeof(*buffer)); + return clock(); +}