]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Clean up write() return type
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 08:58:13 +0000 (10:58 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 09:00:39 +0000 (11:00 +0200)
and analogously for pg_pwrite() and FileWrite()

Be sure to store the return value in a variable of type ssize_t, not
int.

Some callers of FileWrite() did not have a separate error message for
a short write.  This is okay in practice because FileWriteV() sets
ENOSPC for all non-error returns, so you'll get a reasonable error
message either way.  But callers handled this inconsistently, and this
behavior isn't really prominently documented and commit 871fe4917e1
seems to frown upon it, so it seems better to make all callers handle
this consistently by adding the separate error message.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org

31 files changed:
src/backend/access/heap/rewriteheap.c
src/backend/access/transam/timeline.c
src/backend/access/transam/twophase.c
src/backend/access/transam/xlog.c
src/backend/backup/basebackup_server.c
src/backend/commands/dbcommands.c
src/backend/libpq/be-fsstubs.c
src/backend/postmaster/fork_process.c
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
src/backend/replication/walreceiver.c
src/backend/storage/file/buffile.c
src/backend/storage/ipc/waiteventset.c
src/backend/storage/smgr/md.c
src/backend/utils/error/elog.c
src/backend/utils/init/miscinit.c
src/backend/utils/probes.d
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_basebackup/receivelog.c
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_combinebackup/backup_label.c
src/bin/pg_combinebackup/copy_file.c
src/bin/pg_combinebackup/reconstruct.c
src/bin/pg_combinebackup/write_manifest.c
src/bin/pg_dump/parallel.c
src/bin/pg_test_fsync/pg_test_fsync.c
src/fe_utils/cancel.c
src/include/access/timeline.h
src/include/replication/walreceiver.h
src/interfaces/libpq/fe-lobj.c
src/test/examples/testlo.c
src/test/examples/testlo64.c

index 0ccd392c3dc0ba96e499916b515fedf4bd26d32e..0648e433031f4bfd5868a4d41aa3680ddec6d4a2 100644 (file)
@@ -829,8 +829,8 @@ logical_heap_rewrite_flush_mappings(RewriteState state)
                char       *waldata_start;
                xl_heap_rewrite_mapping xlrec;
                Oid                     dboid;
-               uint32          len;
-               int                     written;
+               size_t          len;
+               ssize_t         written;
                uint32          num_mappings = dclist_count(&src->mappings);
 
                /* this file hasn't got any new mappings */
@@ -882,10 +882,14 @@ logical_heap_rewrite_flush_mappings(RewriteState state)
                 */
                written = FileWrite(src->vfd, waldata_start, len, src->off,
                                                        WAIT_EVENT_LOGICAL_REWRITE_WRITE);
-               if (written != len)
+               if (written < 0)
                        ereport(ERROR,
                                        (errcode_for_file_access(),
-                                        errmsg("could not write to file \"%s\", wrote %d of %d: %m", src->path,
+                                        errmsg("could not write to file \"%s\": %m", src->path)));
+               else if (written != len)
+                       ereport(ERROR,
+                                       (errcode_for_file_access(),
+                                        errmsg("could not write to file \"%s\": wrote %zd of %zu", src->path,
                                                        written, len)));
                src->off += len;
 
@@ -1078,7 +1082,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
        char            path[MAXPGPATH];
        int                     fd;
        xl_heap_rewrite_mapping *xlrec;
-       uint32          len;
+       size_t          len;
        char       *data;
 
        xlrec = (xl_heap_rewrite_mapping *) XLogRecGetData(r);
index db101b761eea021f6988e4bb92922f61854b20b3..d80c8ffe0a7496a00c090738524d40abdffdd2f0 100644 (file)
@@ -461,7 +461,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
  * to avoid emplacing a bogus file.
  */
 void
-writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size)
+writeTimeLineHistoryFile(TimeLineID tli, const char *content, size_t size)
 {
        char            path[MAXPGPATH];
        char            tmppath[MAXPGPATH];
@@ -483,7 +483,7 @@ writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size)
 
        errno = 0;
        pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE);
