]> granicus.if.org Git - postgresql/blob - src/bin/psql/common.h
enable \timing oputput for \copy commands
[postgresql] / src / bin / psql / common.h
1 /*
2  * psql - the PostgreSQL interactive terminal
3  *
4  * Copyright (c) 2000-2006, PostgreSQL Global Development Group
5  *
6  * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.52 2006/12/16 00:38:43 adunstan Exp $
7  */
8 #ifndef COMMON_H
9 #define COMMON_H
10
11 #include "postgres_fe.h"
12 #include <setjmp.h>
13 #include "libpq-fe.h"
14
15 #ifdef USE_ASSERT_CHECKING
16 #include <assert.h>
17 #define psql_assert(p) assert(p)
18 #else
19 #define psql_assert(p)
20 #endif
21
22 #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
23
24 /*
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.
28  */
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);
33
34 extern bool setQFout(const char *fname);
35
36 extern void
37 psql_error(const char *fmt,...)
38 /* This lets gcc check the format string for consistency. */
39 __attribute__((format(printf, 1, 2)));
40
41 extern void NoticeProcessor(void *arg, const char *message);
42
43 extern volatile bool sigint_interrupt_enabled;
44
45 extern sigjmp_buf sigint_interrupt_jmp;
46
47 extern volatile bool cancel_pressed;
48
49 /* Note: cancel_pressed is defined in print.c, see that file for reasons */
50
51 extern void setup_cancel_handler(void);
52
53 extern void SetCancelConn(void);
54 extern void ResetCancelConn(void);
55
56 extern PGresult *PSQLexec(const char *query, bool start_xact);
57
58 extern bool SendQuery(const char *query);
59
60 extern bool is_superuser(void);
61 extern bool standard_strings(void);
62 extern const char *session_username(void);
63
64 extern char *expand_tilde(char **filename);
65
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.
69  */
70 #ifndef WIN32
71
72 #include <sys/time.h>
73
74 typedef struct timeval TimevalStruct;
75
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)
80 #else
81
82 typedef struct _timeb TimevalStruct;
83
84 #include <sys/types.h>
85 #include <sys/timeb.h>
86
87 #define GETTIMEOFDAY(T) _ftime(T)
88 #define DIFF_MSEC(T, U) \
89         (((T)->time - (U)->time) * 1000.0 + \
90          ((T)->millitm - (U)->millitm))
91 #endif
92
93 #endif   /* COMMON_H */