Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 653b55b

Browse files
committed
Return ssize_t in fd.c I/O functions.
In the past, FileRead() and FileWrite() used types based on the Unix read() and write() functions from before C and POSIX standardization, though not exactly (we had int for amount instead of unsigned). In commit 2d4f1ba we changed to the appropriate standard C types, just like the modern POSIX functions they wrap, but again not exactly: the return type stayed as int. In theory, a ssize_t value could be returned by the underlying call that is too large for an int. That wasn't really a live bug, because we don't expect PostgreSQL code to perform reads or writes of gigabytes, and OSes probably apply internal caps smaller than that anyway. This change is done on the principle that the return might as well follow the standard interfaces consistently. Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/1672202.1703441340%40sss.pgh.pa.us
1 parent 655dc31 commit 653b55b

File tree

2 files changed

+8
-8
lines changed
  • src
    • backend/storage/file
    • include/storage

2 files changed

+8
-8
lines changed

src/backend/storage/file/fd.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2132,11 +2132,11 @@ FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info)
21322132
pgstat_report_wait_end();
21332133
}
21342134

2135-
int
2135+
ssize_t
21362136
FileReadV(File file, const struct iovec *iov, int iovcnt, off_t offset,
21372137
uint32 wait_event_info)
21382138
{
2139-
int returnCode;
2139+
ssize_t returnCode;
21402140
Vfd *vfdP;
21412141

21422142
Assert(FileIsValid(file));
@@ -2188,11 +2188,11 @@ FileReadV(File file, const struct iovec *iov, int iovcnt, off_t offset,
21882188
return returnCode;
21892189
}
21902190

2191-
int
2191+
ssize_t
21922192
FileWriteV(File file, const struct iovec *iov, int iovcnt, off_t offset,
21932193
uint32 wait_event_info)
21942194
{
2195-
int returnCode;
2195+
ssize_t returnCode;
21962196
Vfd *vfdP;
21972197

21982198
Assert(FileIsValid(file));

src/include/storage/fd.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fil
107107
extern File OpenTemporaryFile(bool interXact);
108108
extern void FileClose(File file);
109109
extern int FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info);
110-
extern int FileReadV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info);
111-
extern int FileWriteV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info);
110+
extern ssize_t FileReadV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info);
111+
extern ssize_t FileWriteV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info);
112112
extern int FileSync(File file, uint32 wait_event_info);
113113
extern int FileZero(File file, off_t offset, off_t amount, uint32 wait_event_info);
114114
extern int FileFallocate(File file, off_t offset, off_t amount, uint32 wait_event_info);
@@ -192,7 +192,7 @@ extern int durable_unlink(const char *fname, int elevel);
192192
extern void SyncDataDirectory(void);
193193
extern int data_sync_elevel(int elevel);
194194

195-
static inline int
195+
static inline ssize_t
196196
FileRead(File file, void *buffer, size_t amount, off_t offset,
197197
uint32 wait_event_info)
198198
{
@@ -204,7 +204,7 @@ FileRead(File file, void *buffer, size_t amount, off_t offset,
204204
return FileReadV(file, &iov, 1, offset, wait_event_info);
205205
}
206206

207-
static inline int
207+
static inline ssize_t
208208
FileWrite(File file, const void *buffer, size_t amount, off_t offset,
209209
uint32 wait_event_info)
210210
{

0 commit comments

Comments
 (0)