1
1

gettimeofday: fix name space pollution

For systems without its own gettimeofday() implementation, we still must
not provide one outside our namespace.

Reported by: Bill Segall
Этот коммит содержится в:
Daniel Stenberg 2011-08-05 23:46:12 +02:00
родитель 49453c9ae2
Коммит 79f48e4881
3 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -424,7 +424,7 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
}
}
gettimeofday(&now, NULL);
_libssh2_gettimeofday(&now, NULL);
if(!firstsec) {
firstsec = now.tv_sec;
}
@ -563,16 +563,15 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */
#endif
#if defined(LIBSSH2_WIN32) && !defined(__MINGW32__)
/* this define is defined in misc.h for the correct platforms */
#ifdef LIBSSH2_GETTIMEOFDAY_WIN32
/*
* gettimeofday
* Implementation according to:
* The Open Group Base Specifications Issue 6
* IEEE Std 1003.1, 2004 Edition
*/
/*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
@ -591,9 +590,7 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */
/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
#define _W32_FT_OFFSET (116444736000000000)
int __cdecl gettimeofday(struct timeval *tp,
void *tzp)
int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp)
{
union {
unsigned __int64 ns100; /*time since 1 Jan 1601 in 100ns units */

Просмотреть файл

@ -1,6 +1,6 @@
#ifndef __LIBSSH2_MISC_H
#define __LIBSSH2_MISC_H
/* Copyright (c) 2009-2010 by Daniel Stenberg
/* Copyright (c) 2009-2011 by Daniel Stenberg
*
* All rights reserved.
*
@ -78,4 +78,17 @@ void _libssh2_htonu32(unsigned char *buf, uint32_t val);
void _libssh2_store_u32(unsigned char **buf, uint32_t value);
void _libssh2_store_str(unsigned char **buf, const char *str, size_t len);
#if defined(LIBSSH2_WIN32) && !defined(__MINGW32__)
/* provide a private one */
#undef HAVE_GETTIMEOFDAY
int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp);
#define HAVE_LIBSSH2_GETTIMEOFDAY
#define LIBSSH2_GETTIMEOFDAY_WIN32 /* enable the win32 implementation */
#else
#ifdef HAVE_GETTIMEOFDAY
#define _libssh2_gettimeofday(x,y) gettimeofday(x,y)
#define HAVE_LIBSSH2_GETTIMEOFDAY
#endif
#endif
#endif /* _LIBSSH2_MISC_H */

Просмотреть файл

@ -56,6 +56,7 @@
#include "session.h"
#include "channel.h"
#include "mac.h"
#include "misc.h"
/* libssh2_default_alloc
*/
@ -1573,13 +1574,13 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
}
#ifdef HAVE_POLL
#ifdef HAVE_GETTIMEOFDAY
#ifdef HAVE_LIBSSH2_GETTIMEOFDAY
{
struct timeval tv_begin, tv_end;
gettimeofday((struct timeval *) &tv_begin, NULL);
_libssh2_gettimeofday((struct timeval *) &tv_begin, NULL);
sysret = poll(sockets, nfds, timeout_remaining);
gettimeofday((struct timeval *) &tv_end, NULL);
_libssh2_gettimeofday((struct timeval *) &tv_end, NULL);
timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000;
timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000;
}
@ -1633,13 +1634,13 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
#elif defined(HAVE_SELECT)
tv.tv_sec = timeout_remaining / 1000;
tv.tv_usec = (timeout_remaining % 1000) * 1000;
#ifdef HAVE_GETTIMEOFDAY
#ifdef HAVE_LIBSSH2_GETTIMEOFDAY
{
struct timeval tv_begin, tv_end;
gettimeofday((struct timeval *) &tv_begin, NULL);
_libssh2_gettimeofday((struct timeval *) &tv_begin, NULL);
sysret = select(maxfd+1, &rfds, &wfds, NULL, &tv);
gettimeofday((struct timeval *) &tv_end, NULL);
_libssh2_gettimeofday((struct timeval *) &tv_end, NULL);
timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000;
timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000;