PostgreSQL Source Code  git master
rmgrdesc_utils.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * rmgrdesc_utils.c
4  * Support functions for rmgrdesc routines
5  *
6  * Copyright (c) 2023-2024, PostgreSQL Global Development Group
7  *
8  *
9  * IDENTIFICATION
10  * src/backend/access/rmgrdesc/rmgrdesc_utils.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15 
16 #include "access/rmgrdesc_utils.h"
17 #include "storage/off.h"
18 
19 /*
20  * Helper function to print an array, in the format described in the
21  * README.
22  */
23 void
24 array_desc(StringInfo buf, void *array, size_t elem_size, int count,
25  void (*elem_desc) (StringInfo buf, void *elem, void *data),
26  void *data)
27 {
28  if (count == 0)
29  {
31  return;
32  }
34  for (int i = 0; i < count; i++)
35  {
36  elem_desc(buf, (char *) array + elem_size * i, data);
37  if (i < count - 1)
39  }
41 }
42 
43 void
44 offset_elem_desc(StringInfo buf, void *offset, void *data)
45 {
46  appendStringInfo(buf, "%u", *(OffsetNumber *) offset);
47 }
48 
49 void
50 redirect_elem_desc(StringInfo buf, void *offset, void *data)
51 {
52  OffsetNumber *new_offset = (OffsetNumber *) offset;
53 
54  appendStringInfo(buf, "%u->%u", new_offset[0], new_offset[1]);
55 }
56 
57 void
58 oid_elem_desc(StringInfo buf, void *relid, void *data)
59 {
60  appendStringInfo(buf, "%u", *(Oid *) relid);
61 }
int i
Definition: isn.c:72
uint16 OffsetNumber
Definition: off.h:24
const void * data
static char * buf
Definition: pg_test_fsync.c:72
unsigned int Oid
Definition: postgres_ext.h:31
void oid_elem_desc(StringInfo buf, void *relid, void *data)
void redirect_elem_desc(StringInfo buf, void *offset, void *data)
void array_desc(StringInfo buf, void *array, size_t elem_size, int count, void(*elem_desc)(StringInfo buf, void *elem, void *data), void *data)
void offset_elem_desc(StringInfo buf, void *offset, void *data)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:94
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:191