From 2d4f1ba6cfc2f0a977f1c30bda9848041343e248 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 8 Dec 2022 08:51:38 +0100 Subject: [PATCH] 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 --- src/backend/storage/file/fd.c | 8 ++++---- src/include/storage/fd.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 4151cafec5..f6c9382023 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -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; diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index c0a212487d..7144fc9f60 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -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);