summaryrefslogtreecommitdiff
path: root/src/unistd/getcwd.c
AgeCommit message (Collapse)AuthorLines
2018-05-01avoid excessive stack usage in getcwdRich Felker-2/+2
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.
2018-02-07make getcwd fail if it cannot obtain an absolute pathDmitry V. Levin-1/+7
Currently getcwd(3) can succeed without returning an absolute path because the underlying getcwd syscall, starting with linux commit v2.6.36-rc1~96^2~2, may succeed without returning an absolute path. This is a conformance issue because "The getcwd() function shall place an absolute pathname of the current working directory in the array pointed to by buf, and return buf". Fix this by checking the path returned by syscall and failing with ENOENT if the path is not absolute. The error code is chosen for consistency with the case when the current directory is unlinked. Similar issue was fixed in glibc recently, see https://sourceware.org/bugzilla/show_bug.cgi?id=22679
2013-10-08fix errno value for getcwd when size argument is zeroRich Felker-1/+7
based on patch by Michael Forney. at the same time, I've changed the if branch to be more clear, avoiding the comma operator. the underlying issue is that Linux always returns ERANGE when size is too short, even when it's zero, rather than returning EINVAL for the special case of zero as required by POSIX.
2012-03-01support null buffer argument to getcwd, auto-allocating behaviorRich Felker-1/+6
this is a popular extension some programs depend on, and by using a temporary buffer and strdup rather than malloc prior to the syscall, i've avoided the dependency on free and thus minimized the bloat cost of supporting this feature.
2011-03-20global cleanup to use the new syscall interfaceRich Felker-1/+1
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+8