1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Clean up write() return type

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 871fe4917e
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
This commit is contained in:
Peter Eisentraut
2026-07-15 10:58:13 +02:00
parent ca326e903d
commit 1f8c504e30
31 changed files with 96 additions and 85 deletions

View 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);

View 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;

View 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);

View 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;

View 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.")));

View 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)

View 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,

View 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";

View 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];

View 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);

View 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++;
}

View File

@@ -1905,7 +1905,7 @@ latch_sigurg_handler(SIGNAL_ARGS)
static void
sendSelfPipeByte(void)
{
int rc;
ssize_t rc;
char dummy = 0;
retry:

View 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;

View 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);

View 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

View 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();

View 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;
}

View 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));

View 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);
}
}

View 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);
}

View 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)

View 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. */

View 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 &&

View 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)
{

View 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)

View 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)

View 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);

View 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

View 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)
{

View 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)
{

View 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)
{