2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2006, PostgreSQL Global Development Group
6 * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.52 2006/12/16 00:38:43 adunstan Exp $
11 #include "postgres_fe.h"
15 #ifdef USE_ASSERT_CHECKING
17 #define psql_assert(p) assert(p)
19 #define psql_assert(p)
22 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
25 * Safer versions of some standard C library functions. If an
26 * out-of-memory condition occurs, these functions will bail out
27 * safely; therefore, their return value is guaranteed to be non-NULL.
29 extern char *pg_strdup(const char *string);
30 extern void *pg_malloc(size_t size);
31 extern void *pg_malloc_zero(size_t size);
32 extern void *pg_calloc(size_t nmemb, size_t size);
34 extern bool setQFout(const char *fname);
37 psql_error(const char *fmt,...)
38 /* This lets gcc check the format string for consistency. */
39 __attribute__((format(printf, 1, 2)));
41 extern void NoticeProcessor(void *arg, const char *message);
43 extern volatile bool sigint_interrupt_enabled;
45 extern sigjmp_buf sigint_interrupt_jmp;
47 extern volatile bool cancel_pressed;
49 /* Note: cancel_pressed is defined in print.c, see that file for reasons */
51 extern void setup_cancel_handler(void);
53 extern void SetCancelConn(void);
54 extern void ResetCancelConn(void);
56 extern PGresult *PSQLexec(const char *query, bool start_xact);
58 extern bool SendQuery(const char *query);
60 extern bool is_superuser(void);
61 extern bool standard_strings(void);
62 extern const char *session_username(void);
64 extern char *expand_tilde(char **filename);
66 /* Workarounds for Windows */
67 /* Probably to be moved up the source tree in the future, perhaps to be replaced by
68 * more specific checks like configure-style HAVE_GETTIMEOFDAY macros.
74 typedef struct timeval TimevalStruct;
76 #define GETTIMEOFDAY(T) gettimeofday(T, NULL)
77 #define DIFF_MSEC(T, U) \
78 ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
79 ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
82 typedef struct _timeb TimevalStruct;
84 #include <sys/types.h>
85 #include <sys/timeb.h>
87 #define GETTIMEOFDAY(T) _ftime(T)
88 #define DIFF_MSEC(T, U) \
89 (((T)->time - (U)->time) * 1000.0 + \
90 ((T)->millitm - (U)->millitm))