for (;;)
{
- int nbytes = 0;
- int buf1_len = 0;
- int buf2_len = 0;
+ ssize_t nbytes = 0;
+ size_t buf1_len = 0;
+ size_t buf2_len = 0;
while (buf1_len < CMP_BUF_SIZE)
{
char buffer[BLCKSZ];
int srcfd;
int fd;
- int nbytes;
+ ssize_t nbytes;
Assert(newTLI > parentTLI); /* else bad selection of newTLI */
{
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ);
- nbytes = (int) read(srcfd, buffer, sizeof(buffer));
+ nbytes = read(srcfd, buffer, sizeof(buffer));
pgstat_report_wait_end();
if (nbytes < 0 || errno != 0)
ereport(ERROR,
break;
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
- if ((int) write(fd, buffer, nbytes) != nbytes)
+ if (write(fd, buffer, nbytes) != nbytes)
{
int save_errno = errno;
nbytes = strlen(buffer);
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
- if ((int) write(fd, buffer, nbytes) != nbytes)
+ if (write(fd, buffer, nbytes) != nbytes)
{
int save_errno = errno;
ReadTwoPhaseFile(FullTransactionId fxid, bool missing_ok)
{
char path[MAXPGPATH];
+ size_t buflen;
char *buf;
TwoPhaseFileHeader *hdr;
int fd;
uint32 crc_offset;
pg_crc32c calc_crc,
file_crc;
- int r;
+ ssize_t r;
TwoPhaseFilePath(path, fxid);
/*
* OK, slurp in the file.
*/
- buf = (char *) palloc(stat.st_size);
+ buflen = stat.st_size;
+ buf = (char *) palloc(buflen);
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_READ);
- r = read(fd, buf, stat.st_size);
- if (r != stat.st_size)
+ r = read(fd, buf, buflen);
+ if (r != buflen)
{
if (r < 0)
ereport(ERROR,
errmsg("could not read file \"%s\": %m", path)));
else
ereport(ERROR,
- (errmsg("could not read file \"%s\": read %d of %lld",
- path, r, (long long int) stat.st_size)));
+ (errmsg("could not read file \"%s\": read %zd of %zu",
+ path, r, buflen)));
}
pgstat_report_wait_end();
*/
for (nbytes = 0; nbytes < wal_segment_size; nbytes += sizeof(buffer))
{
- int nread;
+ ssize_t nread;
nread = upto - nbytes;
if (nread > 0)
{
- int r;
+ ssize_t r;
if (nread > sizeof(buffer))
nread = sizeof(buffer);
else
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
- path, r, (Size) nread)));
+ errmsg("could not read file \"%s\": read %zd of %zu",
+ path, r, nread)));
}
pgstat_report_wait_end();
}
pg_crc32c crc;
int fd;
char wal_segsz_str[20];
- int r;
+ ssize_t r;
/*
* Read data...
else
ereport(PANIC,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
XLOG_CONTROL_FILE, r, sizeof(ControlFileData))));
}
pgstat_report_wait_end();
while (nbytes > 0)
{
uint32 startoff;
- int segbytes;
- int readbytes;
+ size_t segbytes;
+ ssize_t readbytes;
startoff = XLogSegmentOffset(recptr, state->segcxt.ws_segsize);
int emode = private->emode;
uint32 targetPageOff;
XLogSegNo targetSegNo PG_USED_FOR_ASSERTS_ONLY;
- int r;
+ ssize_t r;
instr_time io_start;
Assert(AmStartupProcess() || !IsUnderPostmaster);
else
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read from WAL segment %s, LSN %X/%08X, offset %u: read %d of %zu",
+ errmsg("could not read from WAL segment %s, LSN %X/%08X, offset %u: read %zd of %zu",
fname, LSN_FORMAT_ARGS(targetPagePtr),
readOff, r, (Size) XLOG_BLCKSZ)));
goto next_record_is_invalid;
errno = errinfo->wre_errno;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read from WAL segment %s, offset %d: %m",
+ errmsg("could not read from WAL segment %s, offset %u: %m",
fname, errinfo->wre_off)));
}
else if (errinfo->wre_read == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read from WAL segment %s, offset %d: read %d of %d",
+ errmsg("could not read from WAL segment %s, offset %u: read %zd of %zu",
fname, errinfo->wre_off, errinfo->wre_read,
errinfo->wre_req)));
}
lo_import_internal(text *filename, Oid lobjOid)
{
int fd;
- int nbytes,
- tmp PG_USED_FOR_ASSERTS_ONLY;
+ ssize_t nbytes;
+ int tmp PG_USED_FOR_ASSERTS_ONLY;
char buf[BUFSIZE];
char fnamebuf[MAXPGPATH];
LargeObjectDesc *lobj;
if (rc == 1 && event.events == WL_SOCKET_READABLE)
{
- int bytesRead;
+ ssize_t bytesRead;
bytesRead = read(syslogPipe[0],
logbuffer + bytes_in_logbuffer,
{
const char *path = PG_REPLORIGIN_CHECKPOINT_FILENAME;
int fd;
- int readBytes;
+ ssize_t readBytes;
uint32 magic = REPLICATION_STATE_MAGIC;
int last_state = 0;
pg_crc32c file_crc;
else
ereport(PANIC,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
path, readBytes, sizeof(magic))));
}
COMP_CRC32C(crc, &magic, sizeof(magic));
{
ereport(PANIC,
(errcode_for_file_access(),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
path, readBytes, sizeof(disk_state))));
}
while (restored < max_changes_in_memory && *segno <= last_segno)
{
- int readBytes;
+ ssize_t readBytes;
ReorderBufferDiskChange *ondisk;
CHECK_FOR_INTERRUPTS();
else if (readBytes != sizeof(ReorderBufferDiskChange))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read from reorderbuffer spill file: read %d instead of %u bytes",
+ errmsg("could not read from reorderbuffer spill file: read %zd of %zu",
readBytes,
- (uint32) sizeof(ReorderBufferDiskChange))));
+ sizeof(ReorderBufferDiskChange))));
file->curOffset += readBytes;
else if (readBytes != ondisk->size - sizeof(ReorderBufferDiskChange))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read from reorderbuffer spill file: read %d instead of %u bytes",
+ errmsg("could not read from reorderbuffer spill file: read %zd of %zu",
readBytes,
- (uint32) (ondisk->size - sizeof(ReorderBufferDiskChange)))));
+ (ondisk->size - sizeof(ReorderBufferDiskChange)))));
file->curOffset += readBytes;
{
char path[MAXPGPATH];
int fd;
- int readBytes;
+ ssize_t readBytes;
LogicalRewriteMappingData map;
sprintf(path, "%s/%s", PG_LOGICAL_MAPPINGS_DIR, fname);
else if (readBytes != sizeof(LogicalRewriteMappingData))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read from file \"%s\": read %d instead of %d bytes",
+ errmsg("could not read from file \"%s\": read %zd of %zu",
path, readBytes,
- (int32) sizeof(LogicalRewriteMappingData))));
+ sizeof(LogicalRewriteMappingData))));
key.rlocator = map.old_locator;
ItemPointerCopy(&map.old_tid,
static void
SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
{
- int readBytes;
+ ssize_t readBytes;
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_READ);
readBytes = read(fd, dest, size);
else
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
path, readBytes, size)));
}
}
char path[MAXPGPATH + sizeof(PG_REPLSLOT_DIR) + 10];
int fd;
bool restored = false;
- int readBytes;
+ ssize_t readBytes;
pg_crc32c checksum;
TimestampTz now = 0;
else
ereport(PANIC,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
path, readBytes,
- (Size) ReplicationSlotOnDiskConstantSize)));
+ ReplicationSlotOnDiskConstantSize)));
}
/* verify magic */
else
ereport(PANIC,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
path, readBytes, (Size) cp.length)));
}
char path[MAXPGPATH];
int fd;
off_t histfilelen;
- off_t bytesleft;
+ size_t bytesleft;
Size len;
dest = CreateDestReceiver(DestRemoteSimple);
while (bytesleft > 0)
{
PGAlignedBlock rbuf;
- int nread;
+ ssize_t nread;
pgstat_report_wait_start(WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ);
nread = read(fd, rbuf.data, sizeof(rbuf));
else if (nread == 0)
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
- path, nread, (Size) bytesleft)));
+ errmsg("could not read file \"%s\": read %zd of %zu",
+ path, nread, bytesleft)));
+
+ /*
+ * We could have read more than expected if the file changed
+ * concurrently. In that case, only send as much as we expected and
+ * make sure the loop aborts properly (no wrap of bytesleft). (This
+ * isn't possible in practice, because the files are updated by atomic
+ * renames, but it's a safer programming practice.)
+ */
+ nread = Min(nread, bytesleft);
pq_sendbytes(&buf, rbuf.data, nread);
+
bytesleft -= nread;
}
File thisfile;
instr_time io_start;
instr_time io_time;
+ ssize_t rc;
/*
* Advance to next component file if necessary and possible.
/*
* Read whatever we can get, up to a full bufferload.
*/
- file->nbytes = FileRead(thisfile,
- file->buffer.data,
- sizeof(file->buffer.data),
- file->curOffset,
- WAIT_EVENT_BUFFILE_READ);
- if (file->nbytes < 0)
+ rc = FileRead(thisfile,
+ file->buffer.data,
+ sizeof(file->buffer.data),
+ file->curOffset,
+ WAIT_EVENT_BUFFILE_READ);
+ if (rc < 0)
{
file->nbytes = 0;
ereport(ERROR,
FilePathName(thisfile))));
}
+ file->nbytes = rc;
+
if (track_io_timing)
{
INSTR_TIME_SET_CURRENT(io_time);
char *buffer;
int srcfd;
int dstfd;
- int nbytes;
+ ssize_t nbytes;
off_t offset;
off_t flush_offset;
break;
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_COPY_FILE_WRITE);
- if ((int) write(dstfd, buffer, nbytes) != nbytes)
+ if (write(dstfd, buffer, nbytes) != nbytes)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
drain(void)
{
char buf[1024];
- int rc;
+ ssize_t rc;
int fd;
#ifdef WAIT_USE_SELF_PIPE
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;
char mapfilename[MAXPGPATH];
pg_crc32c crc;
int fd;
- int r;
+ ssize_t r;
Assert(elevel >= ERROR);
else
ereport(elevel,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
mapfilename, r, sizeof(RelMapFile))));
}
pgstat_report_wait_end();
int fd;
char buffer[MAXPGPATH * 2 + 256];
int ntries;
- int len;
int encoded_pid;
pid_t other_pid;
pid_t my_pid,
*/
for (ntries = 0;; ntries++)
{
+ ssize_t len;
+
/*
* Try to create the lock file --- O_EXCL makes this atomic.
*
AddToDataDirLockFile(int target_line, const char *str)
{
int fd;
- int len;
+ ssize_t len;
int lineno;
char *srcptr;
char *destptr;
RecheckDataDirLockFile(void)
{
int fd;
- int len;
+ ssize_t len;
long file_pid;
char buffer[BLCKSZ];
probe twophase__checkpoint__done();
probe smgr__md__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
- probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, 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);
r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
if (r == 1)
{
+ ssize_t nread;
char xlogend[64] = {0};
uint32 hi,
lo;
- r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
- if (r < 0)
+ nread = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
+ if (nread < 0)
pg_fatal("could not read from ready pipe: %m");
if (sscanf(xlogend, "%X/%08X", &hi, &lo) != 2)
{
int fd;
char mbuf[65536];
- int nbytes;
+ ssize_t nbytes;
/* Reject if server is too old. */
if (serverVersion < MINIMUM_VERSION_FOR_WAL_SUMMARIES)
char buf[4];
int bytes_out;
char fullpath[MAXPGPATH * 2];
- int r;
+ ssize_t r;
snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
pg_fatal("could not read compressed file \"%s\": %m",
fullpath);
else
- pg_fatal("could not read compressed file \"%s\": read %d of %zu",
+ pg_fatal("could not read compressed file \"%s\": read %zd of %zu",
fullpath, r, sizeof(buf));
}
for (blockno = 0;; blockno++)
{
uint16 csum;
- int r = read(f, buf.data, BLCKSZ);
+ ssize_t r;
+ r = read(f, buf.data, BLCKSZ);
if (r == 0)
break;
if (r != BLCKSZ)
pg_fatal("could not read block %u in file \"%s\": %m",
blockno, fn);
else
- pg_fatal("could not read block %u in file \"%s\": read %d of %d",
- blockno, fn, r, BLCKSZ);
+ pg_fatal("could not read block %u in file \"%s\": read %zd of %zu",
+ blockno, fn, r, (size_t) BLCKSZ);
}
blocks_scanned++;
uint32 initial_size;
manifest_files_hash *ht;
char *buffer;
- int rc;
JsonManifestParseContext context;
manifest_data *result;
- int chunk_size = READ_CHUNK_SIZE;
+ size_t total_size;
+ const size_t chunk_size = READ_CHUNK_SIZE;
/* Open the manifest file. */
snprintf(pathname, MAXPGPATH, "%s/backup_manifest", backup_directory);
context.per_wal_range_cb = combinebackup_per_wal_range_cb;
context.error_cb = report_manifest_error;
+ total_size = statbuf.st_size;
+
/*
* Parse the file, in chunks if necessary.
*/
- if (statbuf.st_size <= chunk_size)
+ if (total_size <= chunk_size)
{
- buffer = pg_malloc(statbuf.st_size);
- rc = read(fd, buffer, statbuf.st_size);
- if (rc != statbuf.st_size)
+ ssize_t rc;
+
+ buffer = pg_malloc(total_size);
+ rc = read(fd, buffer, total_size);
+ if (rc != total_size)
{
if (rc < 0)
pg_fatal("could not read file \"%s\": %m", pathname);
else
- pg_fatal("could not read file \"%s\": read %d of %lld",
- pathname, rc, (long long int) statbuf.st_size);
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
+ pathname, rc, total_size);
}
/* Close the manifest file. */
close(fd);
/* Parse the manifest. */
- json_parse_manifest(&context, buffer, statbuf.st_size);
+ json_parse_manifest(&context, buffer, total_size);
}
else
{
- int bytes_left = statbuf.st_size;
+ size_t bytes_left = total_size;
JsonManifestParseIncrementalState *inc_state;
inc_state = json_parse_manifest_incremental_init(&context);
while (bytes_left > 0)
{
- int bytes_to_read = chunk_size;
+ ssize_t rc;
+ size_t bytes_to_read = chunk_size;
/*
* Make sure that the last chunk is sufficiently large. (i.e. at
if (rc < 0)
pg_fatal("could not read file \"%s\": %m", pathname);
else
- pg_fatal("could not read file \"%s\": read %lld of %lld",
+ pg_fatal("could not read file \"%s\": read %zu of %zu",
pathname,
- (long long int) (statbuf.st_size + rc - bytes_left),
- (long long int) statbuf.st_size);
+ total_size + rc - bytes_left,
+ total_size);
}
bytes_left -= rc;
json_parse_manifest_incremental_chunk(inc_state, buffer, rc, bytes_left == 0);
{
struct stat st;
ssize_t rb;
+ size_t len;
/* Check file size, and complain if it's too large. */
if (fstat(fd, &st) != 0)
if (st.st_size > maxlen)
pg_fatal("file \"%s\" is too large", filename);
+ len = st.st_size;
+
/* Make sure we have enough space. */
- enlargeStringInfo(buf, st.st_size);
+ enlargeStringInfo(buf, len);
/* Read the data. */
- rb = read(fd, &buf->data[buf->len], st.st_size);
+ rb = read(fd, &buf->data[buf->len], len);
/*
* We don't expect any concurrent changes, so we should read exactly the
* expected number of bytes.
*/
- if (rb != st.st_size)
+ if (rb != len)
{
if (rb < 0)
pg_fatal("could not read file \"%s\": %m", filename);
else
- pg_fatal("could not read file \"%s\": read %zd of %lld",
- filename, rb, (long long int) st.st_size);
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
+ filename, rb, len);
}
/* Adjust buffer length for new data and restore trailing-\0 invariant */
CopyMethod copy_method,
bool debug,
bool dry_run);
-static void read_bytes(const rfile *rf, void *buffer, unsigned length);
+static void read_bytes(const rfile *rf, void *buffer, size_t length);
static void write_block(int fd, const char *output_filename,
const uint8 *buffer,
pg_checksum_context *checksum_ctx);
* Read the indicated number of bytes from an rfile into the buffer.
*/
static void
-read_bytes(const rfile *rf, void *buffer, unsigned length)
+read_bytes(const rfile *rf, void *buffer, size_t length)
{
- int rb = read(rf->fd, buffer, length);
+ ssize_t rb;
+
+ rb = read(rf->fd, buffer, length);
if (rb != length)
{
if (rb < 0)
pg_fatal("could not read file \"%s\": %m", rf->filename);
else
- pg_fatal("could not read file \"%s\": read %d of %u",
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
rf->filename, rb, length);
}
}
static void
read_block(const rfile *s, off_t off, uint8 *buffer)
{
- int rb;
+ ssize_t rb;
/* Read the block from the correct source, except if dry-run. */
rb = pg_pread(s->fd, buffer, BLCKSZ, off);
if (rb < 0)
pg_fatal("could not read from file \"%s\": %m", s->filename);
else
- pg_fatal("could not read from file \"%s\", offset %lld: read %d of %d",
- s->filename, (long long) off, rb, BLCKSZ);
+ pg_fatal("could not read from file \"%s\", offset %lld: read %zd of %zu",
+ s->filename, (long long) off, rb, (size_t) BLCKSZ);
}
}
int fd;
int nlines;
char **result;
+ size_t buflen;
char *buffer;
char *linebegin;
- int i;
int n;
- int len;
+ ssize_t nread;
struct stat statbuf;
*numlines = 0; /* in case of failure or empty file */
*result = NULL;
return result;
}
- buffer = pg_malloc(statbuf.st_size + 1);
- len = read(fd, buffer, statbuf.st_size + 1);
+ buflen = statbuf.st_size + 1;
+ buffer = pg_malloc(buflen);
+
+ nread = read(fd, buffer, buflen);
close(fd);
- if (len != statbuf.st_size)
+ if (nread != buflen - 1)
{
/* oops, the file size changed between fstat and read */
pg_free(buffer);
* any characters after the last newline will be ignored.
*/
nlines = 0;
- for (i = 0; i < len; i++)
+ for (ssize_t i = 0; i < nread; i++)
{
if (buffer[i] == '\n')
nlines++;
/* now split the buffer into lines */
linebegin = buffer;
n = 0;
- for (i = 0; i < len; i++)
+ for (ssize_t i = 0; i < nread; i++)
{
if (buffer[i] == '\n')
{
read_controlfile(void)
{
int fd;
- int len;
+ ssize_t len;
char *buffer;
pg_crc32c crc;
char *buffer;
struct stat statbuf;
char fullpath[MAXPGPATH];
- int len;
- int r;
+ size_t len;
+ ssize_t r;
snprintf(fullpath, sizeof(fullpath), "%s/%s", datadir, path);
pg_fatal("could not read file \"%s\": %m",
fullpath);
else
- pg_fatal("could not read file \"%s\": read %d of %zu",
- fullpath, r, (Size) len);
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
+ fullpath, r, len);
}
close(fd);
uint32 targetPageOff;
XLogRecPtr targetSegEnd;
XLogSegNo targetSegNo;
- int r;
+ ssize_t r;
XLByteToSeg(targetPagePtr, targetSegNo, WalSegSz);
XLogSegNoOffsetToRecPtr(targetSegNo + 1, 0, WalSegSz, targetSegEnd);
if (r < 0)
pg_log_error("could not read file \"%s\": %m", xlogfpath);
else
- pg_log_error("could not read file \"%s\": read %d of %zu",
+ pg_log_error("could not read file \"%s\": read %zd of %zu",
xlogfpath, r, (Size) XLOG_BLCKSZ);
-
return -1;
}
uint32 initial_size;
manifest_files_hash *ht;
char *buffer;
- int rc;
JsonManifestParseContext context;
manifest_data *result;
-
- int chunk_size = READ_CHUNK_SIZE;
+ size_t total_size;
+ const size_t chunk_size = READ_CHUNK_SIZE;
/* Open the manifest file. */
if ((fd = open(manifest_path, O_RDONLY | PG_BINARY, 0)) < 0)
context.per_wal_range_cb = verifybackup_per_wal_range_cb;
context.error_cb = report_manifest_error;
+ total_size = statbuf.st_size;
+
/*
* Parse the file, in chunks if necessary.
*/
- if (statbuf.st_size <= chunk_size)
+ if (total_size <= chunk_size)
{
- buffer = pg_malloc(statbuf.st_size);
- rc = read(fd, buffer, statbuf.st_size);
- if (rc != statbuf.st_size)
+ ssize_t rc;
+
+ buffer = pg_malloc(total_size);
+ rc = read(fd, buffer, total_size);
+ if (rc != total_size)
{
if (rc < 0)
pg_fatal("could not read file \"%s\": %m", manifest_path);
else
- pg_fatal("could not read file \"%s\": read %d of %lld",
- manifest_path, rc, (long long int) statbuf.st_size);
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
+ manifest_path, rc, total_size);
}
/* Close the manifest file. */
close(fd);
/* Parse the manifest. */
- json_parse_manifest(&context, buffer, statbuf.st_size);
+ json_parse_manifest(&context, buffer, total_size);
}
else
{
- int bytes_left = statbuf.st_size;
+ size_t bytes_left = total_size;
JsonManifestParseIncrementalState *inc_state;
inc_state = json_parse_manifest_incremental_init(&context);
while (bytes_left > 0)
{
- int bytes_to_read = chunk_size;
+ ssize_t rc;
+ size_t bytes_to_read = chunk_size;
/*
* Make sure that the last chunk is sufficiently large. (i.e. at
if (rc < 0)
pg_fatal("could not read file \"%s\": %m", manifest_path);
else
- pg_fatal("could not read file \"%s\": read %lld of %lld",
+ pg_fatal("could not read file \"%s\": read %zu of %zu",
manifest_path,
- (long long int) (statbuf.st_size + rc - bytes_left),
- (long long int) statbuf.st_size);
+ total_size + rc - bytes_left,
+ total_size);
}
bytes_left -= rc;
json_parse_manifest_incremental_chunk(inc_state, buffer, rc,
astreamer *streamer)
{
int fd;
- int rc;
+ ssize_t rc;
char *buffer;
pg_log_debug("reading \"%s\"", fullpath);
pg_checksum_context checksum_ctx;
const char *relpath = m->pathname;
int fd;
- int rc;
+ ssize_t rc;
uint64 bytes_read = 0;
uint8 checksumbuf[PG_CHECKSUM_MAX_LENGTH];
int checksumlen;
static bool
read_archive_file(XLogDumpPrivate *privateInfo)
{
- int rc;
+ ssize_t rc;
/* Fail if we already reached EOF in a prior call. */
if (privateInfo->archive_fd_eof)
if (fd >= 0)
{
PGAlignedXLogBlock buf;
- int r;
+ ssize_t r;
r = read(fd, buf.data, XLOG_BLCKSZ);
if (r == XLOG_BLCKSZ)
pg_fatal("could not read file \"%s\": %m",
fname);
else
- pg_fatal("could not read file \"%s\": read %d of %d",
- fname, r, XLOG_BLCKSZ);
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
+ fname, r, (size_t) XLOG_BLCKSZ);
close(fd);
return true;
}
if (errinfo.wre_errno != 0)
{
errno = errinfo.wre_errno;
- pg_fatal("could not read from file \"%s\", offset %d: %m",
+ pg_fatal("could not read from file \"%s\", offset %u: %m",
fname, errinfo.wre_off);
}
else
- pg_fatal("could not read from file \"%s\", offset %d: read %d of %d",
+ pg_fatal("could not read from file \"%s\", offset %u: read %zd of %zu",
fname, errinfo.wre_off, errinfo.wre_read,
errinfo.wre_req);
}
ControlFileData *ControlFile;
int fd;
pg_crc32c crc;
- int r;
+ ssize_t r;
#ifdef FRONTEND
pg_crc32c last_crc;
int retries = 0;
#ifndef FRONTEND
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read file \"%s\": read %d of %zu",
+ errmsg("could not read file \"%s\": read %zd of %zu",
ControlFilePath, r, sizeof(ControlFileData))));
#else
- pg_fatal("could not read file \"%s\": read %d of %zu",
+ pg_fatal("could not read file \"%s\": read %zd of %zu",
ControlFilePath, r, sizeof(ControlFileData));
#endif
}
typedef struct WALReadError
{
int wre_errno; /* errno set by the last pg_pread() */
- int wre_off; /* Offset we tried to read from. */
- int wre_req; /* Bytes requested to be read. */
- int wre_read; /* Bytes read by the last read(). */
+ uint32 wre_off; /* Offset we tried to read from. */
+ size_t wre_req; /* Bytes requested to be read. */
+ ssize_t wre_read; /* Bytes read by the last read(). */
WALOpenSegment wre_seg; /* Segment we tried to read from. */
} WALReadError;
lo_import_internal(PGconn *conn, const char *filename, Oid oid)
{
int fd;
- int nbytes,
- tmp;
+ ssize_t nbytes;
+ int tmp;
char buf[LO_BUFSIZE];
Oid lobjOid;
int lobj;
Oid lobjId;
int lobj_fd;
char buf[BUFSIZE];
- int nbytes,
- tmp;
+ ssize_t nbytes;
+ int tmp;
int fd;
/*
{
int lobj_fd;
char *buf;
- int nbytes;
+ ssize_t nbytes;
int nread;
lobj_fd = lo_open(conn, lobjId, INV_READ);
Oid lobjId;
int lobj_fd;
char buf[BUFSIZE];
- int nbytes,
- tmp;
+ ssize_t nbytes;
+ int tmp;
int fd;
/*