Update types in File API

Make the argument types of the File API match stdio better:

- Change the data buffer to void *, from char *.
- Change FileWrite() data buffer to const on top of that.
- Change amounts to size_t, from int.

In passing, change the FilePrefetch() amount argument from int to
off_t, to match the underlying posix_fadvise().

Discussion: https://www.postgresql.org/message-id/flat/11dda853-bb5b-59ba-a746-e168b1ce4bdb%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-12-08 08:51:38 +01:00
parent 4b3e379932
commit 2d4f1ba6cf
2 changed files with 7 additions and 7 deletions

View File

@ -1980,7 +1980,7 @@ FileClose(File file)
* to read into.
*/
int
FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info)
FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info)
{
#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
int returnCode;
@ -2031,7 +2031,7 @@ FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info)
}
int
FileRead(File file, char *buffer, int amount, off_t offset,
FileRead(File file, void *buffer, size_t amount, off_t offset,
uint32 wait_event_info)
{
int returnCode;
@ -2039,7 +2039,7 @@ FileRead(File file, char *buffer, int amount, off_t offset,
Assert(FileIsValid(file));
DO_DB(elog(LOG, "FileRead: %d (%s) " INT64_FORMAT " %d %p",
DO_DB(elog(LOG, "FileRead: %d (%s) " INT64_FORMAT " %zu %p",
file, VfdCache[file].fileName,
(int64) offset,
amount, buffer));
@ -2087,7 +2087,7 @@ retry:
}
int
FileWrite(File file, char *buffer, int amount, off_t offset,
FileWrite(File file, const void *buffer, size_t amount, off_t offset,
uint32 wait_event_info)
{
int returnCode;

View File

@ -102,9 +102,9 @@ extern File PathNameOpenFile(const char *fileName, int fileFlags);
extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
extern File OpenTemporaryFile(bool interXact);
extern void FileClose(File file);
extern int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info);
extern int FileRead(File file, char *buffer, int amount, off_t offset, uint32 wait_event_info);
extern int FileWrite(File file, char *buffer, int amount, off_t offset, uint32 wait_event_info);
extern int FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info);
extern int FileRead(File file, void *buffer, size_t amount, off_t offset, uint32 wait_event_info);
extern int FileWrite(File file, const void *buffer, size_t amount, off_t offset, uint32 wait_event_info);
extern int FileSync(File file, uint32 wait_event_info);
extern off_t FileSize(File file);
extern int FileTruncate(File file, off_t offset, uint32 wait_event_info);