~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/port.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * port.h
 
4
 *        Header for src/port/ compatibility functions.
 
5
 *
 
6
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
7
 * Portions Copyright (c) 1994, Regents of the University of California
 
8
 *
 
9
 * $PostgreSQL: pgsql/src/include/port.h,v 1.69.4.2 2005-03-25 00:35:15 tgl Exp $
 
10
 *
 
11
 *-------------------------------------------------------------------------
 
12
 */
 
13
 
 
14
#ifndef WIN32_CLIENT_ONLY
 
15
/* for thread.c */
 
16
#include <pwd.h>
 
17
#include <netdb.h>
 
18
#endif
 
19
 
 
20
#include <ctype.h>
 
21
 
 
22
/* non-blocking */
 
23
extern bool pg_set_noblock(int sock);
 
24
extern bool pg_set_block(int sock);
 
25
 
 
26
/* Portable path handling for Unix/Win32 */
 
27
 
 
28
extern char *first_dir_separator(const char *filename);
 
29
extern char *last_dir_separator(const char *filename);
 
30
extern char *first_path_separator(const char *pathlist);
 
31
extern void join_path_components(char *ret_path,
 
32
                                                                 const char *head, const char *tail);
 
33
extern void canonicalize_path(char *path);
 
34
extern void make_native_path(char *path);
 
35
extern const char *get_progname(const char *argv0);
 
36
extern void get_share_path(const char *my_exec_path, char *ret_path);
 
37
extern void get_etc_path(const char *my_exec_path, char *ret_path);
 
38
extern void get_include_path(const char *my_exec_path, char *ret_path);
 
39
extern void get_pkginclude_path(const char *my_exec_path, char *ret_path);
 
40
extern void get_includeserver_path(const char *my_exec_path, char *ret_path);
 
41
extern void get_lib_path(const char *my_exec_path, char *ret_path);
 
42
extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
 
43
extern void get_locale_path(const char *my_exec_path, char *ret_path);
 
44
extern void set_pglocale_pgservice(const char *argv0, const char *app);
 
45
extern bool get_home_path(char *ret_path);
 
46
extern void get_parent_directory(char *path);
 
47
 
 
48
/*
 
49
 *      is_absolute_path
 
50
 *
 
51
 *      By making this a macro we prevent the need for libpq to include
 
52
 *      path.c which uses exec.c.
 
53
 */
 
54
#ifndef WIN32
 
55
#define is_absolute_path(filename) \
 
56
( \
 
57
        ((filename)[0] == '/') \
 
58
)
 
59
#else
 
60
#define is_absolute_path(filename) \
 
61
( \
 
62
        ((filename)[0] == '/') || \
 
63
        (filename)[0] == '\\' || \
 
64
        (isalpha((filename)[0]) && (filename)[1] == ':' && \
 
65
        ((filename)[2] == '\\' || (filename)[2] == '/')) \
 
66
)
 
67
#endif
 
68
 
 
69
 
 
70
/* Portable way to find binaries */
 
71
extern int      find_my_exec(const char *argv0, char *retpath);
 
72
extern int find_other_exec(const char *argv0, const char *target,
 
73
                                const char *versionstr, char *retpath);
 
74
 
 
75
#if defined(WIN32) || defined(__CYGWIN__)
 
76
#define EXE ".exe"
 
77
#else
 
78
#define EXE ""
 
79
#endif
 
80
 
 
81
#if defined(WIN32) && !defined(__CYGWIN__)
 
82
#define DEVNULL "nul"
 
83
#else
 
84
#define DEVNULL "/dev/null"
 
85
#endif
 
86
 
 
87
/*
 
88
 *      Win32 needs double quotes at the beginning and end of system()
 
89
 *      strings.  If not, it gets confused with multiple quoted strings.
 
90
 *      It also requires double-quotes around the executable name and
 
91
 *      any files used for redirection.  Other args can use single-quotes.
 
92
 *
 
93
 *      See the "Notes" section about quotes at:
 
94
 *              http://home.earthlink.net/~rlively/MANUALS/COMMANDS/C/CMD.HTM
 
95
 */
 
