1
/* config.h - general config and Dprintf macro
3
* Copyright (C) 2003 Federico Di Gregorio <fog@debian.org>
5
* This file is part of psycopg.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2,
10
* or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#ifndef PSYCOPG_CONFIG_H
23
#define PSYCOPG_CONFIG_H 1
25
/* replacement for asprintf() */
27
extern int asprintf(char **buffer, char *fmt, ...);
30
/* debug printf-like function */
31
#if defined( __GNUC__) && !defined(__APPLE__)
33
#include <sys/types.h>
35
#define Dprintf(fmt, args...) \
36
fprintf(stderr, "[%d] " fmt "\n", getpid() , ## args)
38
#define Dprintf(fmt, args...)
40
#else /* !__GNUC__ or __APPLE__ */
43
static void Dprintf(const char *fmt, ...)
52
static void Dprintf(const char *fmt, ...) {}
56
/* win32 specific stuff */
61
#define pthread_mutex_t HANDLE
62
#define pthread_condvar_t HANDLE
63
#define pthread_mutex_lock(object) WaitForSingleObject(object, INFINITE)
64
#define pthread_mutex_unlock(object) ReleaseMutex(object)
65
#define pthread_mutex_destroy(ref) (CloseHandle(ref))
66
/* convert pthread mutex to native mutex */
67
static int pthread_mutex_init(pthread_mutex_t *mutex, void* fake)
69
*mutex = CreateMutex(NULL, FALSE, NULL);
72
/* to work around the fact that Windows does not have a gmtime_r function, or
73
a proper gmtime function */
74
static struct tm *gmtime_r(time_t *t, struct tm *tm)
79
/* remove the inline keyword, since it doesn't work unless C++ file */
83
#if defined(__FreeBSD__) || defined(_WIN32)
84
/* what's this, we have no round function either? */
85
static double round(double num)
87
return (num >= 0) ? floor(num + 0.5) : ceil(num - 0.5);
91
/* postgresql < 7.4 does not have PQfreemem */
92
#ifndef HAVE_PQFREEMEM
93
#define PQfreemem free
96
#endif /* !defined(PSYCOPG_CONFIG_H) */