2003-05-15 18:35:30 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* port.h
|
2004-11-06 02:16:22 +01:00
|
|
|
* Header for src/port/ compatibility functions.
|
2003-05-15 18:35:30 +02:00
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2003-05-15 18:35:30 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2005-07-05 19:24:30 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/port.h,v 1.78 2005/07/05 17:24:30 momjian Exp $
|
2003-05-15 18:35:30 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2004-09-28 01:24:45 +02:00
|
|
|
#ifndef WIN32_CLIENT_ONLY
|
2003-06-14 16:35:42 +02:00
|
|
|
/* for thread.c */
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <netdb.h>
|
2003-06-24 02:44:29 +02:00
|
|
|
#endif
|
2004-09-28 01:24:45 +02:00
|
|
|
|
2004-05-20 03:47:01 +02:00
|
|
|
#include <ctype.h>
|
2003-06-14 16:35:42 +02:00
|
|
|
|
2004-03-10 22:12:49 +01:00
|
|
|
/* non-blocking */
|
2005-03-25 01:34:31 +01:00
|
|
|
extern bool pg_set_noblock(int sock);
|
|
|
|
extern bool pg_set_block(int sock);
|
2004-03-10 22:12:49 +01:00
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
/* Portable path handling for Unix/Win32 */
|
2004-06-11 00:26:24 +02:00
|
|
|
|
|
|
|
extern char *first_dir_separator(const char *filename);
|
|
|
|
extern char *last_dir_separator(const char *filename);
|
2004-11-06 02:16:22 +01:00
|
|
|
extern char *first_path_separator(const char *pathlist);
|
|
|
|
extern void join_path_components(char *ret_path,
|
|
|
|
const char *head, const char *tail);
|
2004-03-09 05:49:02 +01:00
|
|
|
extern void canonicalize_path(char *path);
|
2004-08-12 20:32:52 +02:00
|
|
|
extern void make_native_path(char *path);
|
2004-05-12 15:38:49 +02:00
|
|
|
extern const char *get_progname(const char *argv0);
|
2004-05-17 16:35:34 +02:00
|
|
|
extern void get_share_path(const char *my_exec_path, char *ret_path);
|
|
|
|
extern void get_etc_path(const char *my_exec_path, char *ret_path);
|
|
|
|
extern void get_include_path(const char *my_exec_path, char *ret_path);
|
|
|
|
extern void get_pkginclude_path(const char *my_exec_path, char *ret_path);
|
2004-08-01 08:56:39 +02:00
|
|
|
extern void get_includeserver_path(const char *my_exec_path, char *ret_path);
|
|
|
|
extern void get_lib_path(const char *my_exec_path, char *ret_path);
|
2004-05-17 16:35:34 +02:00
|
|
|
extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
|
2004-05-25 03:00:30 +02:00
|
|
|
extern void get_locale_path(const char *my_exec_path, char *ret_path);
|
2004-06-03 02:07:38 +02:00
|
|
|
extern void set_pglocale_pgservice(const char *argv0, const char *app);
|
2004-08-18 04:59:12 +02:00
|
|
|
extern bool get_home_path(char *ret_path);
|
2004-08-29 23:08:48 +02:00
|
|
|
extern void get_parent_directory(char *path);
|
2004-05-17 16:35:34 +02:00
|
|
|
|
2004-05-19 06:21:49 +02:00
|
|
|
/*
|
|
|
|
* is_absolute_path
|
|
|
|
*
|
2004-11-08 17:34:23 +01:00
|
|
|
* By making this a macro we prevent the need for libpq to include
|
|
|
|
* path.c which uses exec.c.
|
2004-05-19 06:21:49 +02:00
|
|
|
*/
|
|
|
|
#ifndef WIN32
|
|
|
|
#define is_absolute_path(filename) \
|
|
|
|
( \
|
|
|
|
((filename)[0] == '/') \
|
|
|
|
)
|
|
|
|
#else
|
|
|
|
#define is_absolute_path(filename) \
|
|
|
|
( \
|
|
|
|
((filename)[0] == '/') || \
|
|
|
|
(filename)[0] == '\\' || \
|
|
|
|
(isalpha((filename)[0]) && (filename)[1] == ':' && \
|
|
|
|
((filename)[2] == '\\' || (filename)[2] == '/')) \
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-05-11 23:57:15 +02:00
|
|
|
/* Portable way to find binaries */
|
2004-08-29 07:07:03 +02:00
|
|
|
extern int find_my_exec(const char *argv0, char *retpath);
|
2004-05-21 18:06:23 +02:00
|
|
|
extern int find_other_exec(const char *argv0, const char *target,
|
2004-08-29 07:07:03 +02:00
|
|
|
const char *versionstr, char *retpath);
|
|
|
|
|
2004-08-07 23:48:09 +02:00
|
|
|
#if defined(WIN32) || defined(__CYGWIN__)
|
2004-05-11 23:57:15 +02:00
|
|
|
#define EXE ".exe"
|
|
|
|
#else
|
|
|
|
#define EXE ""
|
2004-11-17 18:46:24 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
|
|
|
#define DEVNULL "nul"
|
|
|
|
#else
|
2004-05-11 23:57:15 +02:00
|
|
|
#define DEVNULL "/dev/null"
|
|
|
|
#endif
|
|
|
|
|
2004-06-10 18:35:18 +02:00
|
|
|
/*
|
|
|
|
* Win32 needs double quotes at the beginning and end of system()
|
|
|
|
* strings. If not, it gets confused with multiple quoted strings.
|
2004-08-09 04:12:51 +02:00
|
|
|
* It also requires double-quotes around the executable name and
|
|
|
|
* any files used for redirection. Other args can use single-quotes.
|
2004-06-11 18:10:09 +02:00
|
|
|
*
|
|
|
|
* See the "Notes" section about quotes at:
|
|
|
|
* http://home.earthlink.net/~rlively/MANUALS/COMMANDS/C/CMD.HTM
|
2004-06-10 18:35:18 +02:00
|
|
|
*/
|
2004-11-17 18:46:24 +01:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
2004-06-10 18:35:18 +02:00
|
|
|
#define SYSTEMQUOTE "\""
|
|
|
|
#else
|
|
|
|
#define SYSTEMQUOTE ""
|
|
|
|
#endif
|
|
|
|
|
2004-02-10 04:42:45 +01:00
|
|
|
/* Portable delay handling */
|
|
|
|
extern void pg_usleep(long microsec);
|
|
|
|
|
2004-05-07 02:24:59 +02:00
|
|
|
/* Portable SQL-like case-independent comparisons and conversions */
|
|
|
|
extern int pg_strcasecmp(const char *s1, const char *s2);
|
|
|
|
extern int pg_strncasecmp(const char *s1, const char *s2, size_t n);
|
|
|
|
extern unsigned char pg_toupper(unsigned char ch);
|
|
|
|
extern unsigned char pg_tolower(unsigned char ch);
|
|
|
|
|
2005-07-04 21:54:51 +02:00
|
|
|
#if defined(USE_SNPRINTF) && !defined(NO_PGPORT)
|
2005-03-11 18:20:35 +01:00
|
|
|
extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
|
|
|
extern int pg_snprintf(char *str, size_t count, const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
|
|
|
__attribute__((format(printf, 3, 4)));
|
2005-03-16 22:27:23 +01:00
|
|
|
extern int pg_sprintf(char *str, const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
|
|
|
__attribute__((format(printf, 2, 3)));
|
2005-03-11 20:13:43 +01:00
|
|
|
extern int pg_fprintf(FILE *stream, const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
|
|
|
__attribute__((format(printf, 2, 3)));
|
2005-03-11 18:20:35 +01:00
|
|
|
extern int pg_printf(const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
|
|
|
__attribute__((format(printf, 1, 2)));
|
|
|
|
|
2005-03-11 20:13:43 +01:00
|
|
|
/*
|
|
|
|
* The GCC-specific code below prevents the __attribute__(... 'printf')
|
|
|
|
* above from being replaced, and this is required because gcc doesn't
|
|
|
|
* know anything about pg_printf.
|
|
|
|
*/
|
2005-03-11 18:20:35 +01:00
|
|
|
#ifdef __GNUC__
|
2005-03-11 20:13:43 +01:00
|
|
|
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
|
2005-03-11 18:20:35 +01:00
|
|
|
#define snprintf(...) pg_snprintf(__VA_ARGS__)
|
2005-03-16 22:27:23 +01:00
|
|
|
#define sprintf(...) pg_sprintf(__VA_ARGS__)
|
2005-03-11 20:13:43 +01:00
|
|
|
#define fprintf(...) pg_fprintf(__VA_ARGS__)
|
2005-03-11 18:20:35 +01:00
|
|
|
#define printf(...) pg_printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define vsnprintf pg_vsnprintf
|
|
|
|
#define snprintf pg_snprintf
|
2005-03-16 22:27:23 +01:00
|
|
|
#define sprintf pg_sprintf
|
2005-03-11 20:13:43 +01:00
|
|
|
#define fprintf pg_fprintf
|
2005-03-11 18:20:35 +01:00
|
|
|
#define printf pg_printf
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-02-10 04:42:45 +01:00
|
|
|
/* Portable prompt handling */
|
2003-08-08 06:52:22 +02:00
|
|
|
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
|
2003-05-15 18:35:30 +02:00
|
|
|
|
2004-04-05 05:16:21 +02:00
|
|
|
/*
|
|
|
|
* WIN32 doesn't allow descriptors returned by pipe() to be used in select(),
|
|
|
|
* so for that platform we use socket() instead of pipe().
|
2004-08-17 16:38:38 +02:00
|
|
|
* There is some inconsistency here because sometimes we require pg*, like
|
|
|
|
* pgpipe, but in other cases we define rename to pgrename just on Win32.
|
2004-04-05 05:16:21 +02:00
|
|
|
*/
|
|
|
|
#ifndef WIN32
|
|
|
|
#define pgpipe(a) pipe(a)
|
|
|
|
#define piperead(a,b,c) read(a,b,c)
|
|
|
|
#define pipewrite(a,b,c) write(a,b,c)
|
|
|
|
#else
|
2004-08-29 07:07:03 +02:00
|
|
|
extern int pgpipe(int handles[2]);
|
|
|
|
extern int piperead(int s, char *buf, int len);
|
|
|
|
|
2004-04-05 05:16:21 +02:00
|
|
|
#define pipewrite(a,b,c) send(a,b,c,0)
|
2004-05-27 16:39:33 +02:00
|
|
|
|
|
|
|
#define PG_SIGNAL_COUNT 32
|
2004-08-29 07:07:03 +02:00
|
|
|
#define kill(pid,sig) pgkill(pid,sig)
|
|
|
|
extern int pgkill(int pid, int sig);
|
2004-04-05 05:16:21 +02:00
|
|
|
#endif
|
2004-05-27 16:39:33 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
extern int pclose_check(FILE *stream);
|
2004-04-05 05:16:21 +02:00
|
|
|
|
2004-09-09 16:18:20 +02:00
|
|
|
/* Global variable holding time zone information. */
|
|
|
|
#ifndef __CYGWIN__
|
|
|
|
#define TIMEZONE_GLOBAL timezone
|
|
|
|
#define TZNAME_GLOBAL tzname
|
|
|
|
#else
|
|
|
|
#define TIMEZONE_GLOBAL _timezone
|
|
|
|
#define TZNAME_GLOBAL _tzname
|
|
|
|
#endif
|
|
|
|
|
2005-07-05 19:24:30 +02:00
|
|
|
#if (defined(WIN32) || defined(__CYGWIN__)) && !defined(NO_PGPORT)
|
2003-05-15 18:35:30 +02:00
|
|
|
/*
|
2004-08-07 23:48:09 +02:00
|
|
|
* Win32 doesn't have reliable rename/unlink during concurrent access,
|
|
|
|
* and we need special code to do symlinks.
|
2003-05-15 18:35:30 +02:00
|
|
|
*/
|
2003-08-08 23:42:59 +02:00
|
|
|
extern int pgrename(const char *from, const char *to);
|
|
|
|
extern int pgunlink(const char *path);
|
2004-09-27 22:37:20 +02:00
|
|
|
/* Include this first so later includes don't see these defines */
|
2004-09-28 01:24:45 +02:00
|
|
|
#ifdef WIN32_CLIENT_ONLY
|
2004-09-27 22:37:20 +02:00
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2004-08-07 23:48:09 +02:00
|
|
|
#define rename(from, to) pgrename(from, to)
|
|
|
|
#define unlink(path) pgunlink(path)
|
2004-10-12 00:50:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cygwin has its own symlinks which work on Win95/98/ME where
|
|
|
|
* junction points don't, so use it instead. We have no way of
|
|
|
|
* knowing what type of system Cygwin binaries will be run on.
|
2004-11-17 18:46:24 +01:00
|
|
|
* Note: Some CYGWIN includes might #define WIN32.
|
2004-10-12 00:50:48 +02:00
|
|
|
*/
|
2004-11-17 18:46:24 +01:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
2004-10-12 00:50:48 +02:00
|
|
|
extern int pgsymlink(const char *oldpath, const char *newpath);
|
2004-08-07 23:48:09 +02:00
|
|
|
#define symlink(oldpath, newpath) pgsymlink(oldpath, newpath)
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
2005-07-05 19:24:30 +02:00
|
|
|
#endif /* defined(WIN32) || defined(__CYGWIN__) && !defined(NO_PGPORT) */
|
2004-10-12 00:50:48 +02:00
|
|
|
|
2004-08-01 08:19:26 +02:00
|
|
|
extern bool rmtree(char *path, bool rmtopdir);
|
|
|
|
|
2005-07-05 19:24:30 +02:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(NO_PGPORT)
|
2004-03-24 04:54:16 +01:00
|
|
|
|
2005-02-27 01:53:29 +01:00
|
|
|
/* open() replacement to allow delete of held files and passing
|
|
|
|
* of special options. */
|
2004-09-28 01:24:45 +02:00
|
|
|
#ifndef WIN32_CLIENT_ONLY
|
2004-08-29 07:07:03 +02:00
|
|
|
extern int win32_open(const char *, int,...);
|
|
|
|
|
|
|
|
#define open(a,b,...) win32_open(a,b,##__VA_ARGS__)
|
2004-04-05 05:16:21 +02:00
|
|
|
#endif
|
2004-03-24 04:54:16 +01:00
|
|
|
|
2004-04-19 19:42:59 +02:00
|
|
|
#ifndef __BORLANDC__
|
|
|
|
#define popen(a,b) _popen(a,b)
|
|
|
|
#define pclose(a) _pclose(a)
|
|
|
|
#endif
|
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
extern int copydir(char *fromdir, char *todir);
|
|
|
|
|
Briefly,
* configure + Makefile changes
* shared memory attaching in EXEC_BACKEND case (+ minor fix for apparent
cygwin bug under cygwin/EXEC_BACKEND case only)
* PATH env var separator differences
* missing win32 rand functions added
* placeholder replacements for sync etc under port.h
To those who are really interested, and there are a few of you: the attached
patch + file will allow the source base to be compiled (and, for some
definition, "run") under MingW, with the following caveats (I wanted to
first properly fix all but the last of these, but y'all won't quit asking
for a patch :-):
* child death: SIGCHLD not yet sent, so as a minimum, you'll need to
put in some sort of delay after StartupDatabase, and handle setting
StartupPID to 0 etc (ie. the stuff the reaper() signal function is supposed
to do)
* dirmod.c: comment out the elog calls
* dfmgr.c: some hackage required to substitute_libpath_macro
* slru/xact.c: comment out the errno checking after the readdir
(fixed by next version of MingW)
Again, this is only if you *really* want to see postgres compile and start,
and is a nice leg-up for working on the other Win32 TODO list items. Just
don't expect too much else from it at this point...
Claudio Natoli
2004-02-02 01:11:31 +01:00
|
|
|
/* Missing rand functions */
|
2004-08-29 07:07:03 +02:00
|
|
|
extern long lrand48(void);
|
|
|
|
extern void srand48(long seed);
|
Briefly,
* configure + Makefile changes
* shared memory attaching in EXEC_BACKEND case (+ minor fix for apparent
cygwin bug under cygwin/EXEC_BACKEND case only)
* PATH env var separator differences
* missing win32 rand functions added
* placeholder replacements for sync etc under port.h
To those who are really interested, and there are a few of you: the attached
patch + file will allow the source base to be compiled (and, for some
definition, "run") under MingW, with the following caveats (I wanted to
first properly fix all but the last of these, but y'all won't quit asking
for a patch :-):
* child death: SIGCHLD not yet sent, so as a minimum, you'll need to
put in some sort of delay after StartupDatabase, and handle setting
StartupPID to 0 etc (ie. the stuff the reaper() signal function is supposed
to do)
* dirmod.c: comment out the elog calls
* dfmgr.c: some hackage required to substitute_libpath_macro
* slru/xact.c: comment out the errno checking after the readdir
(fixed by next version of MingW)
Again, this is only if you *really* want to see postgres compile and start,
and is a nice leg-up for working on the other Win32 TODO list items. Just
don't expect too much else from it at this point...
Claudio Natoli
2004-02-02 01:11:31 +01:00
|
|
|
|
2003-05-16 06:59:24 +02:00
|
|
|
/* Last parameter not used */
|
2003-08-04 02:43:34 +02:00
|
|
|
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
|
2003-05-16 03:57:52 +02:00
|
|
|
|
2004-11-06 02:16:22 +01:00
|
|
|
#else /* !WIN32 */
|
2003-05-16 03:57:52 +02:00
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
/*
|
|
|
|
* Win32 requires a special close for sockets and pipes, while on Unix
|
|
|
|
* close() does them all.
|
|
|
|
*/
|
2003-08-04 02:43:34 +02:00
|
|
|
#define closesocket close
|
2004-11-06 02:16:22 +01:00
|
|
|
#endif /* WIN32 */
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
/*
|
|
|
|
* Default "extern" declarations or macro substitutes for library routines.
|
|
|
|
* When necessary, these routines are provided by files in src/port/.
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_CRYPT
|
2003-05-16 03:57:52 +02:00
|
|
|
extern char *crypt(const char *key, const char *setting);
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
2004-11-06 02:16:22 +01:00
|
|
|
#if defined(bsdi) || defined(netbsd)
|
|
|
|
extern int fseeko(FILE *stream, off_t offset, int whence);
|
|
|
|
extern off_t ftello(FILE *stream);
|
|
|
|
#endif
|
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
#ifndef HAVE_FSEEKO
|
2005-05-25 23:40:43 +02:00
|
|
|
#define fseeko(a, b, c) fseek(a, b, c)
|
|
|
|
#define ftello(a) ftell(a)
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_GETOPT
|
2003-08-04 02:43:34 +02:00
|
|
|
extern int getopt(int nargc, char *const * nargv, const char *ostr);
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ISINF
|
2003-08-04 02:43:34 +02:00
|
|
|
extern int isinf(double x);
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_RINT
|
|
|
|
extern double rint(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_INET_ATON
|
2004-09-28 01:24:45 +02:00
|
|
|
#ifndef WIN32_CLIENT_ONLY
|
2003-08-04 02:43:34 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2003-06-12 10:15:29 +02:00
|
|
|
#endif
|
2003-08-04 02:43:34 +02:00
|
|
|
extern int inet_aton(const char *cp, struct in_addr * addr);
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
|
|
|
extern char *strdup(char const *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_RANDOM
|
|
|
|
extern long random(void);
|
|
|
|
#endif
|
|
|
|
|
2004-05-07 02:24:59 +02:00
|
|
|
#ifndef HAVE_UNSETENV
|
|
|
|
extern void unsetenv(const char *name);
|
|
|
|
#endif
|
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
#ifndef HAVE_SRANDOM
|
|
|
|
extern void srandom(unsigned int seed);
|
|
|
|
#endif
|
2003-06-14 16:35:42 +02:00
|
|
|
|
|
|
|
/* thread.h */
|
|
|
|
extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
|
|
|
|
|
2004-11-17 18:46:24 +01:00
|
|
|
#if !defined(WIN32) || defined(__CYGWIN__)
|
2003-08-04 02:43:34 +02:00
|
|
|
extern int pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
|
2004-08-29 07:07:03 +02:00
|
|
|
size_t buflen, struct passwd ** result);
|
2003-09-05 19:43:40 +02:00
|
|
|
#endif
|
2003-06-14 16:35:42 +02:00
|
|
|
|
|
|
|
extern int pqGethostbyname(const char *name,
|
2004-08-29 07:07:03 +02:00
|
|
|
struct hostent * resultbuf,
|
2003-09-13 16:49:51 +02:00
|
|
|
char *buffer, size_t buflen,
|
2004-08-29 07:07:03 +02:00
|
|
|
struct hostent ** result,
|
2003-08-04 02:43:34 +02:00
|
|
|
int *herrno);
|