Add clock(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-05-15 15:00:48 +02:00
parent 0903f4edc2
commit ad51b5a070
3 changed files with 12 additions and 9 deletions

View File

@ -174,7 +174,6 @@ canonicalize_file_name.o \
chdir.o \
chmod.o \
chown.o \
clock.o \
close.o \
confstr.o \
$(CPUDIR)/calltrace.o \
@ -355,6 +354,7 @@ time/clock_getres.o \
time/clock_gettime.o \
time/clock_gettimeres.o \
time/clock_nanosleep.o \
time/clock.o \
time/clock_settime.o \
time/clock_settimeres.o \
time/nanosleep.o \

View File

@ -62,7 +62,7 @@ __BEGIN_DECLS
@include(NULL.h)
#define CLOCKS_PER_SEC ((clock_t) 1000000)
#define CLOCKS_PER_SEC 1000000l
__END_DECLS
#include <sortix/clock.h>

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2013
This file is part of the Sortix C Library.
@ -17,16 +17,19 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
clock.cpp
Determine processor time.
time/clock.cpp
Get process execution time.
*******************************************************************************/
#include <errno.h>
#include <time.h>
extern "C" clock_t clock(void)
// TODO: This function is crap and has been replaced by clock_gettime.
extern "C" clock_t clock()
{
errno = ENOTSUP;
return -1;
struct timespec now;
if ( clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now) < 0 )
return -1;
static_assert(CLOCKS_PER_SEC == 1000000, "CLOCKS_PER_SEC == 1000000");
return (clock_t) now.tv_sec * 1000000 + (clock_t) now.tv_sec / 1000;
}