summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorJason Erickson <jerickso@stickpeople.com>2017-02-09 20:57:54 -0700
committerJason Erickson <jerickso@stickpeople.com>2017-02-09 20:57:54 -0700
commitd52e9100d28a5c57078f14b4007e7d9f065b243c (patch)
tree090fc73de34e7a32dbaca2885b29f8fc60d75a3c /psycopg
parent83cf908c88de1b6feff51f5529a0d14491354c5d (diff)
downloadpsycopg2-d52e9100d28a5c57078f14b4007e7d9f065b243c.tar.gz
Added support for MSVC compiler
Added function 'timeradd'. Changed second parameter of 'gettimeofday' to void since not used in function and MSVC timezone definition is not a struct).
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/config.h2
-rw-r--r--psycopg/win32_support.c21
-rw-r--r--psycopg/win32_support.h14
3 files changed, 30 insertions, 7 deletions
diff --git a/psycopg/config.h b/psycopg/config.h
index f8e17a9..95d428a 100644
--- a/psycopg/config.h
+++ b/psycopg/config.h
@@ -140,6 +140,8 @@ static int pthread_mutex_init(pthread_mutex_t *mutex, void* fake)
#endif
#define strcasecmp(x, y) lstrcmpi(x, y)
#endif
+
+#include "win32_support.h"
#endif
/* what's this, we have no round function either? */
diff --git a/psycopg/win32_support.c b/psycopg/win32_support.c
index d508b22..7a9c8b8 100644
--- a/psycopg/win32_support.c
+++ b/psycopg/win32_support.c
@@ -35,7 +35,7 @@
src/port/gettimeofday.c in PostgreSQL core */
/* FILETIME of Jan 1 1970 00:00:00. */
-static const unsigned __int64 epoch = 116444736000000000ULL;
+static const unsigned __int64 epoch = ((unsigned __int64) 116444736000000000ULL);
/*
* timezone information is stored outside the kernel so tzp isn't used anymore.
@@ -44,7 +44,7 @@ static const unsigned __int64 epoch = 116444736000000000ULL;
* elapsed_time().
*/
int
-gettimeofday(struct timeval * tp, struct timezone * tzp)
+gettimeofday(struct timeval * tp, void * tzp)
{
FILETIME file_time;
SYSTEMTIME system_time;
@@ -60,17 +60,30 @@ gettimeofday(struct timeval * tp, struct timezone * tzp)
return 0;
}
+
+/* timeradd missing on MS VC */
+void
+timeradd(struct timeval *a, struct timeval *b, struct timeval *c)
+{
+ c->tv_sec = a->tv_sec + b->tv_sec;
+ c->tv_usec = a->tv_usec + b->tv_usec;
+ if(c->tv_usec >= 1000000L) {
+ c->tv_usec -= 1000000L;
+ c->tv_sec += 1;
+ }
+}
#endif /* !defined(__MINGW32__) */
-/* timersub is missing on mingw */
+/* timersub is missing on mingw & MS VC */
void
timersub(struct timeval *a, struct timeval *b, struct timeval *c)
{
c->tv_sec = a->tv_sec - b->tv_sec;
c->tv_usec = a->tv_usec - b->tv_usec;
- if (tv_usec < 0) {
+ if (c->tv_usec < 0) {
c->tv_usec += 1000000;
c->tv_sec -= 1;
}
}
+
#endif /* defined(_WIN32) */
diff --git a/psycopg/win32_support.h b/psycopg/win32_support.h
index be963df..b463141 100644
--- a/psycopg/win32_support.h
+++ b/psycopg/win32_support.h
@@ -23,18 +23,26 @@
* License for more details.
*/
#ifndef PSYCOPG_WIN32_SUPPORT_H
-#define PSYCOPG_WIN32_SUPPORT_H 1
+#define PSYCOPG_WIN32_SUPPORT_H
#include "psycopg/config.h"
+#ifdef _WIN32
+#include <time.h>
+#endif
+#ifdef __MINGW32__
#include <sys/time.h>
+#endif
+
#ifdef _WIN32
#ifndef __MINGW32__
-HIDDEN int gettimeofday(struct timeval * tp, struct timezone * tzp);
+extern HIDDEN int gettimeofday(struct timeval * tp, void * tzp);
+extern HIDDEN void timeradd(struct timeval *a, struct timeval *b, struct timeval *c);
+#elif
#endif
-HIDDEN void timersub(struct timeval *a, struct timeval *b, struct timeval *c);
+extern HIDDEN void timersub(struct timeval *a, struct timeval *b, struct timeval *c);
#endif
#endif /* !defined(PSYCOPG_WIN32_SUPPORT_H) */