more POSIX 2008 cleanup: strnlen(), rindex()

Started by Peter Eisentraut3 months ago4 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

It has previously been established that POSIX 2008 is the baseline for
PostgreSQL code (modulo Windows). Looking through the POSIX 2008
changes, I found a few more things we can clean up with respect to that.

The first patch removes the configure checks for strnlen(), since that
is now required, and I see that all buildfarm members support. There
was some discussion in the commit messages that added these checks
(e.g., commit 8a241792f96) that suggests it was once required, but I did
not find any information about which platforms were affected then. But
that's 8 years ago now, so I think it might be obsolete.

The second patch replaces the single remaining use of rindex() with the
equivalent strrchr(). rindex() has been removed from POSIX.

Attachments:

0001-strnlen-is-now-required.patchtext/plain; charset=UTF-8; name=0001-strnlen-is-now-required.patchDownload+1-73
0002-Remove-use-of-rindex-function.patchtext/plain; charset=UTF-8; name=0002-Remove-use-of-rindex-function.patchDownload+1-2
#2Jelte Fennema-Nio
postgres@jeltef.nl
In reply to: Peter Eisentraut (#1)
Re: more POSIX 2008 cleanup: strnlen(), rindex()

On Sat, 3 Jan 2026 at 10:52, Peter Eisentraut <peter@eisentraut.org> wrote:

It has previously been established that POSIX 2008 is the baseline for
PostgreSQL code (modulo Windows). Looking through the POSIX 2008
changes, I found a few more things we can clean up with respect to that.

Both changes look sensible to me

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jelte Fennema-Nio (#2)
Re: more POSIX 2008 cleanup: strnlen(), rindex()

Jelte Fennema-Nio <postgres@jeltef.nl> writes:

On Sat, 3 Jan 2026 at 10:52, Peter Eisentraut <peter@eisentraut.org> wrote:

It has previously been established that POSIX 2008 is the baseline for
PostgreSQL code (modulo Windows). Looking through the POSIX 2008
changes, I found a few more things we can clean up with respect to that.

Both changes look sensible to me

+1. I also checked the buildfarm and confirm that no animals report
not having strnlen().

I'm a little disturbed by the rindex bit, because that's not hoary old
code: it came in with JIT in v11, only about 8 years ago. How can we
prevent similar mistakes in future?

regards, tom lane

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#3)
Re: more POSIX 2008 cleanup: strnlen(), rindex()

On 03.01.26 18:42, Tom Lane wrote:

Jelte Fennema-Nio <postgres@jeltef.nl> writes:

On Sat, 3 Jan 2026 at 10:52, Peter Eisentraut <peter@eisentraut.org> wrote:

It has previously been established that POSIX 2008 is the baseline for
PostgreSQL code (modulo Windows). Looking through the POSIX 2008
changes, I found a few more things we can clean up with respect to that.

Both changes look sensible to me

+1. I also checked the buildfarm and confirm that no animals report
not having strnlen().

committed

I'm a little disturbed by the rindex bit, because that's not hoary old
code: it came in with JIT in v11, only about 8 years ago. How can we
prevent similar mistakes in future?

AFAICT, rindex() doesn't exist on Windows, so we only got away with it
because the JIT code is not compiled under Windows. So in general this
should regulate itself.