agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Clean up readlink() return type
Date: Mon, 13 Jul 2026 09:15:16 +0000
Message-ID: <E1wjCkt-000sBZ-2r@gemulon.postgresql.org> (raw)

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@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.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(-)



Message-ID: <E1wjCkt-000sBZ-2r@gemulon.postgresql.org>
Permalink:  ../E1wjCkt-000sBZ-2r@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wjCkt-000sBZ-2r@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: peter@eisentraut.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Clean up readlink() return type
  In-Reply-To: <E1wjCkt-000sBZ-2r@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox