]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Some const qualifications added in passing
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 13 Jul 2026 09:01:36 +0000 (11:01 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 13 Jul 2026 09:05:56 +0000 (11:05 +0200)
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
src/backend/access/transam/twophase.c
src/bin/pg_basebackup/receivelog.c
src/bin/pg_combinebackup/reconstruct.c
src/include/access/timeline.h

index 68e5f692d26dd8d3c4872c4c41183c279c387b5b..d49e52993b79640171fe677d071aeec761b2b7e2 100644 (file)
@@ -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];
index 1035e8b3fc795ff8d709a064776b6f51026b3e1b..e27efcaab471a9669ac99693984c2c21a521796a 100644 (file)
@@ -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;
index 77894b721e145b153d78a50aca284ab29149db63..4925e9927419205c27bbb372e45e845f3072fea7 100644 (file)
@@ -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];
index 0a994e57bdaf60d7fc680256b393305499433a79..8748d38d4b68fa0babefd697a2255900079471a2 100644 (file)
@@ -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;
 
index 97f1d619c35d8ded328ee8dc409d0e07bd9fdeb2..76b852d07ab090d7eaa7fb794696df0adb783463 100644 (file)
@@ -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);