-       if ((int) write(fd, content, size) != size)
+       if (write(fd, content, size) != size)
        {
                int                     save_errno = errno;
 
index 69c12226b7b7ec5a511b0a4540c2a46f7423e733..439e28c9987f90657dadb10d89650a477e9c1c74 100644 (file)
@@ -232,7 +232,7 @@ static void ProcessRecords(char *bufptr, FullTransactionId fxid,
                                                   const TwoPhaseCallback callbacks[]);
 static void RemoveGXact(GlobalTransaction gxact);
 
-static void XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len);
+static void XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, size_t *len);
 static char *ProcessTwoPhaseBuffer(FullTransactionId fxid,
                                                                   XLogRecPtr prepare_start_lsn,
                                                                   bool fromdisk, bool setParent, bool setNextXid);
@@ -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, const void *content, int len);
+static void RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, size_t len);
 
 /*
  * Register shared memory for two-phase state.
@@ -1417,7 +1417,7 @@ ReadTwoPhaseFile(FullTransactionId fxid, bool missing_ok)
  * similarly to the way WALSender or Logical Decoding would do.
  */
 static void
-XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len)
+XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, size_t *len)
 {
        XLogRecord *record;
        XLogReaderState *xlogreader;
@@ -1747,7 +1747,7 @@ RemoveTwoPhaseFile(FullTransactionId fxid, bool giveWarning)
  * Note: content and len don't include CRC.
  */
 static void
-RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, int len)
+RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, size_t len)
 {
        char            path[MAXPGPATH];
        pg_crc32c       statefile_crc;
@@ -1867,7 +1867,7 @@ CheckPointTwoPhase(XLogRecPtr redo_horizon)
                        gxact->prepare_end_lsn <= redo_horizon)
                {
                        char       *buf;
-                       int                     len;
+                       size_t          len;
 
                        XlogReadTwoPhaseData(gxact->prepare_start_lsn, &buf, &len);
                        RecreateTwoPhaseFile(gxact->fxid, buf, len);
index 291692368961fc709e3fe4d3bcefed80a4f9db1a..f8b939853e945d6156db45198994bc3b8d987b66 100644 (file)
@@ -3541,7 +3541,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
                }
                errno = 0;
                pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_WRITE);
