postgres.git / summary / log / commit / refs
commit 7f77b2a89bd4788b6bd686ba63138f51302d9839
Author: Peter Eisentraut <peter@eisentraut.org>
Date: Mon Jul 13 09:01:36 2026 +0000
Some const qualifications added in passing
These are some cases in the vicinity of the patches to improve the
size_t/ssize_t use with POSIX file system APIs. For example, the
input buffers for write operations or the file names passed for error
reporting can be const.
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org
src/backend/access/transam/timeline.c | 4 ++--
src/backend/access/transam/twophase.c | 4 ++--
src/bin/pg_basebackup/receivelog.c | 2 +-
src/bin/pg_combinebackup/reconstruct.c | 40 +++++++++++++++++-----------------
src/include/access/timeline.h | 4 ++--
5 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 68e5f692d26..d49e52993b7 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -303,7 +303,7 @@ findNewestTimeLine(TimeLineID startTLI)
*/
void
writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
- XLogRecPtr switchpoint, char *reason)
+ XLogRecPtr switchpoint, const char *reason)
{
char path[MAXPGPATH];
char tmppath[MAXPGPATH];
@@ -461,7 +461,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
* to avoid emplacing a bogus file.
*/
void
-writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
+writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size)
{
char path[MAXPGPATH];
char tmppath[MAXPGPATH];
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 1035e8b3fc7..e27efcaab47 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -240,7 +240,7 @@ static void MarkAsPreparingGuts(GlobalTransaction gxact, FullTransactionId fxid,
const char *gid, TimestampTz prepared_at, Oid owner,
Oid databaseid);
static void RemoveTwoPhaseFile(FullTransactionId fxid, bool giveWarning);
-static void RecreateTwoPhaseFile(FullTransactionId fxid, void *content, int len);
+static void RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, int len);
/*
* Register shared memory for two-phase state.
@@ -1745,7 +1745,7 @@ RemoveTwoPhaseFile(FullTransactionId fxid, bool giveWarning)
* Note: content and len don't include CRC.
*/
static void
-RecreateTwoPhaseFile(FullTransactionId fxid, void *content, int len)
+RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, int len)
{
char path[MAXPGPATH];
pg_crc32c statefile_crc;
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 77894b721e1..4925e992741 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -272,7 +272,7 @@ existsTimeLineHistoryFile(StreamCtl *stream)
}
static bool
-writeTimeLineHistoryFile(StreamCtl *stream, char *filename, char *content)
+writeTimeLineHistoryFile(StreamCtl *stream, const char *filename, const char *content)
{
int size = strlen(content);
char histfname[MAXFNAMELEN];
diff --git a/src/bin/pg_combinebackup/reconstruct.c b/src/bin/pg_combinebackup/reconstruct.c
index 0a994e57bda..8748d38d4b6 100644
--- a/src/bin/pg_combinebackup/reconstruct.c
+++ b/src/bin/pg_combinebackup/reconstruct.c
@@ -49,23 +49,23 @@ typedef struct rfile
static void debug_reconstruction(int n_source,
rfile **sources,
bool dry_run);
-static unsigned find_reconstructed_block_length(rfile *s);
-static rfile *make_incremental_rfile(char *filename);
-static rfile *make_rfile(char *filename, bool missing_ok);
-static void write_reconstructed_file(char *input_filename,
- char *output_filename,
+static unsigned find_reconstructed_block_length(const rfile *s);
+static rfile *make_incremental_rfile(const char *filename);
+static rfile *make_rfile(const char *filename, bool missing_ok);
+static void write_reconstructed_file(const char *input_filename,
+ const char *output_filename,
unsigned block_length,
rfile **sourcemap,
- off_t *offsetmap,
+ const off_t *offsetmap,
pg_checksum_context *checksum_ctx,
CopyMethod copy_method,
bool debug,
bool dry_run);
-static void read_bytes(rfile *rf, void *buffer, unsigned length);
-static void write_block(int fd, char *output_filename,
- uint8 *buffer,
+static void read_bytes(const rfile *rf, void *buffer, unsigned length);
+static void write_block(int fd, const char *output_filename,
+ const uint8 *buffer,
pg_checksum_context *checksum_ctx);
-static void read_block(rfile *s, off_t off, uint8 *buffer);
+static void read_block(const rfile *s, off_t off, uint8 *buffer);
/*
* Reconstruct a full file from an incremental file and a chain of prior
@@ -433,7 +433,7 @@ debug_reconstruction(int n_source, rfile **sources, bool dry_run)
* necessary to include those blocks.
*/
static unsigned
-find_reconstructed_block_length(rfile *s)
+find_reconstructed_block_length(const rfile *s)
{
unsigned block_length = s->truncation_block_length;
unsigned i;
@@ -450,7 +450,7 @@ find_reconstructed_block_length(rfile *s)
* blocks it contains.
*/
static rfile *
-make_incremental_rfile(char *filename)
+make_incremental_rfile(const char *filename)
{
rfile *rf;
unsigned magic;
@@ -505,7 +505,7 @@ make_incremental_rfile(char *filename)
* Allocate and perform basic initialization of an rfile.
*/
static rfile *
-make_rfile(char *filename, bool missing_ok)
+make_rfile(const char *filename, bool missing_ok)
{
rfile *rf;
@@ -529,7 +529,7 @@ make_rfile(char *filename, bool missing_ok)
* Read the indicated number of bytes from an rfile into the buffer.
*/
static void
-read_bytes(rfile *rf, void *buffer, unsigned length)
+read_bytes(const rfile *rf, void *buffer, unsigned length)
{
int rb = read(rf->fd, buffer, length);
@@ -547,11 +547,11 @@ read_bytes(rfile *rf, void *buffer, unsigned length)
* Write out a reconstructed file.
*/
static void
-write_reconstructed_file(char *input_filename,
- char *output_filename,
+write_reconstructed_file(const char *input_filename,
+ const char *output_filename,
unsigned block_length,
rfile **sourcemap,
- off_t *offsetmap,
+ const off_t *offsetmap,
pg_checksum_context *checksum_ctx,
CopyMethod copy_method,
bool debug,
@@ -750,8 +750,8 @@ write_reconstructed_file(char *input_filename,
* provided only for the error message.
*/
static void
-write_block(int fd, char *output_filename,
- uint8 *buffer, pg_checksum_context *checksum_ctx)
+write_block(int fd, const char *output_filename,
+ const uint8 *buffer, pg_checksum_context *checksum_ctx)
{
int wb;
@@ -774,7 +774,7 @@ write_block(int fd, char *output_filename,
* Read a block of data (BLCKSZ bytes) into the buffer.
*/
static void
-read_block(rfile *s, off_t off, uint8 *buffer)
+read_block(const rfile *s, off_t off, uint8 *buffer)
{
int rb;
diff --git a/src/include/access/timeline.h b/src/include/access/timeline.h
index 97f1d619c35..76b852d07ab 100644
--- a/src/include/access/timeline.h
+++ b/src/include/access/timeline.h
@@ -33,8 +33,8 @@ extern List *readTimeLineHistory(TimeLineID targetTLI);
extern bool existsTimeLineHistory(TimeLineID probeTLI);
extern TimeLineID findNewestTimeLine(TimeLineID startTLI);
extern void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
- XLogRecPtr switchpoint, char *reason);
-extern void writeTimeLineHistoryFile(TimeLineID tli, char *content, int size);
+ XLogRecPtr switchpoint, const char *reason);
+extern void writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size);
extern void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end);
extern bool tliInHistory(TimeLineID tli, List *expectedTLEs);
extern TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history);
[parent: 1863452a4bfe]