PostgreSQL Source Code
git master
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
a
c
d
g
h
i
k
l
m
p
r
s
t
Functions
Variables
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
c
d
f
h
i
n
o
p
r
s
t
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
compat.c
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* compat.c
4
* Reimplementations of various backend functions.
5
*
6
* Portions Copyright (c) 2013-2025, PostgreSQL Global Development Group
7
*
8
* IDENTIFICATION
9
* src/bin/pg_waldump/compat.c
10
*
11
* This file contains client-side implementations for various backend
12
* functions that the rm_desc functions in *desc.c files rely on.
13
*
14
*-------------------------------------------------------------------------
15
*/
16
17
/* ugly hack, same as in e.g pg_controldata */
18
#define FRONTEND 1
19
#include "
postgres.h
"
20
21
#include <
time.h
>
22
23
#include "
utils/datetime.h
"
24
25
/* copied from timestamp.c */
26
pg_time_t
27
timestamptz_to_time_t
(
TimestampTz
t)
28
{
29
pg_time_t
result;
30
31
result = (
pg_time_t
) (t /
USECS_PER_SEC
+
32
((
POSTGRES_EPOCH_JDATE
-
UNIX_EPOCH_JDATE
) *
SECS_PER_DAY
));
33
return
result;
34
}
35
36
/*
37
* Stopgap implementation of timestamptz_to_str that doesn't depend on backend
38
* infrastructure. This will work for timestamps that are within the range
39
* of the platform time_t type. (pg_time_t is compatible except for possibly
40
* being wider.)
41
*
42
* XXX the return value points to a static buffer, so beware of using more
43
* than one result value concurrently.
44
*
45
* XXX: The backend timestamp infrastructure should instead be split out and
46
* moved into src/common. That's a large project though.
47
*/
48
const
char
*
49
timestamptz_to_str
(
TimestampTz
t)
50
{
51
static
char
buf
[
MAXDATELEN
+ 1];
52
char
ts[
MAXDATELEN
+ 1];
53
char
zone
[
MAXDATELEN
+ 1];
54
time_t result = (time_t)
timestamptz_to_time_t
(t);
55
struct
tm
*ltime = localtime(&result);
56
57
strftime(ts,
sizeof
(ts),
"%Y-%m-%d %H:%M:%S"
, ltime);
58
strftime(
zone
,
sizeof
(
zone
),
"%Z"
, ltime);
59
60
snprintf
(
buf
,
sizeof
(
buf
),
"%s.%06d %s"
,
61
ts, (
int
) (t %
USECS_PER_SEC
),
zone
);
62
63
return
buf
;
64
}
timestamptz_to_str
const char * timestamptz_to_str(TimestampTz t)
Definition:
compat.c:49
timestamptz_to_time_t
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition:
compat.c:27
TimestampTz
int64 TimestampTz
Definition:
timestamp.h:39
USECS_PER_SEC
#define USECS_PER_SEC
Definition:
timestamp.h:134
UNIX_EPOCH_JDATE
#define UNIX_EPOCH_JDATE
Definition:
timestamp.h:234
SECS_PER_DAY
#define SECS_PER_DAY
Definition:
timestamp.h:126
POSTGRES_EPOCH_JDATE
#define POSTGRES_EPOCH_JDATE
Definition:
timestamp.h:235
datetime.h
MAXDATELEN
#define MAXDATELEN
Definition:
datetime.h:200
tm
static struct pg_tm tm
Definition:
localtime.c:104
buf
static char * buf
Definition:
pg_test_fsync.c:72
pg_time_t
int64 pg_time_t
Definition:
pgtime.h:23
snprintf
#define snprintf
Definition:
port.h:239
postgres.h
zone
Definition:
zic.c:94
time.h
src
bin
pg_waldump
compat.c
Generated on Fri Mar 14 2025 18:13:23 for PostgreSQL Source Code by
1.9.4