-               if ((int) write(fd, buffer.data, sizeof(buffer)) != (int) sizeof(buffer))
+               if (write(fd, buffer.data, sizeof(buffer)) != sizeof(buffer))
                {
                        int                     save_errno = errno;
 
index 3d44bf71d19f82a3578183a86491c654ef6b508a..b2e89f09d3045cf0c386a7fb9c9f16a693514575 100644 (file)
@@ -160,7 +160,7 @@ static void
 bbsink_server_archive_contents(bbsink *sink, size_t len)
 {
        bbsink_server *mysink = (bbsink_server *) sink;
-       int                     nbytes;
+       ssize_t         nbytes;
 
        nbytes = FileWrite(mysink->file, mysink->base.bbs_buffer, len,
                                           mysink->filepos, WAIT_EVENT_BASEBACKUP_WRITE);
@@ -176,7 +176,7 @@ bbsink_server_archive_contents(bbsink *sink, size_t len)
                /* short write: complain appropriately */
                ereport(ERROR,
                                (errcode(ERRCODE_DISK_FULL),
-                                errmsg("could not write file \"%s\": wrote only %d of %zu bytes at offset %lld",
+                                errmsg("could not write file \"%s\": wrote only %zd of %zu bytes at offset %lld",
                                                FilePathName(mysink->file),
                                                nbytes, len, (long long) mysink->filepos),
                                 errhint("Check free disk space.")));
@@ -253,7 +253,7 @@ static void
 bbsink_server_manifest_contents(bbsink *sink, size_t len)
 {
        bbsink_server *mysink = (bbsink_server *) sink;
-       int                     nbytes;
+       ssize_t         nbytes;
 
        nbytes = FileWrite(mysink->file, mysink->base.bbs_buffer, len,
                                           mysink->filepos, WAIT_EVENT_BASEBACKUP_WRITE);
@@ -269,7 +269,7 @@ bbsink_server_manifest_contents(bbsink *sink, size_t len)
                /* short write: complain appropriately */
                ereport(ERROR,
                                (errcode(ERRCODE_DISK_FULL),
-                                errmsg("could not write file \"%s\": wrote only %d of %zu bytes at offset %lld",
+                                errmsg("could not write file \"%s\": wrote only %zd of %zu bytes at offset %lld",
                                                FilePathName(mysink->file),
                                                nbytes, len, (long long) mysink->filepos),
                                 errhint("Check free disk space.")));
index f0819d15ab7017153cf08b1f039b6fbab9f0f411..51dcbd9cace4f84b31aaa3ddee068974cddf963c 100644 (file)
@@ -460,7 +460,7 @@ static void
 CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
 {
        int                     fd;
-       int                     nbytes;
+       size_t          nbytes;
        char            versionfile[MAXPGPATH];
        char            buf[16];
 
@@ -500,7 +500,7 @@ CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
        /* Write PG_MAJORVERSION in the PG_VERSION file. */
        pgstat_report_wait_start(WAIT_EVENT_VERSION_FILE_WRITE);
        errno = 0;
-       if ((int) write(fd, buf, nbytes) != nbytes)
+       if (write(fd, buf, nbytes) != nbytes)
        {
                /* If write didn't set errno, assume problem is no disk space. */
                if (errno == 0)
index 1aa4a3080f51b5d73db1189fabf73462ad538ed0..10cc05d5e4bf913bfd83b5601ef0a6b299cae414 100644 (file)
@@ -488,8 +488,7 @@ be_lo_export(PG_FUNCTION_ARGS)
        Oid                     lobjId = PG_GETARG_OID(0);
        text       *filename = PG_GETARG_TEXT_PP(1);
        int                     fd;
-       int                     nbytes,
-                               tmp;
+       int                     nbytes;
        char            buf[BUFSIZE];
        char            fnamebuf[MAXPGPATH];
        LargeObjectDesc *lobj;
@@ -531,6 +530,8 @@ be_lo_export(PG_FUNCTION_ARGS)
         */
        while ((nbytes = inv_read(lobj, buf, BUFSIZE)) > 0)
        {
+               ssize_t         tmp;
+
                tmp = write(fd, buf, nbytes);
                if (tmp != nbytes)
                        ereport(ERROR,
index 855c1a9abda355410f318a72c0869556eea7f19f..c6b0c41c6d4425f5efb2f72cc10dd13252f7f9ff 100644 (file)
@@ -102,7 +102,7 @@ fork_process(void)
                        if (fd >= 0)
                        {
                                const char *oomvalue = getenv("PG_OOM_ADJUST_VALUE");
-                               int                     rc;
+                               ssize_t         rc;
 
                                if (oomvalue == NULL)   /* supply a useful default */
                                        oomvalue = "0";
index 5376519fea5caf3eeae350ffabaa0ee576dd0fc7..ff76469bcf26ecefd8e3f82f3f9fd5477e9799a0 100644 (file)
@@ -70,7 +70,7 @@ static char *libpqrcv_get_option_from_conninfo(const char *connInfo,
 static int     libpqrcv_server_version(WalReceiverConn *conn);
 static void libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
                                                                                         TimeLineID tli, char **filename,
-                                                                                        char **content, int *len);
+                                                                                        char **content, size_t *len);
 static bool libpqrcv_startstreaming(WalReceiverConn *conn,
                                                                        const WalRcvStreamOptions *options);
 static void libpqrcv_endstreaming(WalReceiverConn *conn,
@@ -738,7 +738,7 @@ libpqrcv_endstreaming(WalReceiverConn *conn, TimeLineID *next_tli)
 static void
 libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
                                                                 TimeLineID tli, char **filename,
-                                                                char **content, int *len)
+                                                                char **content, size_t *len)
 {
        PGresult   *res;
        char            cmd[64];
index 05e2f690fa792421241e48dbc21f0cbea5ad458b..429a1b2d96d1a490229abab173af999c19e5d4b1 100644 (file)
@@ -755,7 +755,7 @@ WalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)
                {
                        char       *fname;
                        char       *content;
-                       int                     len;
+                       size_t          len;
                        char            expectedfname[MAXFNAMELEN];
 
                        ereport(LOG,
@@ -913,7 +913,7 @@ static void
 XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr, TimeLineID tli)
 {
        int                     startoff;
-       int                     byteswritten;
+       ssize_t         byteswritten;
        instr_time      start;
 
        Assert(tli != 0);
index b44d24cdbd36fb4281ddcafb8abe607118c119a2..5c59913646bbb0ff2fc3d8f8d44e7f4879820d5a 100644 (file)
@@ -498,7 +498,6 @@ static void
 BufFileDumpBuffer(BufFile *file)
 {
        int64           wpos = 0;
-       int64           bytestowrite;
        File            thisfile;
 
        /*
@@ -510,6 +509,8 @@ BufFileDumpBuffer(BufFile *file)
                int64           availbytes;
                instr_time      io_start;
                instr_time      io_time;
+               size_t          bytestowrite;
+               ssize_t         rc;
 
                /*
                 * Advance to next component file if necessary and possible.
@@ -538,12 +539,12 @@ BufFileDumpBuffer(BufFile *file)
                else
                        INSTR_TIME_SET_ZERO(io_start);
 
-               bytestowrite = FileWrite(thisfile,
-                                                                file->buffer.data + wpos,
-                                                                bytestowrite,
-                                                                file->curOffset,
-                                                                WAIT_EVENT_BUFFILE_WRITE);
-               if (bytestowrite <= 0)
+               rc = FileWrite(thisfile,
+                                          file->buffer.data + wpos,
+                                          bytestowrite,
+                                          file->curOffset,
+                                          WAIT_EVENT_BUFFILE_WRITE);
+               if (rc <= 0)
                        ereport(ERROR,
                                        (errcode_for_file_access(),
                                         errmsg("could not write to file \"%s\": %m",
@@ -555,8 +556,8 @@ BufFileDumpBuffer(BufFile *file)
                        INSTR_TIME_ACCUM_DIFF(pgBufferUsage.temp_blk_write_time, io_time, io_start);
                }
 
-               file->curOffset += bytestowrite;
-               wpos += bytestowrite;
+               file->curOffset += rc;
+               wpos += rc;
 
                pgBufferUsage.temp_blks_written++;
        }
index 880c05dd6477f1bce160092b60650897367977e2..5c807c3b274b649b0b6825008eb63d2b794a051c 100644 (file)
@@ -1905,7 +1905,7 @@ latch_sigurg_handler(SIGNAL_ARGS)
 static void
 sendSelfPipeByte(void)
 {
-       int                     rc;
+       ssize_t         rc;
        char            dummy = 0;
 
 retry:
index 79febf12de3fd36f941040065ee03130299112e9..9f96d9cbbfc3e89043bb07dfc2b7f284ac901da9 100644 (file)
@@ -488,7 +488,7 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
                 const void *buffer, bool skipFsync)
 {
        pgoff_t         seekpos;
-       int                     nbytes;
+       ssize_t         nbytes;
        MdfdVec    *v;
 
        /* If this build supports direct I/O, the buffer must be I/O aligned. */
@@ -530,9 +530,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
                /* short write: complain appropriately */
                ereport(ERROR,
                                (errcode(ERRCODE_DISK_FULL),
-                                errmsg("could not extend file \"%s\": wrote only %d of %d bytes at block %u",
+                                errmsg("could not extend file \"%s\": wrote only %zd of %zu bytes at block %u",
                                                FilePathName(v->mdfd_vfd),
-                                               nbytes, BLCKSZ, blocknum),
+                                               nbytes, (size_t) BLCKSZ, blocknum),
                                 errhint("Check free disk space.")));
        }
 
@@ -1080,7 +1080,7 @@ mdwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
                struct iovec iov[PG_IOV_MAX];
                int                     iovcnt;
                pgoff_t         seekpos;
-               int                     nbytes;
+               ssize_t         nbytes;
                MdfdVec    *v;
                BlockNumber nblocks_this_segment;
                size_t          transferred_this_segment;
index a6936a0c664a9895acc49176438450217769781a..b9d2c96b97ad4fd7ad20b9845541d319a33f12e7 100644 (file)
@@ -3027,7 +3027,7 @@ write_eventlog(int level, const char *line, int len)
 static void
 write_console(const char *line, int len)
 {
-       int                     rc;
+       ssize_t         rc;
 
 #ifdef WIN32
 
@@ -3917,7 +3917,7 @@ write_pipe_chunks(char *data, int len, int dest)
 {
        PipeProtoChunk p;
        int                     fd = fileno(stderr);
-       int                     rc;
+       ssize_t         rc;
 
        Assert(len > 0);
 
index 263ae7b8d8603b1c36bf5848e1e23e001d442e2d..eddce1ce33fc7872d80c0c60b6aec6a3546542e7 100644 (file)
@@ -1522,7 +1522,8 @@ void
 AddToDataDirLockFile(int target_line, const char *str)
 {
        int                     fd;
-       ssize_t         len;
+       ssize_t         nread;
+       size_t          len;
        int                     lineno;
        char       *srcptr;
        char       *destptr;
@@ -1539,9 +1540,9 @@ AddToDataDirLockFile(int target_line, const char *str)
                return;
        }
        pgstat_report_wait_start(WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ);
-       len = read(fd, srcbuffer, sizeof(srcbuffer) - 1);
+       nread = read(fd, srcbuffer, sizeof(srcbuffer) - 1);
        pgstat_report_wait_end();
-       if (len < 0)
+       if (nread < 0)
        {
                ereport(LOG,
                                (errcode_for_file_access(),
@@ -1550,7 +1551,7 @@ AddToDataDirLockFile(int target_line, const char *str)
                close(fd);
                return;
        }
-       srcbuffer[len] = '\0';
+       srcbuffer[nread] = '\0';
 
        /*
         * Advance over lines we are not supposed to rewrite, then copy them to
index 48b269468a5fda26708cbb38213fffd7e50df6a3..2d8f12cbe30b2fb1d37cbf5d5e6b3eb1abcaecc0 100644 (file)
@@ -85,7 +85,7 @@ provider postgresql {
        probe smgr__md__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
        probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, long long int, long long int);
        probe smgr__md__write__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
-       probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int);
+       probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, long long int, long long int);
 
        probe wal__insert(unsigned char, unsigned char);
        probe wal__switch();
index bc95e4d0735b39488639879d39b1ac9fffa5eaef..40f6f65f757141c716304c9bc6c4a44eee03580f 100644 (file)
@@ -292,10 +292,10 @@ StreamLogicalLog(void)
        while (!time_to_abort)
        {
                int                     r;
-               int                     bytes_left;
-               int                     bytes_written;
+               size_t          bytes_left;
+               size_t          bytes_written;
                TimestampTz now;
-               int                     hdr_len;
+               size_t          hdr_len;
 
                cur_record_lsn = InvalidXLogRecPtr;
 
@@ -560,7 +560,7 @@ StreamLogicalLog(void)
 
                while (bytes_left)
                {
-                       int                     ret;
+                       ssize_t         ret;
 
                        ret = write(outfd,
                                                copybuf + hdr_len + bytes_written,
@@ -568,7 +568,7 @@ StreamLogicalLog(void)
 
                        if (ret < 0)
                        {
-                               pg_log_error("could not write %d bytes to log file \"%s\": %m",
+                               pg_log_error("could not write %zu bytes to log file \"%s\": %m",
                                                         bytes_left, outfile);
                                goto error;
                        }
@@ -580,8 +580,8 @@ StreamLogicalLog(void)
 
                if (write(outfd, "\n", 1) != 1)
                {
-                       pg_log_error("could not write %d bytes to log file \"%s\": %m",
-                                                1, outfile);
+                       pg_log_error("could not write %zu bytes to log file \"%s\": %m",
+                                                (size_t) 1, outfile);
                        goto error;
                }
 
index 4925e9927419205c27bbb372e45e845f3072fea7..faa60711b1b8a87662511035ffe8fd0b64bb6c03 100644 (file)
@@ -274,7 +274,7 @@ existsTimeLineHistoryFile(StreamCtl *stream)
 static bool
 writeTimeLineHistoryFile(StreamCtl *stream, const char *filename, const char *content)
 {
-       int                     size = strlen(content);
+       size_t          size = strlen(content);
        char            histfname[MAXFNAMELEN];
        Walfile    *f;
 
@@ -299,7 +299,7 @@ writeTimeLineHistoryFile(StreamCtl *stream, const char *filename, const char *co
                return false;
        }
 
-       if ((int) stream->walmethod->ops->write(f, content, size) != size)
+       if (stream->walmethod->ops->write(f, content, size) != size)
        {
                pg_log_error("could not write timeline history file \"%s\": %s",
                                         histfname, GetLastWalMethodError(stream->walmethod));
index 412c9a18f95109052878e9604feb11701139b797..3b3ae23f1a6f325553796664648ce48f1ca40969 100644 (file)
@@ -237,7 +237,7 @@ scan_file(const char *fn, int segmentno)
                }
                else if (mode == PG_MODE_ENABLE)
                {
-                       int                     w;
+                       ssize_t         w;
 
                        /*
                         * Do not rewrite if the checksum is already set to the expected
@@ -263,8 +263,8 @@ scan_file(const char *fn, int segmentno)
                                        pg_fatal("could not write block %u in file \"%s\": %m",
                                                         blockno, fn);
                                else
-                                       pg_fatal("could not write block %u in file \"%s\": wrote %d of %d",
-                                                        blockno, fn, w, BLCKSZ);
+                                       pg_fatal("could not write block %u in file \"%s\": wrote %zd of %zu",
+                                                        blockno, fn, w, (size_t) BLCKSZ);
                        }
                }
 
index c7f51f0f8c73ece5e5d6828a8d645f2f6339af14..b757e772b92b2e9ea85e91abc38e0c38fc4a1816 100644 (file)
@@ -151,18 +151,19 @@ write_backup_label(char *output_directory, StringInfo buf,
                if (!line_starts_with(s, e, "INCREMENTAL FROM LSN: ", NULL) &&
                        !line_starts_with(s, e, "INCREMENTAL FROM TLI: ", NULL))
                {
+                       const size_t bytes_left = e - s;
                        ssize_t         wb;
 
-                       wb = write(output_fd, s, e - s);
-                       if (wb != e - s)
+                       wb = write(output_fd, s, bytes_left);
+                       if (wb != bytes_left)
                        {
                                if (wb < 0)
                                        pg_fatal("could not write file \"%s\": %m", output_filename);
                                else
-                                       pg_fatal("could not write file \"%s\": wrote %d of %d",
-                                                        output_filename, (int) wb, (int) (e - s));
+                                       pg_fatal("could not write file \"%s\": wrote %zd of %zu",
+                                                        output_filename, wb, bytes_left);
                        }
-                       if (pg_checksum_update(&checksum_ctx, (uint8 *) s, e - s) < 0)
+                       if (pg_checksum_update(&checksum_ctx, (uint8 *) s, bytes_left) < 0)
                                pg_fatal("could not update checksum of file \"%s\"",
                                                 output_filename);
                }
index 0287d6e87df5eefd78039828d82afeab0e5cdb3b..740b63be559ee315bbf4358cd8b875d8a282da0f 100644 (file)
@@ -179,7 +179,7 @@ copy_file_blocks(const char *src, const char *dst,
        uint8      *buffer;
        const int       buffer_size = 50 * BLCKSZ;
        ssize_t         rb;
-       unsigned        offset = 0;
+       size_t          offset = 0;
 
        if ((src_fd = open(src, O_RDONLY | PG_BINARY, 0)) < 0)
                pg_fatal("could not open file \"%s\": %m", src);
@@ -199,8 +199,8 @@ copy_file_blocks(const char *src, const char *dst,
                        if (wb < 0)
                                pg_fatal("could not write to file \"%s\": %m", dst);
                        else
-                               pg_fatal("could not write to file \"%s\", offset %u: wrote %d of %d",
-                                                dst, offset, (int) wb, (int) rb);
+                               pg_fatal("could not write to file \"%s\", offset %zu: wrote %zd of %zu",
+                                                dst, offset, wb, (size_t) rb);
                }
 
                if (pg_checksum_update(checksum_ctx, buffer, rb) < 0)
index 3c377b749f51d38400c7ade11bdd42a4b6a84d70..e4b02746127f84dc4d1f968505b8c630002be368 100644 (file)
@@ -755,15 +755,15 @@ static void
 write_block(int fd, const char *output_filename,
                        const uint8 *buffer, pg_checksum_context *checksum_ctx)
 {
-       int                     wb;
+       ssize_t         wb;
 
        if ((wb = write(fd, buffer, BLCKSZ)) != BLCKSZ)
        {
                if (wb < 0)
                        pg_fatal("could not write file \"%s\": %m", output_filename);
                else
-                       pg_fatal("could not write file \"%s\": wrote %d of %d",
-                                        output_filename, wb, BLCKSZ);
+                       pg_fatal("could not write file \"%s\": wrote %zd of %zu",
+                                        output_filename, wb, (size_t) BLCKSZ);
        }
 
        /* Update the checksum computation. */
index 715286043b5875c748a3053d71e3991f9f972bf4..c2ab728126666c222b912dfcaa64480000a7bef5 100644 (file)
@@ -259,8 +259,8 @@ flush_manifest(manifest_writer *mwriter)
                        if (wb < 0)
                                pg_fatal("could not write file \"%s\": %m", mwriter->pathname);
                        else
-                               pg_fatal("could not write file \"%s\": wrote %zd of %d",
-                                                mwriter->pathname, wb, mwriter->buf.len);
+                               pg_fatal("could not write file \"%s\": wrote %zd of %zu",
+                                                mwriter->pathname, wb, (size_t) mwriter->buf.len);
                }
 
                if (mwriter->still_checksumming &&
index 4a0d04b646f43a4ad2a2c656e5e964c0067ea750..d6bdb60977c70852960fbc169c505081433bd8f9 100644 (file)
@@ -186,7 +186,7 @@ static CRITICAL_SECTION signal_info_lock;
 #define write_stderr(str) \
        do { \
                const char *str_ = (str); \
-               int             rc_; \
+               ssize_t rc_; \
                rc_ = write(fileno(stderr), str_, strlen(str_)); \
                (void) rc_; \
        } while (0)
@@ -1526,7 +1526,7 @@ getMessageFromLeader(int pipefd[2])
 static void
 sendMessageToLeader(int pipefd[2], const char *str)
 {
-       int                     len = strlen(str) + 1;
+       size_t          len = strlen(str) + 1;
 
        if (pipewrite(pipefd[PIPE_WRITE], str, len) != len)
                pg_fatal("could not write to the communication channel: %m");
@@ -1643,7 +1643,7 @@ getMessageFromWorker(ParallelState *pstate, bool do_wait, int *worker)
 static void
 sendMessageToWorker(ParallelState *pstate, int worker, const char *str)
 {
-       int                     len = strlen(str) + 1;
+       size_t          len = strlen(str) + 1;
 
        if (pipewrite(pstate->parallelSlot[worker].pipeWrite, str, len) != len)
        {
index 4b84f86e7d7b7677ec0454cb91c84bf944cd73e5..c51b1271f1f6e60f9ba5e17a5337e7103452a18d 100644 (file)
@@ -593,7 +593,7 @@ test_non_sync(void)
 static void
 signal_cleanup(SIGNAL_ARGS)
 {
-       int                     rc;
+       ssize_t         rc;
 
        /* Delete the file if it exists. Ignore errors */
        if (needs_unlink)
index 9fac04e333e75125016f4639b5c0fc547689ca4c..0de2ccf684c5ac5ada56a182bf41a92d08028534 100644 (file)
@@ -61,7 +61,7 @@
 #define write_stderr(str) \
        do { \
                const char *str_ = (str); \
-               int             rc_; \
+               ssize_t rc_; \
                rc_ = write(fileno(stderr), str_, strlen(str_)); \
                (void) rc_; \
        } while (0)
index 76b852d07ab090d7eaa7fb794696df0adb783463..3aee3419a5c5d70864d3badc9bc299737f9a9b12 100644 (file)
@@ -34,7 +34,7 @@ extern bool existsTimeLineHistory(TimeLineID probeTLI);
 extern TimeLineID findNewestTimeLine(TimeLineID startTLI);
 extern void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
                                                                 XLogRecPtr switchpoint, const char *reason);
-extern void writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size);
+extern void writeTimeLineHistoryFile(TimeLineID tli, const char *content, size_t size);
 extern void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end);
 extern bool tliInHistory(TimeLineID tli, List *expectedTLEs);
 extern TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history);
index 47c07574d4d82dd1dbb0d345572853e8d7e99338..760364e35870f8b9c320b22cca3c709acf0b217f 100644 (file)
@@ -309,7 +309,7 @@ typedef void (*walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn,
                                                                                                   TimeLineID tli,
                                                                                                   char **filename,
                                                                                                   char **content,
-                                                                                                  int *size);
+                                                                                                  size_t *size);
 
 /*
  * walrcv_startstreaming_fn
index 3014cae33ac1778d41c45d86833e15300116743a..19ebab22ba309fad5f211d321aa9a3f918093916 100644 (file)
@@ -749,8 +749,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
 {
        int                     result = 1;
        int                     fd;
-       int                     nbytes,
-                               tmp;
+       int                     nbytes;
        char            buf[LO_BUFSIZE];
        int                     lobj;
        char            sebuf[PG_STRERROR_R_BUFLEN];
@@ -788,6 +787,8 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
         */
        while ((nbytes = lo_read(conn, lobj, buf, LO_BUFSIZE)) > 0)
        {
+               ssize_t         tmp;
+
                tmp = write(fd, buf, nbytes);
                if (tmp != nbytes)
                {
index f73a0fcb10018e07b7b2c95e34edf0cfab4d8b0e..0b1d097edff2ad959f11a20366fe3f59dbe93b9a 100644 (file)
@@ -151,8 +151,7 @@ exportFile(PGconn *conn, Oid lobjId, char *filename)
 {
        int                     lobj_fd;
        char            buf[BUFSIZE];
-       int                     nbytes,
-                               tmp;
+       int                     nbytes;
        int                     fd;
 
        /*
@@ -177,6 +176,8 @@ exportFile(PGconn *conn, Oid lobjId, char *filename)
         */
        while ((nbytes = lo_read(conn, lobj_fd, buf, BUFSIZE)) > 0)
        {
+               ssize_t         tmp;
+
                tmp = write(fd, buf, nbytes);
                if (tmp < nbytes)
                {
index cecfa6836985a32076d2f9b50e0b59b7146d9895..3698d7f256e4d9e4f43e4080eec8b10fc94f13f2 100644 (file)
@@ -174,8 +174,7 @@ exportFile(PGconn *conn, Oid lobjId, char *filename)
 {
        int                     lobj_fd;
        char            buf[BUFSIZE];
-       int                     nbytes,
-                               tmp;
+       int                     nbytes;
        int                     fd;
 
        /*
@@ -200,6 +199,8 @@ exportFile(PGconn *conn, Oid lobjId, char *filename)
         */
        while ((nbytes = lo_read(conn, lobj_fd, buf, BUFSIZE)) > 0)
        {
+               ssize_t         tmp;
+
                tmp = write(fd, buf, nbytes);
                if (tmp < nbytes)
                {