source: roaraudio/libroarpulse/timeval.c @ 3455:5a26f2fec851

Last change on this file since 3455:5a26f2fec851 was 3448:a1d933fa1897, checked in by phi, 14 years ago

implemented pa_timeval_add()

File size: 2.4 KB
Line 
1//timeval.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include <libroarpulse/libroarpulse.h>
40
41struct timeval *pa_gettimeofday(struct timeval *tv) {
42#ifdef ROAR_HAVE_GETTIMEOFDAY
43 if ( gettimeofday(tv, NULL) == -1 ) {
44  return NULL;
45 } else {
46  return tv;
47 }
48#else
49 return NULL;
50#endif
51}
52
53pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
54int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
55pa_usec_t pa_timeval_age(const struct timeval *tv);
56struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
57 unsigned long long int secs;
58
59 if ( tv == NULL )
60  return NULL;
61
62 secs = v/1000000LLU;
63
64 tv->tv_sec += secs;
65
66 v -= secs*1000000LLU;
67
68 tv->tv_usec += v;
69
70 while ( tv->tv_usec > 1000000LLU ) {
71  tv->tv_usec -= 1000000LLU;
72  tv->tv_sec  += 1;
73 }
74
75 return tv;
76}
77
78
79//ll
Note: See TracBrowser for help on using the repository browser.