96
#if defined(WIN32) && !defined(__CYGWIN__)
 
97
#define SYSTEMQUOTE "\""
 
98
#else
 
99
#define SYSTEMQUOTE ""
 
100
#endif
 
101
 
 
102
/* Portable delay handling */
 
103
extern void pg_usleep(long microsec);
 
104
 
 
105
/* Portable SQL-like case-independent comparisons and conversions */
 
106
extern int      pg_strcasecmp(const char *s1, const char *s2);
 
107
extern int      pg_strncasecmp(const char *s1, const char *s2, size_t n);
 
108
extern unsigned char pg_toupper(unsigned char ch);
 
109
extern unsigned char pg_tolower(unsigned char ch);
 
110
 
 
111
/* Portable prompt handling */
 
112
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
 
113
 
 
114
/*
 
115
 *      WIN32 doesn't allow descriptors returned by pipe() to be used in select(),
 
116
 *      so for that platform we use socket() instead of pipe().
 
117
 *      There is some inconsistency here because sometimes we require pg*, like
 
118
 *      pgpipe, but in other cases we define rename to pgrename just on Win32.
 
119
 */
 
120
#ifndef WIN32
 
121
#define pgpipe(a)                       pipe(a)
 
122
#define piperead(a,b,c)         read(a,b,c)
 
123
#define pipewrite(a,b,c)        write(a,b,c)
 
124
#else
 
125
extern int      pgpipe(int handles[2]);
 
126
extern int      piperead(int s, char *buf, int len);
 
127
 
 
128
#define pipewrite(a,b,c)        send(a,b,c,0)
 
129
 
 
130
#define PG_SIGNAL_COUNT 32
 
131
#define kill(pid,sig)   pgkill(pid,sig)
 
132
extern int      pgkill(int pid, int sig);
 
133
#endif
 
134
 
 
135
extern int      pclose_check(FILE *stream);
 
136
 
 
137
/* Global variable holding time zone information. */
 
138
#ifndef __CYGWIN__
 
139
#define TIMEZONE_GLOBAL timezone
 
140
#define TZNAME_GLOBAL tzname
 
141
#else
 
142
#define TIMEZONE_GLOBAL _timezone
 
143
#define TZNAME_GLOBAL _tzname
 
144
#endif
 
145
 
 
146
#if defined(WIN32) || defined(__CYGWIN__)
 
147
/*
 
148
 *      Win32 doesn't have reliable rename/unlink during concurrent access,
 
149
 *      and we need special code to do symlinks.
 
150
 */
 
151
extern int      pgrename(const char *from, const char *to);
 
152
extern int      pgunlink(const char *path);
 
153
/* Include this first so later includes don't see these defines */
 
154
#ifdef WIN32_CLIENT_ONLY
 
155
#include <io.h>
 
156
#endif
 
157
 
 
158
#define rename(from, to)                pgrename(from, to)
 
159
#define unlink(path)                    pgunlink(path)
 
160
 
 
161
/*
 
162
 *      Cygwin has its own symlinks which work on Win95/98/ME where
 
163
 *      junction points don't, so use it instead.  We have no way of
 
164
 *      knowing what type of system Cygwin binaries will be run on.
 
165
 *      Note: Some CYGWIN includes might #define WIN32.
 
166
 */
 
167
#if defined(WIN32) && !defined(__CYGWIN__)
 
168
extern int      pgsymlink(const char *oldpath, const char *newpath);
 
169
#define symlink(oldpath, newpath)       pgsymlink(oldpath, newpath)
 
170
#endif
 
171
 
 
172
#endif /* defined(WIN32) || defined(__CYGWIN__) */
 
173
 
 
174
extern bool rmtree(char *path, bool rmtopdir);
 
