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