From fd1a43dbf894d37256bbf104dbcd3b341f8f1bee Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 24 Apr 2025 16:46:04 +0200 Subject: Posix 2008 doesn't say getcwd allocates, actually --- faq/foo_max.mdwn | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/faq/foo_max.mdwn b/faq/foo_max.mdwn index 5f736680..cf5f80ba 100644 --- a/faq/foo_max.mdwn +++ b/faq/foo_max.mdwn @@ -35,8 +35,9 @@ memory page, thus a TLB lookup) when manipulating a lot of paths. Allocating dynamically would use much less memory. Most often interfaces can be made to properly allocate dynamically. Notably, -since Posix 2008 `realpath(path, NULL)` and `getcwd(NULL, 0)` allocate the path -dynamically. +since Posix 2008 `realpath(path, NULL)` allocates the path dynamically. +Posix 2008 does not say that `getcwd(NULL, 0)` allocates the path dynamically, +but BSD, Linux, and even windows do. In general, using `FOO_MAX` in source code (with a large value) leads to code that is not actually checking against overflows. `PATH_MAX` being 4096 is -- cgit v1.2.3