121308Sache/*- 221308Sache * SPDX-License-Identifier: BSD-2-Clause 321308Sache * 421308Sache * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org> 521308Sache * 621308Sache * Redistribution and use in source and binary forms, with or without 721308Sache * modification, are permitted provided that the following conditions 821308Sache * are met: 921308Sache * 1. Redistributions of source code must retain the above copyright 1058310Sache * notice, this list of conditions and the following disclaimer. 1121308Sache * 2. Redistributions in binary form must reproduce the above copyright 1221308Sache * notice, this list of conditions and the following disclaimer in the 1321308Sache * documentation and/or other materials provided with the distribution. 1421308Sache * 1521308Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1621308Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1721308Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1821308Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1921308Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2021308Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2158310Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2221308Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2321308Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2421308Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2521308Sache * SUCH DAMAGE. 2621308Sache */ 2721308Sache 2826497Sache#include <sys/syscall.h> 2926497Sache#include <sys/time.h> 3058310Sache#include <sys/vdso.h> 3158310Sache#include <errno.h> 3221308Sache#include <time.h> 3321308Sache#include "libc_private.h" 3421308Sache 3521308Sacheint __clock_gettime(clockid_t, struct timespec *ts); 3621308Sache 3721308Sache__weak_reference(__clock_gettime, clock_gettime); 3821308Sache 3921308Sacheint 4021308Sache__clock_gettime(clockid_t clock_id, struct timespec *ts) 4121308Sache{ 4221308Sache int error; 4321308Sache 4421308Sache if (__vdso_clock_gettime != NULL && __vdso_gettc != NULL) 4521308Sache error = __vdso_clock_gettime(clock_id, ts); 4621308Sache else 4721308Sache error = ENOSYS; 4821308Sache if (error == ENOSYS) { 4958310Sache error = __sys_clock_gettime(clock_id, ts); 5058310Sache } else if (error != 0) { 5158310Sache errno = error; 5221308Sache error = -1; 5326497Sache } 5421308Sache return (error); 5521308Sache} 5621308Sache