avoid excessive stack usage in getcwd
authorRich Felker <dalias@aerifal.cx>
Tue, 1 May 2018 18:46:59 +0000 (14:46 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 1 May 2018 18:46:59 +0000 (14:46 -0400)
commit375840c7d8e1f58a9bf40ced72fbe82635f49489
treeed205abe92c31fcc9ee61d16fdc232a1f6e82589
parente3c682ab5257aaa6739ef242a9676d897370e78e
avoid excessive stack usage in getcwd

to support the GNU extension of allocating a buffer for getcwd's
result when a null pointer is passed without incurring a link
dependency on free, we use a PATH_MAX-sized buffer on the stack and
only duplicate it to allocated storage after the operation succeeds.
unfortunately this imposed excessive stack usage on all callers,
including those not making use of the GNU extension.

instead, use a VLA to make stack allocation conditional.
src/unistd/getcwd.c