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 /* debug printf-like function */
26 #if defined( __GNUC__) && !defined(__APPLE__)
28 #include <sys/types.h>
30 #define Dprintf(fmt, args...) \
31 fprintf(stderr, "[%d] " fmt "\n", getpid() , ## args)
33 #define Dprintf(fmt, args...)
35 #else /* !__GNUC__ or __APPLE__ */
38 static void Dprintf(const char *fmt, ...)
47 static void Dprintf(const char *fmt, ...) {}
51 /* pthreads work-arounds for mutilated operating systems */
52 #if defined(_WIN32) || defined(__BEOS__)
56 #define pthread_mutex_t HANDLE
57 #define pthread_condvar_t HANDLE
58 #define pthread_mutex_lock(object) WaitForSingleObject(object, INFINITE)
59 #define pthread_mutex_unlock(object) ReleaseMutex(object)
60 #define pthread_mutex_destroy(ref) (CloseHandle(*(ref)))
61 /* convert pthread mutex to native mutex */
62 static int pthread_mutex_init(pthread_mutex_t *mutex, void* fake)
64 *mutex = CreateMutex(NULL, FALSE, NULL);
71 #define pthread_mutex_t sem_id
72 #define pthread_mutex_lock(object) acquire_sem(object)
73 #define pthread_mutex_unlock(object) release_sem(object)
74 #define pthread_mutex_destroy(ref) delete_sem(*ref)
75 static int pthread_mutex_init(pthread_mutex_t *mutex, void* fake)
77 *mutex = create_sem(1, "psycopg_mutex");
84 #else /* pthread is available */
88 /* to work around the fact that Windows does not have a gmtime_r function, or
89 a proper gmtime function */
91 static struct tm *gmtime_r(time_t *t, struct tm *tm)
96 static struct tm *localtime_r(time_t *t, struct tm *tm)
101 /* remove the inline keyword, since it doesn't work unless C++ file */
105 #if defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__)
106 /* what's this, we have no round function either? */
107 static double round(double num)
109 return (num >= 0) ? floor(num + 0.5) : ceil(num - 0.5);
113 /* postgresql < 7.4 does not have PQfreemem */
114 #ifndef HAVE_PQFREEMEM
115 #define PQfreemem free
118 #endif /* !defined(PSYCOPG_CONFIG_H) */