UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / lib / autil.cpp
blob243511fcccb3114e57e8d98e95fc31d9a424a5bc
1 /*
2 * autil.cpp
4 * Common helper routines for a* classes.
5 */
7 /*
8 * Copyright (C) 2007 Adam Kropelin
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General
12 * Public License as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA.
25 #include "autil.h"
26 #include "apc.h"
28 void calc_abstimeout(int msec, struct timespec *abstime)
30 // It would be best to use clock_gettime here, but it is not
31 // widely available, so use gettimeofday() which we can count on
32 // being available, if not quite as accurate.
33 struct timeval now;
34 gettimeofday(&now, NULL);
35 abstime->tv_sec = now.tv_sec + msec/1000;
36 abstime->tv_nsec = now.tv_usec*1000 + (msec % 1000) * 1000000;
37 if (abstime->tv_nsec >= 1000000000) {
38 abstime->tv_sec++;
39 abstime->tv_nsec -= 1000000000;