LCOV - differential code coverage report
Current view: top level - src/bin/pg_waldump - compat.c (source / functions) Coverage Total Hit UNC UBC DUB
Current: Differential Code Coverage HEAD vs 15 Lines: 0.0 % 11 0 3 8 3
Current Date: 2023-04-08 17:13:01 Functions: 0.0 % 2 0 1 1 1
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (180,240] days: 0.0 % 3 0 3
Legend: Lines: hit not hit (240..) days: 0.0 % 8 0 8
Function coverage date bins:
(180,240] days: 0.0 % 1 0 1
(240..) days: 0.0 % 1 0 1

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*-------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * compat.c
                                  4                 :  *      Reimplementations of various backend functions.
                                  5                 :  *
                                  6                 :  * Portions Copyright (c) 2013-2023, 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
 3698 alvherre                   27 UBC           0 : timestamptz_to_time_t(TimestampTz t)
                                 28                 : {
                                 29                 :     pg_time_t   result;
                                 30                 : 
                                 31               0 :     result = (pg_time_t) (t / USECS_PER_SEC +
                                 32                 :                           ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
                                 33               0 :     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 *
  201 pg                         49 UNC           0 : timestamptz_to_str(TimestampTz t)
                                 50                 : {
                                 51                 :     static char buf[MAXDATELEN + 1];
                                 52                 :     char        ts[MAXDATELEN + 1];
                                 53                 :     char        zone[MAXDATELEN + 1];
                                 54               0 :     time_t      result = (time_t) timestamptz_to_time_t(t);
 3698 alvherre                   55 UBC           0 :     struct tm  *ltime = localtime(&result);
                                 56                 : 
 3694 tgl                        57               0 :     strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", ltime);
 3698 alvherre                   58               0 :     strftime(zone, sizeof(zone), "%Z", ltime);
                                 59                 : 
 1758 tgl                        60               0 :     snprintf(buf, sizeof(buf), "%s.%06d %s",
  201 pg                         61 UNC           0 :              ts, (int) (t % USECS_PER_SEC), zone);
                                 62                 : 
 3698 alvherre                   63 UBC           0 :     return buf;
                                 64                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a