175
 
 
176
#if defined(WIN32) && !defined(__CYGWIN__)
 
177
 
 
178
/* open() replacement to allow delete of held files and passing
 
179
 * of special options. */
 
180
#ifndef WIN32_CLIENT_ONLY
 
181
extern int      win32_open(const char *, int,...);
 
182
 
 
183
#define         open(a,b,...)   win32_open(a,b,##__VA_ARGS__)
 
184
#endif
 
185
 
 
186
#ifndef __BORLANDC__
 
187
#define popen(a,b) _popen(a,b)
 
188
#define pclose(a) _pclose(a)
 
189
#endif
 
190
 
 
191
extern int      copydir(char *fromdir, char *todir);
 
192
 
 
193
/* Missing rand functions */
 
194
extern long lrand48(void);
 
195
extern void srand48(long seed);
 
196
 
 
197
/* Last parameter not used */
 
198
extern int      gettimeofday(struct timeval * tp, struct timezone * tzp);
 
199
 
 
200
#else /* !WIN32 */
 
201
 
 
202
/*
 
203
 *      Win32 requires a special close for sockets and pipes, while on Unix
 
204
 *      close() does them all.
 
205
 */
 
206
#define closesocket close
 
207
#endif /* WIN32 */
 
208
 
 
209
/*
 
210
 * Default "extern" declarations or macro substitutes for library routines.
 
211
 * When necessary, these routines are provided by files in src/port/.
 
212
 */
 
213
#ifndef HAVE_CRYPT
 
214
extern char *crypt(const char *key, const char *setting);
 
215
#endif
 
216
 
 
217
#if defined(bsdi) || defined(netbsd)
 
218
extern int      fseeko(FILE *stream, off_t offset, int whence);
 
219
extern off_t ftello(FILE *stream);
 
220
#endif
 
221
 
 
222
#ifndef HAVE_FSEEKO
 
223
#define fseeko(a, b, c) fseek((a), (b), (c))
 
224
#define ftello(a) ftell((a))
 
225
#endif
 
226
 
 
227
#ifndef HAVE_GETOPT
 
228
extern int      getopt(int nargc, char *const * nargv, const char *ostr);
 
229
#endif
 
230
 
 
231
#ifndef HAVE_ISINF
 
232
extern int      isinf(double x);
 
233
#endif
 
234
 
 
235
#if !defined(HAVE_GETHOSTNAME) && defined(KRB4)
 
236
extern int      gethostname(char *name, int namelen);
 
237
#endif
 
238
 
 
239
#ifndef HAVE_RINT
 
240
extern double rint(double x);
 
241
#endif
 
242
 
 
243
#ifndef HAVE_INET_ATON
 
244
#ifndef WIN32_CLIENT_ONLY
 
245
#include <netinet/in.h>
 
246
#include <arpa/inet.h>
 
247
#endif
 
248
extern int      inet_aton(const char *cp, struct in_addr * addr);
 
249
#endif
 
250
 
 
251
#ifndef HAVE_STRDUP
 
252
extern char *strdup(char const *);
 
253
#endif
 
254
 
 
255
#ifndef HAVE_RANDOM
 
256
extern long random(void);
 
257
#endif
 
258
 
 
259
#ifndef HAVE_UNSETENV
 
260
extern void unsetenv(const char *name);
 
261
#endif
 
262
 
 
263
#ifndef HAVE_SRANDOM
 
264
extern void srandom(unsigned int seed);
 
265
#endif
 
266
 
 
267
/* thread.h */
 
268
extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
 
269
 
 
270
#if !defined(WIN32) || defined(__CYGWIN__)
 
271
extern int pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
 
272
                   size_t buflen, struct passwd ** result);
 
273
#endif
 
274
 
 
275
extern int pqGethostbyname(const char *name,
 
276
                                struct hostent * resultbuf,
 
277
                                char *buffer, size_t buflen,
 
278
                                struct hostent ** result,
 
279
                                int *herrno);