Lassi
Lassi

Reputation: 3950

Are realpath() portability concerns obsolete?

The traditional way to call the Unix realpath() function has been realpath(pathname, buf) where buf is a user-supplied buffer with room for PATH_MAX bytes. This is problematic since PATH_MAX is unnecessarily big for most filenames and yet can be smaller than the actual OS pathname length limit.

The ability to pass a NULL pointer in place of buf was later added. In this case realpath() will dynamically allocate a buffer of the right size using malloc(). This makes the function easy to use safely. Since NULL support was a later addition, it was not universally implemented and hence portable programs could not rely on it.

POSIX Issue 7, 2018 edition now guarantees NULL support. Endorsement by POSIX would seem to imply that the portability concerns have all but vanished. Are there any Unix systems in active use (e.g. from the last decade) where realpath() does not support giving a NULL buffer?

Upvotes: 4

Views: 451

Answers (2)

Bruno Haible
Bruno Haible

Reputation: 1282

According to the Gnulib documentation, the Gnulib developers last saw this issue on

  • Mac OS X 10.5 (end of support in 2011),
  • FreeBSD 6.4 (end of support in 2010),
  • OpenBSD 4.4 (end of support in 2009),
  • Solaris 10 (end of support in 2024).

Upvotes: 1

Lassi
Lassi

Reputation: 3950

realpath(path, NULL) works on recent releases of at least the following systems:

  • Darwin
  • DragonFly BSD
  • FreeBSD
  • Haiku
  • Linux/glibc
  • Linux/musl
  • Minix
  • NetBSD
  • OpenBSD
  • Solaris (OmniOS)

Upvotes: 1

Related Questions