change pa_gettimeofday() to return a pointer to the struct timeval*, instead of an int

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@645 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2006-04-06 23:31:40 +00:00
parent e872c751e1
commit 1be00173c1
2 changed files with 18 additions and 16 deletions

View file

@ -418,9 +418,11 @@ char *pa_strlcpy(char *b, const char *s, size_t l) {
return b; return b;
} }
int pa_gettimeofday(struct timeval *tv) { struct timeval *pa_gettimeofday(struct timeval *tv) {
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
return gettimeofday(tv, NULL); assert(tv);
return gettimeofday(tv, NULL) < 0 ? NULL : tv;
#elif defined(OS_IS_WIN32) #elif defined(OS_IS_WIN32)
/* /*
* Copied from implementation by Steven Edwards (LGPL). * Copied from implementation by Steven Edwards (LGPL).
@ -437,7 +439,8 @@ int pa_gettimeofday(struct timeval *tv) {
LARGE_INTEGER li; LARGE_INTEGER li;
__int64 t; __int64 t;
if (tv) { assert(tv);
GetSystemTimeAsFileTime(&ft); GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime; li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime; li.HighPart = ft.dwHighDateTime;
@ -446,9 +449,8 @@ int pa_gettimeofday(struct timeval *tv) {
t /= 10; /* In microseconds */ t /= 10; /* In microseconds */
tv->tv_sec = (long)(t / 1000000); tv->tv_sec = (long)(t / 1000000);
tv->tv_usec = (long)(t % 1000000); tv->tv_usec = (long)(t % 1000000);
}
return 0; return tv;
#else #else
#error "Platform lacks gettimeofday() or equivalent function." #error "Platform lacks gettimeofday() or equivalent function."
#endif #endif
@ -503,8 +505,8 @@ int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
pa_usec_t pa_timeval_age(const struct timeval *tv) { pa_usec_t pa_timeval_age(const struct timeval *tv) {
struct timeval now; struct timeval now;
assert(tv); assert(tv);
pa_gettimeofday(&now);
return pa_timeval_diff(&now, tv); return pa_timeval_diff(pa_gettimeofday(&now), tv);
} }
/* Add the specified time inmicroseconds to the specified timeval structure */ /* Add the specified time inmicroseconds to the specified timeval structure */

View file

@ -55,7 +55,7 @@ char *pa_get_home_dir(char *s, size_t l);
const char *pa_path_get_filename(const char *p); const char *pa_path_get_filename(const char *p);
int pa_gettimeofday(struct timeval *tv); struct timeval *pa_gettimeofday(struct timeval *tv);
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b); pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b); int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
pa_usec_t pa_timeval_age(const struct timeval *tv); pa_usec_t pa_timeval_age(const struct timeval *tv);