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
|
|
|
*
|
2011-01-01 19:18:15 +01:00
|
|
|
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
|
2003-05-15 18:35:30 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/port.h
|
2003-05-15 18:35:30 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2006-10-04 00:18:23 +02:00
|
|
|
#ifndef PG_PORT_H
|
|
|
|
#define PG_PORT_H
|
2003-05-15 18:35:30 +02:00
|
|
|
|
2004-05-20 03:47:01 +02:00
|
|
|
#include <ctype.h>
|
2006-09-11 22:10:30 +02:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <pwd.h>
|
2003-06-14 16:35:42 +02:00
|
|
|
|
2010-01-10 15:16:08 +01:00
|
|
|
/* socket has a different definition on WIN32 */
|
|
|
|
#ifndef WIN32
|
|
|
|
typedef int pgsocket;
|
2010-02-26 03:01:40 +01:00
|
|
|
|
2010-01-31 18:35:46 +01:00
|
|
|
#define PGINVALID_SOCKET (-1)
|
2010-01-10 15:16:08 +01:00
|
|
|
#else
|
|
|
|
typedef SOCKET pgsocket;
|
2010-02-26 03:01:40 +01:00
|
|
|
|
2010-01-10 15:16:08 +01:00
|
|
|
#define PGINVALID_SOCKET INVALID_SOCKET
|
|
|
|
#endif
|
|
|
|
|
2004-03-10 22:12:49 +01:00
|
|
|
/* non-blocking */
|
2010-01-10 15:16:08 +01:00
|
|
|
extern bool pg_set_noblock(pgsocket sock);
|
|
|
|
extern bool pg_set_block(pgsocket sock);
|
2004-03-10 22:12:49 +01:00
|
|
|
|
2006-09-11 22:10:30 +02:00
|
|
|
/* Portable path handling for Unix/Win32 (in path.c) */
|
2004-06-11 00:26:24 +02:00
|
|
|
|
2011-07-06 17:45:13 +02:00
|
|
|
extern bool has_drive_prefix(const char *filename);
|
2004-06-11 00:26:24 +02:00
|
|
|
extern char *first_dir_separator(const char *filename);
|
|
|
|
extern char *last_dir_separator(const char *filename);
|
2011-02-03 04:49:54 +01:00
|
|
|
extern char *first_path_var_separator(const char *pathlist);
|
2004-11-06 02:16:22 +01:00
|
|
|
extern void join_path_components(char *ret_path,
|
2005-10-15 04:49:52 +02:00
|
|
|
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);
|
2005-08-12 23:07:53 +02:00
|
|
|
extern bool path_contains_parent_reference(const char *path);
|
2011-02-12 15:47:51 +01:00
|
|
|
extern bool path_is_relative_and_below_cwd(const char *path);
|
2005-08-29 21:39:39 +02:00
|
|
|
extern bool path_is_prefix_of_path(const char *path1, const char *path2);
|
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);
|
2005-09-27 19:39:35 +02:00
|
|
|
extern void get_doc_path(const char *my_exec_path, char *ret_path);
|
2008-02-18 15:51:48 +01:00
|
|
|
extern void get_html_path(const char *my_exec_path, char *ret_path);
|
2005-09-27 19:39:35 +02:00
|
|
|
extern void get_man_path(const char *my_exec_path, char *ret_path);
|
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
|
|
|
|
2007-01-19 17:42:24 +01:00
|
|
|
/* port/dirmod.c */
|
2008-04-18 19:05:45 +02:00
|
|
|
extern char **pgfnames(const char *path);
|
2007-01-19 17:42:24 +01:00
|
|
|
extern void pgfnames_cleanup(char **filenames);
|
|
|
|
|
2004-05-19 06:21:49 +02:00
|
|
|
/*
|
|
|
|
* is_absolute_path
|
|
|
|
*
|
2006-09-11 22:10:30 +02:00
|
|
|
* By making this a macro we avoid needing to include path.c in libpq.
|
2004-05-19 06:21:49 +02:00
|
|
|
*/
|
|
|
|
#ifndef WIN32
|
2011-02-03 16:46:31 +01:00
|
|
|
#define IS_DIR_SEP(ch) ((ch) == '/')
|
|
|
|
|
2004-05-19 06:21:49 +02:00
|
|
|
#define is_absolute_path(filename) \
|
|
|
|
( \
|
2011-02-03 16:46:31 +01:00
|
|
|
IS_DIR_SEP((filename)[0]) \
|
2004-05-19 06:21:49 +02:00
|
|
|
)
|
|
|
|
#else
|
2011-02-03 16:46:31 +01:00
|
|
|
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
|
|
|
|
|
2011-02-12 15:47:51 +01:00
|
|
|
/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */
|
2004-05-19 06:21:49 +02:00
|
|
|
#define is_absolute_path(filename) \
|
|
|
|
( \
|
2011-02-03 16:46:31 +01:00
|
|
|
IS_DIR_SEP((filename)[0]) || \
|
2006-09-22 23:39:58 +02:00
|
|
|
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
|
2011-02-03 16:46:31 +01:00
|
|
|
IS_DIR_SEP((filename)[2])) \
|
2004-05-19 06:21:49 +02:00
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
2006-09-11 22:10:30 +02:00
|
|
|
/* Portable locale initialization (in exec.c) */
|
|
|
|
extern void set_pglocale_pgservice(const char *argv0, const char *app);
|
2004-05-19 06:21:49 +02:00
|
|
|
|
2006-09-11 22:10:30 +02:00
|
|
|
/* Portable way to find binaries (in exec.c) */
|
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);
|
|
|
|
|
2008-02-29 16:31:33 +01:00
|
|
|
/* Windows security token manipulation (in exec.c) */
|
|
|
|
#ifdef WIN32
|
2009-11-14 16:39:36 +01:00
|
|
|
extern BOOL AddUserToTokenDacl(HANDLE hToken);
|
2008-02-29 16:31:33 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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"
|
2006-03-05 06:33:12 +01:00
|
|
|
/* "con" does not work from the Msys 1.0.10 console (part of MinGW). */
|
2006-03-04 05:30:41 +01:00
|
|
|
#define DEVTTY "con"
|
2004-11-17 18:46:24 +01:00
|
|
|
#else
|
2004-05-11 23:57:15 +02:00
|
|
|
#define DEVNULL "/dev/null"
|
2006-03-04 05:30:41 +01:00
|
|
|
#define DEVTTY "/dev/tty"
|
2004-05-11 23:57:15 +02:00
|
|
|
#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
|
|
|
*
|
2006-08-18 17:47:08 +02:00
|
|
|
* Generated using Win32 "CMD /?":
|
2006-07-19 19:01:24 +02:00
|
|
|
*
|
2006-10-04 02:30:14 +02:00
|
|
|
* 1. If all of the following conditions are met, then quote characters
|
|
|
|
* on the command line are preserved:
|
2006-07-19 19:01:24 +02:00
|
|
|
*
|
2006-10-04 02:30:14 +02:00
|
|
|
* - no /S switch
|
|
|
|
* - exactly two quote characters
|
|
|
|
* - no special characters between the two quote characters, where special
|
|
|
|
* is one of: &<>()@^|
|
2010-04-24 01:21:44 +02:00
|
|
|
* - there are one or more whitespace characters between the two quote
|
2006-10-04 02:30:14 +02:00
|
|
|
* characters
|
|
|
|
* - the string between the two quote characters is the name of an
|
|
|
|
* executable file.
|
2006-07-19 19:01:24 +02:00
|
|
|
*
|
2006-10-04 02:30:14 +02:00
|
|
|
* 2. Otherwise, old behavior is to see if the first character is a quote
|
|
|
|
* character and if so, strip the leading character and remove the last
|
|
|
|
* quote character on the command line, preserving any text after the last
|
|
|
|
* quote character.
|
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);
|
2011-03-20 17:43:39 +01:00
|
|
|
extern unsigned char pg_ascii_toupper(unsigned char ch);
|
|
|
|
extern unsigned char pg_ascii_tolower(unsigned char ch);
|
2004-05-07 02:24:59 +02:00
|
|
|
|
2005-12-06 03:29:04 +01:00
|
|
|
#ifdef USE_REPL_SNPRINTF
|
|
|
|
|
|
|
|
/*
|
2005-12-06 19:35:10 +01:00
|
|
|
* Versions of libintl >= 0.13 try to replace printf() and friends with
|
2006-10-04 02:30:14 +02:00
|
|
|
* macros to their own versions that understand the %$ format. We do the
|
2005-12-06 19:35:10 +01:00
|
|
|
* same, so disable their macros, if they exist.
|
2005-12-06 03:29:04 +01:00
|
|
|
*/
|
|
|
|
#ifdef vsnprintf
|
|
|
|
#undef vsnprintf
|
|
|
|
#endif
|
|
|
|
#ifdef snprintf
|
|
|
|
#undef snprintf
|
|
|
|
#endif
|
|
|
|
#ifdef sprintf
|
|
|
|
#undef sprintf
|
|
|
|
#endif
|
2006-11-28 02:12:34 +01:00
|
|
|
#ifdef vfprintf
|
|
|
|
#undef vfprintf
|
|
|
|
#endif
|
2005-12-06 03:29:04 +01:00
|
|
|
#ifdef fprintf
|
|
|
|
#undef fprintf
|
|
|
|
#endif
|
|
|
|
#ifdef printf
|
|
|
|
#undef printf
|
|
|
|
#endif
|
2011-02-01 13:19:18 +01:00
|
|
|
/*
|
|
|
|
* Versions of libintl >= 0.18? try to replace setlocale() with a macro
|
|
|
|
* to their own versions. Remove the macro, if it exists, because it
|
|
|
|
* ends up calling the wrong version when the backend and libintl use
|
|
|
|
* different versions of msvcrt.
|
|
|
|
*/
|
|
|
|
#if defined(setlocale) && defined(WIN32)
|
|
|
|
#undef setlocale
|
|
|
|
#endif
|
2005-12-06 03:29:04 +01:00
|
|
|
|
2005-12-06 06:13:46 +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 */
|
2011-04-28 16:56:14 +02:00
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
2005-12-06 06:13:46 +01:00
|
|
|
extern int
|
|
|
|
pg_sprintf(char *str, const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
2011-04-28 16:56:14 +02:00
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
2007-11-15 22:14:46 +01:00
|
|
|
extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
|
2005-12-06 06:13:46 +01:00
|
|
|
extern int
|
|
|
|
pg_fprintf(FILE *stream, const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
2011-04-28 16:56:14 +02:00
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
2005-12-06 06:13:46 +01:00
|
|
|
extern int
|
|
|
|
pg_printf(const char *fmt,...)
|
|
|
|
/* This extension allows gcc to check the format string */
|
2011-04-28 16:56:14 +02:00
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
|
2005-12-06 06:13:46 +01:00
|
|
|
|
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-10-15 04:49:52 +02: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__)
|
2006-11-28 02:12:34 +01:00
|
|
|
#define vfprintf(...) pg_vfprintf(__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
|
2006-11-28 02:12:34 +01:00
|
|
|
#define vfprintf pg_vfprintf
|
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
|
2006-10-04 02:30:14 +02:00
|
|
|
#endif /* USE_REPL_SNPRINTF */
|
2005-03-11 18:20:35 +01:00
|
|
|
|
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
|
2006-07-11 15:54:25 +02:00
|
|
|
/*
|
|
|
|
* The function prototypes are not supplied because every C file
|
|
|
|
* includes this file.
|
|
|
|
*/
|
2004-04-05 05:16:21 +02:00
|
|
|
#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-06 23:40:09 +02:00
|
|
|
#if defined(WIN32) || defined(__CYGWIN__)
|
2003-05-15 18:35:30 +02:00
|
|
|
/*
|
2007-07-13 01:28:49 +02:00
|
|
|
* Win32 doesn't have reliable rename/unlink during concurrent access.
|
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);
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-09-27 22:37:20 +02:00
|
|
|
/* Include this first so later includes don't see these defines */
|
2006-06-08 00:24:46 +02:00
|
|
|
#ifdef WIN32_ONLY_COMPILER
|
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)
|
2007-07-13 01:28:49 +02:00
|
|
|
#endif /* defined(WIN32) || defined(__CYGWIN__) */
|
|
|
|
|
2004-10-12 00:50:48 +02:00
|
|
|
/*
|
2007-07-13 01:28:49 +02:00
|
|
|
* Win32 also doesn't have symlinks, but we can emulate them with
|
|
|
|
* junction points on newer Win32 versions.
|
|
|
|
*
|
2004-10-12 00:50:48 +02:00
|
|
|
* Cygwin has its own symlinks which work on Win95/98/ME where
|
2007-07-13 01:28:49 +02:00
|
|
|
* junction points don't, so use those instead. We have no way of
|
2004-10-12 00:50:48 +02:00
|
|
|
* knowing what type of system Cygwin binaries will be run on.
|
2005-10-15 04:49:52 +02: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);
|
2011-01-09 15:06:55 +01:00
|
|
|
extern int pgreadlink(const char *path, char *buf, size_t size);
|
|
|
|
extern bool pgwin32_is_junction(char *path);
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-08-07 23:48:09 +02:00
|
|
|
#define symlink(oldpath, newpath) pgsymlink(oldpath, newpath)
|
2011-01-09 15:06:55 +01:00
|
|
|
#define readlink(path, buf, size) pgreadlink(path, buf, size)
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
2004-10-12 00:50:48 +02:00
|
|
|
|
2008-04-18 19:05:45 +02:00
|
|
|
extern bool rmtree(const char *path, bool rmtopdir);
|
2004-08-01 08:19:26 +02:00
|
|
|
|
2009-06-11 16:49:15 +02:00
|
|
|
/*
|
2008-04-12 01:53:00 +02:00
|
|
|
* stat() is not guaranteed to set the st_size field on win32, so we
|
|
|
|
* redefine it to our own implementation that is.
|
|
|
|
*
|
|
|
|
* We must pull in sys/stat.h here so the system header definition
|
|
|
|
* goes in first, and we redefine that, and not the other way around.
|
2008-04-16 16:19:56 +02:00
|
|
|
*
|
|
|
|
* Some frontends don't need the size from stat, so if UNSAFE_STAT_OK
|
|
|
|
* is defined we don't bother with this.
|
2008-04-12 01:53:00 +02:00
|
|
|
*/
|
2008-04-16 16:19:56 +02:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(UNSAFE_STAT_OK)
|
2008-04-12 01:53:00 +02:00
|
|
|
#include <sys/stat.h>
|
2009-06-11 16:49:15 +02:00
|
|
|
extern int pgwin32_safestat(const char *path, struct stat * buf);
|
|
|
|
|
2008-04-12 01:53:00 +02:00
|
|
|
#define stat(a,b) pgwin32_safestat(a,b)
|
|
|
|
#endif
|
|
|
|
|
2005-07-06 23:40:09 +02:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
2004-03-24 04:54:16 +01:00
|
|
|
|
2008-04-12 01:53:00 +02:00
|
|
|
/*
|
|
|
|
* open() and fopen() replacements to allow deletion of open files and
|
2006-08-30 20:06:27 +02:00
|
|
|
* passing of other special options.
|
|
|
|
*/
|
2007-04-13 12:30:30 +02:00
|
|
|
#define O_DIRECT 0x80000000
|
2006-06-25 02:18:24 +02:00
|
|
|
extern int pgwin32_open(const char *, int,...);
|
2006-08-30 20:06:27 +02:00
|
|
|
extern FILE *pgwin32_fopen(const char *, const char *);
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2006-06-08 00:24:46 +02:00
|
|
|
#ifndef FRONTEND
|
2006-10-04 02:30:14 +02:00
|
|
|
#define open(a,b,c) pgwin32_open(a,b,c)
|
2006-08-30 20:06:27 +02:00
|
|
|
#define fopen(a,b) pgwin32_fopen(a,b)
|
2004-04-05 05:16:21 +02:00
|
|
|
#endif
|
2004-03-24 04:54:16 +01:00
|
|
|
|
2011-01-31 01:56:46 +01:00
|
|
|
#ifndef popen
|
2004-04-19 19:42:59 +02:00
|
|
|
#define popen(a,b) _popen(a,b)
|
2011-01-31 01:56:46 +01:00
|
|
|
#endif
|
|
|
|
#ifndef pclose
|
2004-04-19 19:42:59 +02:00
|
|
|
#define pclose(a) _pclose(a)
|
2011-01-31 01:56:46 +01:00
|
|
|
#endif
|
2004-04-19 19:42:59 +02:00
|
|
|
|
2007-10-29 12:25:42 +01:00
|
|
|
/* New versions of MingW have gettimeofday, old mingw and msvc don't */
|
|
|
|
#ifndef HAVE_GETTIMEOFDAY
|
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);
|
2007-10-29 12:25:42 +01:00
|
|
|
#endif
|
2005-10-15 04:49:52 +02: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
|
2005-10-15 04:49:52 +02: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
|
|
|
|
|
2009-01-07 04:39:33 +01:00
|
|
|
/* WIN32 handled in port/win32.h */
|
|
|
|
#ifndef WIN32
|
|
|
|
#define pgoff_t off_t
|
2010-05-15 16:44:13 +02:00
|
|
|
#if defined(__bsdi__) || defined(__NetBSD__)
|
2004-11-06 02:16:22 +01:00
|
|
|
extern int fseeko(FILE *stream, off_t offset, int whence);
|
|
|
|
extern off_t ftello(FILE *stream);
|
|
|
|
#endif
|
2009-01-07 04:39:33 +01:00
|
|
|
#endif
|
2004-11-06 02:16:22 +01:00
|
|
|
|
2011-08-03 22:26:40 +02:00
|
|
|
extern double pg_erand48(unsigned short xseed[3]);
|
|
|
|
extern long pg_lrand48(void);
|
|
|
|
extern void pg_srand48(long seed);
|
2009-07-16 19:43:52 +02:00
|
|
|
|
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
|
|
|
|
|
2011-06-02 23:27:30 +02:00
|
|
|
#if !defined(HAVE_GETPEEREID) && !defined(WIN32)
|
2011-06-02 19:05:01 +02:00
|
|
|
extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
|
|
|
|
#endif
|
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
#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
|
2003-08-04 02:43:34 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
extern int inet_aton(const char *cp, struct in_addr * addr);
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
2006-09-27 18:29:46 +02:00
|
|
|
extern char *strdup(const char *str);
|
|
|
|
#endif
|
|
|
|
|
2007-02-07 01:28:55 +01:00
|
|
|
#if !HAVE_DECL_STRLCAT
|
|
|
|
extern size_t strlcat(char *dst, const char *src, size_t siz);
|
|
|
|
#endif
|
|
|
|
|
2006-10-02 02:06:18 +02:00
|
|
|
#if !HAVE_DECL_STRLCPY
|
2006-09-27 18:29:46 +02:00
|
|
|
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
2003-05-15 18:35:30 +02:00
|
|
|
#endif
|
|
|
|
|
2007-01-11 03:39:52 +01:00
|
|
|
#if !defined(HAVE_RANDOM) && !defined(__BORLANDC__)
|
2003-05-15 18:35:30 +02:00
|
|
|
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);
|
2006-10-04 00:18:23 +02:00
|
|
|
|
2006-10-19 22:56:22 +02:00
|
|
|
extern void pg_qsort(void *base, size_t nel, size_t elsize,
|
2007-11-15 22:14:46 +01:00
|
|
|
int (*cmp) (const void *, const void *));
|
2006-10-19 22:56:22 +02:00
|
|
|
|
|
|
|
#define qsort(a,b,c,d) pg_qsort(a,b,c,d)
|
|
|
|
|
2006-10-04 00:18:23 +02:00
|
|
|
typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg);
|
|
|
|
|
|
|
|
extern void qsort_arg(void *base, size_t nel, size_t elsize,
|
2006-10-04 02:30:14 +02:00
|
|
|
qsort_arg_comparator cmp, void *arg);
|
2006-10-04 00:18:23 +02:00
|
|
|
|
2007-09-29 00:25:49 +02:00
|
|
|
/* port/chklocale.c */
|
2011-02-08 22:04:18 +01:00
|
|
|
extern int pg_get_encoding_from_locale(const char *ctype, bool write_message);
|
2007-09-29 00:25:49 +02:00
|
|
|
|
2010-11-24 23:04:19 +01:00
|
|
|
/* port/inet_net_ntop.c */
|
|
|
|
extern char *inet_net_ntop(int af, const void *src, int bits,
|
|
|
|
char *dst, size_t size);
|
|
|
|
|
2010-12-11 01:42:44 +01:00
|
|
|
/* port/pgcheckdir.c */
|
|
|
|
extern int pg_check_dir(const char *dir);
|
|
|
|
|
|
|
|
/* port/pgmkdirp.c */
|
|
|
|
extern int pg_mkdir_p(char *path, int omode);
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#endif /* PG_PORT_H */
|