Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / nacl / clock_gettime.c
1 /*
2  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include <time.h>
8
9 #include "native_client/src/untrusted/nacl/nacl_irt.h"
10
11 void __libnacl_irt_clock_init(void) {
12   __libnacl_irt_query(NACL_IRT_CLOCK_v0_1,
13                       &__libnacl_irt_clock, sizeof(__libnacl_irt_clock));
14 }
15
16 int clock_gettime(clockid_t clock_id, struct timespec *tp) {
17   if (!__libnacl_irt_init_fn(&__libnacl_irt_clock.clock_gettime,
18                              __libnacl_irt_clock_init)) {
19     return -1;
20   }
21
22   int error = __libnacl_irt_clock.clock_gettime(clock_id, tp);
23   if (error) {
24     errno = error;
25     return -1;
26   }
27
28   return 0;
29 }