* port.h
* Header for src/port/ compatibility functions.
*
- * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/port.h,v 1.129 2010/01/10 14:16:08 mha Exp $
+ * src/include/port.h
*
*-------------------------------------------------------------------------
*/
/* socket has a different definition on WIN32 */
#ifndef WIN32
typedef int pgsocket;
-#define PGINVALID_SOCKET -1
+
+#define PGINVALID_SOCKET (-1)
#else
typedef SOCKET pgsocket;
+
#define PGINVALID_SOCKET INVALID_SOCKET
#endif
/* Portable path handling for Unix/Win32 (in path.c) */
+extern bool has_drive_prefix(const char *filename);
extern char *first_dir_separator(const char *filename);
extern char *last_dir_separator(const char *filename);
-extern char *first_path_separator(const char *pathlist);
+extern char *first_path_var_separator(const char *pathlist);
extern void join_path_components(char *ret_path,
const char *head, const char *tail);
extern void canonicalize_path(char *path);
extern void make_native_path(char *path);
extern bool path_contains_parent_reference(const char *path);
+extern bool path_is_relative_and_below_cwd(const char *path);
extern bool path_is_prefix_of_path(const char *path1, const char *path2);
extern const char *get_progname(const char *argv0);
extern void get_share_path(const char *my_exec_path, char *ret_path);
* By making this a macro we avoid needing to include path.c in libpq.
*/
#ifndef WIN32
+#define IS_DIR_SEP(ch) ((ch) == '/')
+
#define is_absolute_path(filename) \
( \
- ((filename)[0] == '/') \
+ IS_DIR_SEP((filename)[0]) \
)
#else
+#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
+
+/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */
#define is_absolute_path(filename) \
( \
- ((filename)[0] == '/') || \
- (filename)[0] == '\\' || \
+ IS_DIR_SEP((filename)[0]) || \
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
- ((filename)[2] == '\\' || (filename)[2] == '/')) \
+ IS_DIR_SEP((filename)[2])) \
)
#endif
#if defined(WIN32) && !defined(__CYGWIN__)
#define DEVNULL "nul"
-/* "con" does not work from the Msys 1.0.10 console (part of MinGW). */
-#define DEVTTY "con"
#else
#define DEVNULL "/dev/null"
-#define DEVTTY "/dev/tty"
#endif
/*
* - exactly two quote characters
* - no special characters between the two quote characters, where special
* is one of: &<>()@^|
- * - there are one or more whitespace characters between the the two quote
+ * - there are one or more whitespace characters between the two quote
* characters
* - the string between the two quote characters is the name of an
* executable file.
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);
+extern unsigned char pg_ascii_toupper(unsigned char ch);
+extern unsigned char pg_ascii_tolower(unsigned char ch);
#ifdef USE_REPL_SNPRINTF
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)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
extern int
pg_sprintf(char *str, const char *fmt,...)
/* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
extern int
pg_fprintf(FILE *stream, const char *fmt,...)
/* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
extern int
pg_printf(const char *fmt,...)
/* This extension allows gcc to check the format string */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
/*
* The GCC-specific code below prevents the __attribute__(... 'printf')
#endif
#endif /* USE_REPL_SNPRINTF */
-/* Portable prompt handling */
-extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
-
+#if defined(WIN32)
/*
- * WIN32 doesn't allow descriptors returned by pipe() to be used in select(),
- * so for that platform we use socket() instead of pipe().
- * There is some inconsistency here because sometimes we require pg*, like
- * pgpipe, but in other cases we define rename to pgrename just on Win32.
+ * 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.
*/
-#ifndef WIN32
+#if defined(setlocale)
+#undef setlocale
+#endif
+
/*
- * The function prototypes are not supplied because every C file
- * includes this file.
+ * Define our own wrapper macro around setlocale() to work around bugs in
+ * Windows' native setlocale() function.
*/
-#define pgpipe(a) pipe(a)
-#define piperead(a,b,c) read(a,b,c)
-#define pipewrite(a,b,c) write(a,b,c)
-#else
-extern int pgpipe(int handles[2]);
-extern int piperead(int s, char *buf, int len);
+extern char *pgwin32_setlocale(int category, const char *locale);
-#define pipewrite(a,b,c) send(a,b,c,0)
+#define setlocale(a,b) pgwin32_setlocale(a,b)
+#endif /* WIN32 */
+
+/* Portable prompt handling */
+extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
+#ifdef WIN32
#define PG_SIGNAL_COUNT 32
#define kill(pid,sig) pgkill(pid,sig)
extern int pgkill(int pid, int sig);
*/
#if defined(WIN32) && !defined(__CYGWIN__)
extern int pgsymlink(const char *oldpath, const char *newpath);
+extern int pgreadlink(const char *path, char *buf, size_t size);
+extern bool pgwin32_is_junction(char *path);
#define symlink(oldpath, newpath) pgsymlink(oldpath, newpath)
+#define readlink(path, buf, size) pgreadlink(path, buf, size)
#endif
-extern void copydir(char *fromdir, char *todir, bool recurse);
-
extern bool rmtree(const char *path, bool rmtopdir);
/*
#define fopen(a,b) pgwin32_fopen(a,b)
#endif
+#ifndef popen
#define popen(a,b) _popen(a,b)
+#endif
+#ifndef pclose
#define pclose(a) _pclose(a)
+#endif
/* New versions of MingW have gettimeofday, old mingw and msvc don't */
#ifndef HAVE_GETTIMEOFDAY
/* WIN32 handled in port/win32.h */
#ifndef WIN32
#define pgoff_t off_t
-#if defined(bsdi) || defined(netbsd)
+#ifdef __NetBSD__
extern int fseeko(FILE *stream, off_t offset, int whence);
extern off_t ftello(FILE *stream);
#endif
#endif
-#ifndef HAVE_ERAND48
-/* we assume all of these are present or missing together */
-extern double erand48(unsigned short xseed[3]);
-extern long lrand48(void);
-extern void srand48(long seed);
+extern double pg_erand48(unsigned short xseed[3]);
+extern long pg_lrand48(void);
+extern void pg_srand48(long seed);
+
+#ifndef HAVE_FLS
+extern int fls(int mask);
#endif
#ifndef HAVE_FSEEKO
extern int getopt(int nargc, char *const * nargv, const char *ostr);
#endif
+#if !defined(HAVE_GETPEEREID) && !defined(WIN32)
+extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
+#endif
+
#ifndef HAVE_ISINF
extern int isinf(double x);
#endif
extern int inet_aton(const char *cp, struct in_addr * addr);
#endif
-#ifndef HAVE_STRDUP
-extern char *strdup(const char *str);
+#ifndef HAVE_ASPRINTF
+extern int asprintf(char **ret, const char *fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+extern int vasprintf(char **ret, const char *fmt, va_list ap) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
#endif
#if !HAVE_DECL_STRLCAT
extern void pg_qsort(void *base, size_t nel, size_t elsize,
int (*cmp) (const void *, const void *));
+extern int pg_qsort_strcmp(const void *a, const void *b);
#define qsort(a,b,c,d) pg_qsort(a,b,c,d)
qsort_arg_comparator cmp, void *arg);
/* port/chklocale.c */
-extern int pg_get_encoding_from_locale(const char *ctype);
+extern int pg_get_encoding_from_locale(const char *ctype, bool write_message);
+
+#if defined(WIN32) && !defined(FRONTEND)
+extern int pg_codepage_to_encoding(UINT cp);
+#endif
+
+/* port/inet_net_ntop.c */
+extern char *inet_net_ntop(int af, const void *src, int bits,
+ char *dst, size_t size);
+
+/* port/pgcheckdir.c */
+extern int pg_check_dir(const char *dir);
+
+/* port/pgmkdirp.c */
+extern int pg_mkdir_p(char *path, int omode);
+
+/* port/pqsignal.c */
+typedef void (*pqsigfunc) (int signo);
+extern pqsigfunc pqsignal(int signo, pqsigfunc func);
+
+/* port/quotes.c */
+extern char *escape_single_quotes_ascii(const char *src);
+
+/* port/wait_error.c */
+extern char *wait_result_to_str(int exit_status);
#endif /* PG_PORT_H */