xref: /openbsd/lib/libc/gen/timespec_get.c (revision d82e6535)
1*d82e6535Spirofti /*	$OpenBSD: timespec_get.c,v 1.2 2020/07/06 13:33:06 pirofti Exp $	*/
26151004eSguenther /*	$NetBSD: timespec_get.c,v 1.2 2016/10/04 12:48:15 christos Exp $	*/
36151004eSguenther 
46151004eSguenther /*-
56151004eSguenther  * Copyright (c) 2016 The NetBSD Foundation, Inc.
66151004eSguenther  * All rights reserved.
76151004eSguenther  *
86151004eSguenther  * This code is derived from software contributed to The NetBSD Foundation
96151004eSguenther  * by Kamil Rytarowski.
106151004eSguenther  *
116151004eSguenther  * Redistribution and use in source and binary forms, with or without
126151004eSguenther  * modification, are permitted provided that the following conditions
136151004eSguenther  * are met:
146151004eSguenther  * 1. Redistributions of source code must retain the above copyright
156151004eSguenther  *    notice, this list of conditions and the following disclaimer.
166151004eSguenther  * 2. Redistributions in binary form must reproduce the above copyright
176151004eSguenther  *    notice, this list of conditions and the following disclaimer in the
186151004eSguenther  *    documentation and/or other materials provided with the distribution.
196151004eSguenther  *
206151004eSguenther  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
216151004eSguenther  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
226151004eSguenther  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
236151004eSguenther  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
246151004eSguenther  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
256151004eSguenther  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
266151004eSguenther  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
276151004eSguenther  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
286151004eSguenther  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
296151004eSguenther  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
306151004eSguenther  * POSSIBILITY OF SUCH DAMAGE.
316151004eSguenther  */
326151004eSguenther 
336151004eSguenther #include <time.h>
346151004eSguenther 
356151004eSguenther int
timespec_get(struct timespec * ts,int base)366151004eSguenther timespec_get(struct timespec *ts, int base)
376151004eSguenther {
386151004eSguenther 	switch (base) {
396151004eSguenther 	case TIME_UTC:
40*d82e6535Spirofti 		if (WRAP(clock_gettime)(CLOCK_REALTIME, ts) == -1)
416151004eSguenther 			return 0;
426151004eSguenther 		break;
436151004eSguenther 	default:
446151004eSguenther 		return 0;
456151004eSguenther 	}
466151004eSguenther 
476151004eSguenther 	return base;
486151004eSguenther }
49