1/***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2013 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18 *                    David Korn <dgkorn@gmail.com>                     *
19 *                     Phong Vo <phongvo@gmail.com>                     *
20 *                                                                      *
21 ***********************************************************************/
22
23#include <errno.h>
24#include <time.h>
25
26#include "tv.h"
27
28/*
29 * sleep for tv
30 * non-zero exit if sleep did not complete
31 * with remaining time in rv
32 *
33 * NOTE: some systems hide nanosleep() ouside of -lc -- puleeze
34 */
35
36int tvsleep(const Tv_t *tv, Tv_t *rv) {
37    struct timespec stv;
38    struct timespec srv;
39    int r;
40
41    stv.tv_sec = tv->tv_sec;
42    stv.tv_nsec = tv->tv_nsec;
43    if ((r = nanosleep(&stv, &srv)) && errno == EINTR && rv) {
44        rv->tv_sec = srv.tv_sec;
45        rv->tv_nsec = srv.tv_nsec;
46    }
47    return r;
48}
49