FIXME: toplevel Makefile: 'make ntest' doesn't run versaplexd for now.
[versaplex.git] / vxodbc / misc.h
blob1b82382161bfe883db86dcc6c71edbd24668dc48
1 /* File: misc.h
3 * Description: See "misc.c"
5 * Comments: See "notice.txt" for copyright and license information.
7 */
9 #ifndef __MISC_H__
10 #define __MISC_H__
12 /* Define a type for defining a constant string expression.
13 * Note: needed by psqlodbc.h
15 #define CSTR static const char * const
17 #include "psqlodbc.h"
19 #include <stdio.h>
20 #ifndef WIN32
21 #include <unistd.h>
22 #endif
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 /* Uncomment MY_LOG define to compile in the mylog() statements.
28 Then, debug logging will occur if 'Debug' is set to 1 in the ODBCINST.INI
29 portion of the registry. You may have to manually add this key.
30 This logfile is intended for development use, not for an end user!
32 #define MY_LOG
35 /* Uncomment Q_LOG to compile in the qlog() statements (Communications log, i.e. CommLog).
36 This logfile contains serious log statements that are intended for an
37 end user to be able to read and understand. It is controlled by the
38 'CommLog' flag in the ODBCINST.INI portion of the registry (see above),
39 which is manipulated on the setup/connection dialog boxes.
41 #define Q_LOG
43 #if defined(WIN_MULTITHREAD_SUPPORT)
44 #define INIT_QLOG_CS InitializeCriticalSection(&qlog_cs)
45 #define ENTER_QLOG_CS EnterCriticalSection(&qlog_cs)
46 #define LEAVE_QLOG_CS LeaveCriticalSection(&qlog_cs)
47 #define DELETE_QLOG_CS DeleteCriticalSection(&qlog_cs)
48 #define INIT_MYLOG_CS InitializeCriticalSection(&mylog_cs)
49 #define ENTER_MYLOG_CS EnterCriticalSection(&mylog_cs)
50 #define LEAVE_MYLOG_CS LeaveCriticalSection(&mylog_cs)
51 #define DELETE_MYLOG_CS DeleteCriticalSection(&mylog_cs)
52 #elif defined(POSIX_MULTITHREAD_SUPPORT)
53 #define INIT_QLOG_CS pthread_mutex_init(&qlog_cs,0)
54 #define ENTER_QLOG_CS pthread_mutex_lock(&qlog_cs)
55 #define LEAVE_QLOG_CS pthread_mutex_unlock(&qlog_cs)
56 #define DELETE_QLOG_CS pthread_mutex_destroy(&qlog_cs)
57 #define INIT_MYLOG_CS pthread_mutex_init(&mylog_cs,0)
58 #define ENTER_MYLOG_CS pthread_mutex_lock(&mylog_cs)
59 #define LEAVE_MYLOG_CS pthread_mutex_unlock(&mylog_cs)
60 #define DELETE_MYLOG_CS pthread_mutex_destroy(&mylog_cs)
61 #else
62 #define INIT_QLOG_CS
63 #define ENTER_QLOG_CS
64 #define LEAVE_QLOG_CS
65 #define DELETE_QLOG_CS
66 #define INIT_MYLOG_CS
67 #define ENTER_MYLOG_CS
68 #define LEAVE_MYLOG_CS
69 #define DELETE_MYLOG_CS
70 #endif /* WIN_MULTITHREAD_SUPPORT */
72 #ifndef WIN32
73 #define MYLOGDIR "/tmp"
74 #else
75 #define MYLOGDIR "c:\\temp"
76 #endif /* WIN32 */
78 #ifdef MY_LOG
79 # define mylog(fmt, args...) _mylog(__func__, __LINE__, fmt, ## args)
80 # define forcelog(fmt, args...) _forcelog(__func__, __LINE__, fmt, ## args)
81 extern int _mylog(const char *file, int line, const char *fmt, ...);
82 extern int _forcelog(const char *file, int line, const char *fmt, ...);
83 #else /* !MY_LOG */
84 # define mylog(fmt, args...)
85 #endif /* MY_LOG */
87 #define inolog if (get_mylog() > 1) mylog /* for really temporary debug */
89 #ifdef Q_LOG
90 # define qlog(fmt, args...) _qlog(__func__, __LINE__, fmt, ## args)
91 extern int _qlog(const char *file, int line, const char *fmt, ...);
92 #else /* !Q_LOG */
93 # define qlog(fmt, args...)
94 #endif
96 #define inoqlog qlog
97 int get_qlog(void);
98 int get_mylog(void);
100 #ifndef WIN32
101 #define DIRSEPARATOR "/"
102 #else
103 #define DIRSEPARATOR "\\"
104 #endif
106 #ifdef WIN32
107 #define PG_BINARY O_BINARY
108 #define PG_BINARY_R "rb"
109 #define PG_BINARY_W "wb"
110 #define PG_BINARY_A "ab"
111 #else
112 #define PG_BINARY 0
113 #define PG_BINARY_R "r"
114 #define PG_BINARY_W "w"
115 #define PG_BINARY_A "a"
116 #endif
119 void InitializeLogging();
120 void FinalizeLogging();
122 void remove_newlines(char *string);
123 char *strncpy_null(char *dst, const char *src, ssize_t len);
124 char *trim(char *string);
125 char *make_string(const unsigned char *s, ssize_t len, char *buf, size_t bufsize);
126 char *make_lstring_ifneeded(ConnectionClass *, const void *s, ssize_t len, BOOL);
127 char *my_strcat(char *buf, const char *fmt, const char *s, ssize_t len);
128 char *schema_strcat(char *buf, const char *fmt, const char *s, ssize_t len,
129 const char *, int, ConnectionClass *conn);
130 char *my_strcat1(char *buf, const char *fmt, const char *s1,
131 const char *s, ssize_t len);
132 char *schema_strcat1(char *buf, const char *fmt, const char *s1,
133 const char *s, ssize_t len,
134 const char *, int, ConnectionClass *conn);
135 int snprintf_add(char *buf, size_t size, const char *format, ...);
136 size_t snprintf_len(char *buf, size_t size, const char *format, ...);
137 /* #define GET_SCHEMA_NAME(nspname) (stricmp(nspname, "public") ? nspname : "") */
138 #define GET_SCHEMA_NAME(nspname) (nspname)
140 /* defines for return value of my_strcpy */
141 #define STRCPY_SUCCESS 1
142 #define STRCPY_FAIL 0
143 #define STRCPY_TRUNCATED (-1)
144 #define STRCPY_NULL (-2)
146 ssize_t my_strcpy(char *dst, ssize_t dst_len, const char *src, ssize_t src_len);
148 #ifdef __cplusplus
150 #endif
151 #endif /* __MISC_H__ */