Re: Switch buffile.c/h to use pgoff_t

Chao Li <li.evan.chao@gmail.com>

From: Chao Li <li.evan.chao@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>, Bryan Green <dbryan.green@gmail.com>
Date: 2025-12-24T09:01:57Z
Lists: pgsql-hackers

Attachments

On Wed, Dec 24, 2025 at 2:15 PM Michael Paquier <michael@paquier.xyz> wrote:

> On Tue, Dec 23, 2025 at 10:59:45AM +0800, Chao Li wrote:
> > I’ve attached a small patch along these lines. It compiles without
> > warnings, and "make check" passes on my side. What do you think?
>
> I don't think it is right.  bytestowrite is not a file offset, and the
> code has been using an int due to BufFile->nbytes.  This leads to a
> more confusing result.
> --
> Michael
>

Make sense, bytestowrite is not a file offset. So, in the current code,
availbytes is not a file offset either, but it is defined as pgoff_t, which
has the same confusion, right? Also bytestowrite is casted to pgoff_t, it's
the same confusion again.

How about using "ssize_t" for both bytestowrite and availbytes? It's still
signed, broader than int, and the odd type casts are eliminated.

In win32_port.h:
```
#ifndef _WIN64
typedef long ssize_t;
#else
typedef __int64 ssize_t;
#endif
```

Best regards,
==
Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/