]> granicus.if.org Git - postgresql/blob - src/include/port.h
More timezone build adjustments.
[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.27 2004/04/30 17:52:07 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
20 /* non-blocking */
21 bool set_noblock(int sock);
22
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);
29
30 /* Portable delay handling */
31 extern void pg_usleep(long microsec);
32
33 /* Portable prompt handling */
34 extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
35
36 #if defined(bsdi) || defined(netbsd)
37 extern int      fseeko(FILE *stream, off_t offset, int whence);
38 extern off_t ftello(FILE *stream);
39 #endif
40
41 /*
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().
44  */
45 #ifndef WIN32
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)
49 #else
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)
53 #endif
54
55 #if defined(__MINGW32__) || defined(__CYGWIN__)
56 /*
57  * Win32 doesn't have reliable rename/unlink during concurrent access
58  */
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)
63 #endif
64
65 #ifdef WIN32
66
67 /* open() replacement to allow delete of held files */
68 #ifndef _MSC_VER
69 extern int      win32_open(const char*,int,...);
70 #define         open(a,b,...)   win32_open(a,b,##__VA_ARGS__)
71 #endif
72
73 #ifndef __BORLANDC__
74 #define popen(a,b) _popen(a,b)
75 #define pclose(a) _pclose(a)
76 #endif
77
78 extern int      copydir(char *fromdir, char *todir);
79
80 /* Missing rand functions */
81 extern long     lrand48(void);
82 extern void     srand48(long seed);
83
84 /* Last parameter not used */
85 extern int      gettimeofday(struct timeval * tp, struct timezone * tzp);
86
87 #else
88
89 /*
90  *      Win32 requires a special close for sockets and pipes, while on Unix
91  *      close() does them all.
92  */
93 #define closesocket close
94 #endif
95
96 /*
97  * Default "extern" declarations or macro substitutes for library routines.
98  * When necessary, these routines are provided by files in src/port/.
99  */
100 #ifndef HAVE_CRYPT
101 extern char *crypt(const char *key, const char *setting);
102 #endif
103
104 #ifndef HAVE_FSEEKO
105 #define fseeko(a, b, c) fseek((a), (b), (c))
106 #define ftello(a) ftell((a))
107 #endif
108
109 #ifndef HAVE_GETOPT
110 extern int      getopt(int nargc, char *const * nargv, const char *ostr);
111 #endif
112
113 #ifndef HAVE_ISINF
114 extern int      isinf(double x);
115 #endif
116
117 #if !defined(HAVE_GETHOSTNAME) && defined(KRB4)
118 extern int      gethostname(char *name, int namelen);
119 #endif
120
121 #ifndef HAVE_RINT
122 extern double rint(double x);
123 #endif
124
125 #ifndef HAVE_INET_ATON
126 #if !defined(_MSC_VER) && !defined(__BORLANDC__)
127 #include <netinet/in.h>
128 #include <arpa/inet.h>
129 #endif
130 extern int      inet_aton(const char *cp, struct in_addr * addr);
131 #endif
132
133 #ifndef HAVE_STRCASECMP
134 extern int      strcasecmp(char *s1, char *s2);
135 #endif
136
137 #ifndef HAVE_STRDUP
138 extern char *strdup(char const *);
139 #endif
140
141 #ifndef HAVE_RANDOM
142 extern long random(void);
143 #endif
144
145 #ifndef HAVE_SRANDOM
146 extern void srandom(unsigned int seed);
147 #endif
148
149 /* thread.h */
150 extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
151
152 #ifndef WIN32
153 extern int pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
154                    size_t buflen, struct passwd **result);
155 #endif
156
157 extern int pqGethostbyname(const char *name,
158                                 struct hostent *resultbuf,
159                                 char *buffer, size_t buflen,
160                                 struct hostent **result,
161                                 int *herrno);
162
163 /* $PATH (or %PATH%) path separator */
164 #ifdef WIN32
165 #define PATHSEP ';'
166 #else
167 #define PATHSEP ':'
168 #endif
169
170 /* FIXME: [win32] Placeholder win32 replacements, to allow continued development */
171 #ifdef WIN32
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)
179 #endif
180
181 /*
182  * Internal timezone library 
183  */
184 #ifdef USE_PGTZ
185 #ifndef FRONTEND
186 #undef localtime
187 #undef gmtime
188 #undef asctime
189 #undef ctime
190 #undef difftime
191 #undef mktime
192 #undef tzset
193
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
201
202
203 extern struct tm *pg_localtime(const time_t *);
204 extern struct tm *pg_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;
211
212 #endif
213 #endif