PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
private.h
Go to the documentation of this file.
1 #ifndef PRIVATE_H
2 #define PRIVATE_H
3 
4 /*
5  * This file is in the public domain, so clarified as of
6  * 1996-06-05 by Arthur David Olson.
7  *
8  * IDENTIFICATION
9  * src/timezone/private.h
10  */
11 
12 /*
13  * This header is for use ONLY with the time conversion code.
14  * There is no guarantee that it will remain unchanged,
15  * or that it will remain at all.
16  * Do NOT copy it to any system include directory.
17  * Thank you!
18  */
19 
20 #include <limits.h> /* for CHAR_BIT et al. */
21 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
22 #include <unistd.h> /* for F_OK and R_OK */
23 
24 #include "pgtime.h"
25 
26 /* This string was in the Factory zone through version 2016f. */
27 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
28 
29 /*
30  * IANA has a bunch of HAVE_FOO #defines here, but in PG we want pretty
31  * much all of that to be done by PG's configure script.
32  */
33 
34 #ifndef ENOTSUP
35 #define ENOTSUP EINVAL
36 #endif
37 #ifndef EOVERFLOW
38 #define EOVERFLOW EINVAL
39 #endif
40 
41 #ifndef WIFEXITED
42 #define WIFEXITED(status) (((status) & 0xff) == 0)
43 #endif /* !defined WIFEXITED */
44 #ifndef WEXITSTATUS
45 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
46 #endif /* !defined WEXITSTATUS */
47 
48 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
49 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
50 
51 #ifndef SIZE_MAX
52 #define SIZE_MAX ((size_t) -1)
53 #endif
54 
55 /*
56  * SunOS 4.1.1 libraries lack remove.
57  */
58 
59 #ifndef remove
60 extern int unlink(const char *filename);
61 
62 #define remove unlink
63 #endif /* !defined remove */
64 
65 
66 /*
67  * Finally, some convenience items.
68  */
69 
70 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
71 #define TYPE_SIGNED(type) (((type) -1) < 0)
72 #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
73 
74 /*
75  * Max and min values of the integer type T, of which only the bottom
76  * B bits are used, and where the highest-order used bit is considered
77  * to be a sign bit if T is signed.
78  */
79 #define MAXVAL(t, b) \
80  ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
81  - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
82 #define MINVAL(t, b) \
83  ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
84 
85 /*
86  * 302 / 1000 is log10(2.0) rounded up.
87  * Subtract one for the sign bit if the type is signed;
88  * add one for integer division truncation;
89  * add one more for a minus sign if the type is signed.
90  */
91 #define INT_STRLEN_MAXIMUM(type) \
92  ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
93  1 + TYPE_SIGNED(type))
94 
95 /*
96  * INITIALIZE(x)
97  */
98 #define INITIALIZE(x) ((x) = 0)
99 
100 #undef _
101 #define _(msgid) (msgid)
102 
103 /* Handy macros that are independent of tzfile implementation. */
104 
105 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
106 
107 #define SECSPERMIN 60
108 #define MINSPERHOUR 60
109 #define HOURSPERDAY 24
110 #define DAYSPERWEEK 7
111 #define DAYSPERNYEAR 365
112 #define DAYSPERLYEAR 366
113 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
114 #define SECSPERDAY ((int32) SECSPERHOUR * HOURSPERDAY)
115 #define MONSPERYEAR 12
116 
117 #define TM_SUNDAY 0
118 #define TM_MONDAY 1
119 #define TM_TUESDAY 2
120 #define TM_WEDNESDAY 3
121 #define TM_THURSDAY 4
122 #define TM_FRIDAY 5
123 #define TM_SATURDAY 6
124 
125 #define TM_JANUARY 0
126 #define TM_FEBRUARY 1
127 #define TM_MARCH 2
128 #define TM_APRIL 3
129 #define TM_MAY 4
130 #define TM_JUNE 5
131 #define TM_JULY 6
132 #define TM_AUGUST 7
133 #define TM_SEPTEMBER 8
134 #define TM_OCTOBER 9
135 #define TM_NOVEMBER 10
136 #define TM_DECEMBER 11
137 
138 #define TM_YEAR_BASE 1900
139 
140 #define EPOCH_YEAR 1970
141 #define EPOCH_WDAY TM_THURSDAY
142 
143 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
144 
145 /*
146  * Since everything in isleap is modulo 400 (or a factor of 400), we know that
147  * isleap(y) == isleap(y % 400)
148  * and so
149  * isleap(a + b) == isleap((a + b) % 400)
150  * or
151  * isleap(a + b) == isleap(a % 400 + b % 400)
152  * This is true even if % means modulo rather than Fortran remainder
153  * (which is allowed by C89 but not C99).
154  * We use this to avoid addition overflow problems.
155  */
156 
157 #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
158 
159 
160 /*
161  * The Gregorian year averages 365.2425 days, which is 31556952 seconds.
162  */
163 
164 #define AVGSECSPERYEAR 31556952L
165 #define SECSPERREPEAT \
166  ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR)
167 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
168 
169 #endif /* !defined PRIVATE_H */
int unlink(const char *filename)
static char * filename
Definition: pg_dumpall.c:89