home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
acld-1.11.tar.gz
/
acld-1.11.tar
/
acld-1.11
/
timer.c
< prev
next >
Wrap
C/C++ Source or Header
|
2008-10-24
|
2KB
|
75 lines
/*
* Copyright (c) 2002, 2006, 2008
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Id: timer.c 529 2008-10-24 06:57:49Z leres $ (LBL)";
#endif
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include "acld.h"
/* Return seconds left (or -1 if not pending) */
int
timercheck(struct timer *tp)
{
int i;
struct timeval tv;
if (tp->duetime == 0)
return (-1);
getts(&tv);
i = tp->duetime - tv.tv_sec;
if (i < 0)
i = 0;
return (i);
}
int
timerdue(struct timer *tp)
{
if (timercheck(tp) != 0)
return (0);
timerreset(tp);
return (1);
}
void
timerreset(struct timer *tp)
{
tp->duetime = 0;
}
void
timerset(struct timer *tp, int secs)
{
struct timeval tv;
getts(&tv);
tp->duetime = tv.tv_sec + secs;
}