1da2e3ebchin/***********************************************************************
25947648Marcel Telka *                                                                      *
35947648Marcel Telka *               This software is part of the ast package               *
45947648Marcel Telka *          Copyright (c) 1985-2013 AT&T Intellectual Property          *
55947648Marcel Telka *                      and is licensed under the                       *
65947648Marcel Telka *                 Eclipse Public License, Version 1.0                  *
75947648Marcel Telka *                    by AT&T Intellectual Property                     *
85947648Marcel Telka *                                                                      *
95947648Marcel Telka *                A copy of the License is available at                 *
105947648Marcel Telka *          http://www.eclipse.org/org/documents/epl-v10.html           *
115947648Marcel Telka *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
125947648Marcel Telka *                                                                      *
135947648Marcel Telka *              Information and Software Systems Research               *
145947648Marcel Telka *                            AT&T Research                             *
155947648Marcel Telka *                           Florham Park NJ                            *
165947648Marcel Telka *                                                                      *
175947648Marcel Telka *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
185947648Marcel Telka *                    David Korn <dgkorn@gmail.com>                     *
195947648Marcel Telka *                     Phong Vo <phongvo@gmail.com>                     *
205947648Marcel Telka *                                                                      *
215947648Marcel Telka ***********************************************************************/
225947648Marcel Telka
235947648Marcel Telka#include <errno.h>
245947648Marcel Telka#include <time.h>
255947648Marcel Telka
265947648Marcel Telka#include "tv.h"
27da2e3ebchin
28da2e3ebchin/*
29da2e3ebchin * sleep for tv
30da2e3ebchin * non-zero exit if sleep did not complete
31da2e3ebchin * with remaining time in rv
325947648Marcel Telka *
335947648Marcel Telka * NOTE: some systems hide nanosleep() ouside of -lc -- puleeze
34da2e3ebchin */
35da2e3ebchin
365947648Marcel Telkaint tvsleep(const Tv_t *tv, Tv_t *rv) {
375947648Marcel Telka    struct timespec stv;
385947648Marcel Telka    struct timespec srv;
395947648Marcel Telka    int r;
405947648Marcel Telka
415947648Marcel Telka    stv.tv_sec = tv->tv_sec;
425947648Marcel Telka    stv.tv_nsec = tv->tv_nsec;
435947648Marcel Telka    if ((r = nanosleep(&stv, &srv)) && errno == EINTR && rv) {
445947648Marcel Telka        rv->tv_sec = srv.tv_sec;
455947648Marcel Telka        rv->tv_nsec = srv.tv_nsec;
465947648Marcel Telka    }
475947648Marcel Telka    return r;
48da2e3ebchin}
49