pgsql: Clean up readlink() return type

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Clean up readlink() return type
Date: 2026-07-13 09:15:16
Message-ID: E1wjCkt-000sBZ-2r@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Clean up readlink() return type

The return type of readlink() per POSIX is ssize_t, but most existing
callers use int, so fix that. Also fix the return type of the Windows
implementation to match.

In _pglstat64(), we neglected to handle the case where the output
buffer is not large enough and the result would be truncated. This
case actually can't happen, because the Windows pgreadlink()
implementation doesn't ever return that case, but adding this seems
good for consistency with _pgstat64(), which already had this check,
and in case pgreadlink() ever changes in this regard.

Some callers of readlink(), in particular _pglstat64(), assume that
errno == EINVAL means that the file was not a symlink. But Windows
pgreadlink() also sets EINVAL in other cases, in particular if the
buffer was too small. This could result in incorrect behavior, so
pick a different errno. (There might be other cases where EINVAL is
set inappropriately, but they are outside the theme of this patch.)

Reviewed-by: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406(at)eisentraut(dot)org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/302222eddc3967d11c11708a59bdafd6d51da556

Modified Files
--------------
src/backend/access/transam/xlog.c | 2 +-
src/backend/backup/basebackup.c | 2 +-
src/backend/catalog/pg_tablespace.c | 2 +-
src/bin/initdb/findtimezone.c | 2 +-
src/bin/pg_combinebackup/pg_combinebackup.c | 2 +-
src/bin/pg_rewind/file_ops.c | 2 +-
src/include/port.h | 2 +-
src/include/port/win32_port.h | 2 +-
src/port/dirmod.c | 14 ++++++++++++--
src/port/win32stat.c | 7 ++++++-
10 files changed, 26 insertions(+), 11 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-07-13 10:13:58 pgsql: Translation updates
Previous Message Amit Kapila 2026-07-13 03:58:37 pgsql: Don't show tables redundantly when their schema is published.