1 /*-------------------------------------------------------------------------
4 * Header for /port compatibility functions.
6 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * $PostgreSQL: pgsql/src/include/port.h,v 1.26 2004/04/30 04:14:05 momjian Exp $
11 *-------------------------------------------------------------------------
14 #if !defined(_MSC_VER) && !defined(__BORLANDC__)
21 bool set_noblock(int sock);
23 /* Portable path handling for Unix/Win32 */
24 extern bool is_absolute_path(const char *filename);
25 extern char *first_path_separator(const char *filename);
26 extern char *last_path_separator(const char *filename);
27 extern void canonicalize_path(char *path);
28 extern char *get_progname(char *argv0);
30 /* Portable delay handling */
31 extern void pg_usleep(long microsec);
33 /* Portable prompt handling */
34 extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
36 #if defined(bsdi) || defined(netbsd)
37 extern int fseeko(FILE *stream, off_t offset, int whence);
38 extern off_t ftello(FILE *stream);
42 * WIN32 doesn't allow descriptors returned by pipe() to be used in select(),
43 * so for that platform we use socket() instead of pipe().
46 #define pgpipe(a) pipe(a)
47 #define piperead(a,b,c) read(a,b,c)
48 #define pipewrite(a,b,c) write(a,b,c)
50 extern int pgpipe(int handles[2]);
51 extern int piperead(int s, char* buf, int len);
52 #define pipewrite(a,b,c) send(a,b,c,0)
55 #if defined(__MINGW32__) || defined(__CYGWIN__)
57 * Win32 doesn't have reliable rename/unlink during concurrent access
59 extern int pgrename(const char *from, const char *to);
60 extern int pgunlink(const char *path);
61 #define rename(from, to) pgrename(from, to)
62 #define unlink(path) pgunlink(path)
67 /* open() replacement to allow delete of held files */
69 extern int win32_open(const char*,int,...);
70 #define open(a,b,...) win32_open(a,b,##__VA_ARGS__)
74 #define popen(a,b) _popen(a,b)
75 #define pclose(a) _pclose(a)
78 extern int copydir(char *fromdir, char *todir);
80 /* Missing rand functions */
81 extern long lrand48(void);
82 extern void srand48(long seed);
84 /* Last parameter not used */
85 extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
90 * Win32 requires a special close for sockets and pipes, while on Unix
91 * close() does them all.
93 #define closesocket close
97 * Default "extern" declarations or macro substitutes for library routines.
98 * When necessary, these routines are provided by files in src/port/.
101 extern char *crypt(const char *key, const char *setting);
105 #define fseeko(a, b, c) fseek((a), (b), (c))
106 #define ftello(a) ftell((a))
110 extern int getopt(int nargc, char *const * nargv, const char *ostr);
114 extern int isinf(double x);
117 #if !defined(HAVE_GETHOSTNAME) && defined(KRB4)
118 extern int gethostname(char *name, int namelen);
122 extern double rint(double x);
125 #ifndef HAVE_INET_ATON
126 #if !defined(_MSC_VER) && !defined(__BORLANDC__)
127 #include <netinet/in.h>
128 #include <arpa/inet.h>
130 extern int inet_aton(const char *cp, struct in_addr * addr);
133 #ifndef HAVE_STRCASECMP
134 extern int strcasecmp(char *s1, char *s2);
138 extern char *strdup(char const *);
142 extern long random(void);
146 extern void srandom(unsigned int seed);
150 extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
153 extern int pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
154 size_t buflen, struct passwd **result);
157 extern int pqGethostbyname(const char *name,
158 struct hostent *resultbuf,
159 char *buffer, size_t buflen,
160 struct hostent **result,
163 /* $PATH (or %PATH%) path separator */
170 /* FIXME: [win32] Placeholder win32 replacements, to allow continued development */
172 #define fsync(a) _commit(a)
173 #define sync() _flushall()
174 #define ftruncate(a,b) chsize(a,b)
175 #define WEXITSTATUS(w) (((w) >> 8) & 0xff)
176 #define WIFEXITED(w) (((w) & 0xff) == 0)
177 #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
178 #define WTERMSIG(w) ((w) & 0x7f)
182 * Internal timezone library
194 #define localtime(timep) pg_localtime(timep)
195 #define gmtime(timep) pg_gmtime(timep)
196 #define asctime(timep) pg_asctime(timep)
197 #define ctime(timep) pg_ctime(timep)
198 #define difftime(t1,t2) pg_difftime(t1,t2)
199 #define mktime(tm) pg_mktime(tm)
200 #define tzset pg_tzset
203 extern struct tm *pg_localtime(const time_t *);
204 extern struct tm *gg_gmtime(const time_t *);
205 extern char *pg_asctime(const struct tm *);
206 extern char *pg_ctime(const time_t *);
207 extern double pg_difftime(const time_t, const time_t);
208 extern time_t pg_mktime(struct tm *);
209 extern void pg_tzset(void);
210 extern time_t pg_timezone;