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