[3445] | 1 | //timeval.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013 |
---|
[3445] | 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 |
---|
[3517] | 25 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 26 | * Boston, MA 02110-1301, USA. |
---|
[3445] | 27 | * |
---|
| 28 | * NOTE for everyone want's to change something and send patches: |
---|
| 29 | * read README and HACKING! There a addition information on |
---|
| 30 | * the license of this document you need to read before you send |
---|
| 31 | * any patches. |
---|
| 32 | * |
---|
| 33 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 34 | * or libpulse*: |
---|
| 35 | * The libs libroaresd, libroararts and libroarpulse link this libroar |
---|
| 36 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 37 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #include <libroarpulse/libroarpulse.h> |
---|
| 41 | |
---|
[3447] | 42 | struct timeval *pa_gettimeofday(struct timeval *tv) { |
---|
| 43 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
| 44 | if ( gettimeofday(tv, NULL) == -1 ) { |
---|
| 45 | return NULL; |
---|
| 46 | } else { |
---|
| 47 | return tv; |
---|
| 48 | } |
---|
| 49 | #else |
---|
| 50 | return NULL; |
---|
| 51 | #endif |
---|
| 52 | } |
---|
| 53 | |
---|
[3446] | 54 | pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b); |
---|
| 55 | int pa_timeval_cmp(const struct timeval *a, const struct timeval *b); |
---|
| 56 | pa_usec_t pa_timeval_age(const struct timeval *tv); |
---|
[3448] | 57 | struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) { |
---|
| 58 | unsigned long long int secs; |
---|
| 59 | |
---|
| 60 | if ( tv == NULL ) |
---|
| 61 | return NULL; |
---|
| 62 | |
---|
| 63 | secs = v/1000000LLU; |
---|
| 64 | |
---|
| 65 | tv->tv_sec += secs; |
---|
| 66 | |
---|
| 67 | v -= secs*1000000LLU; |
---|
| 68 | |
---|
| 69 | tv->tv_usec += v; |
---|
| 70 | |
---|
[5270] | 71 | while ( tv->tv_usec > 1000000LL ) { |
---|
| 72 | tv->tv_usec -= 1000000LL; |
---|
[3448] | 73 | tv->tv_sec += 1; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | return tv; |
---|
| 77 | } |
---|
[3446] | 78 | |
---|
| 79 | |
---|
[3445] | 80 | //ll |
---|