Next: getdate
, Previous: getchar_unlocked
, Up: ISO C and POSIX Function Substitutes [Contents][Index]
getcwd
POSIX specification:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html
LSB specification:
https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib-getcwd.html
Gnulib module: getcwd or getcwd-lgpl
Portability problems fixed by either Gnulib module getcwd
or
getcwd-lgpl
:
<io.h>
or
<direct.h>
) on some platforms:
mingw, MSVC 14.
getcwd (NULL, n)
allocates memory for the result.
On some other platforms, this call is not allowed.
getcwd
uses int
instead of size_t
for the size argument when using non-standard
headers, and the declaration is missing from <unistd.h>
:
mingw, MSVC 14.
getcwd (buf, 0)
crashes:
MSVC 14.
getcwd (buf, 0)
fails with ERANGE
instead of the required EINVAL
:
mingw.
Portability problems fixed by Gnulib module getcwd
:
PATH_MAX
)
correctly on some platforms:
glibc on Linux 2.4.20, musl libc 1.2.2/powerpc64le, macOS 13, FreeBSD 6.4, NetBSD 10.0, OpenBSD 6.7, AIX 7.1.
Portability problems not fixed by Gnulib:
getcwd(NULL, nonzero)
, some platforms, such as glibc
or cygwin, allocate exactly nonzero
bytes and fail with
ERANGE
if it was not big enough, while other platforms, such as
FreeBSD, mingw, or MSVC 14, ignore the size argument and allocate whatever size
is necessary. If this call succeeds, an application cannot portably
access beyond the string length of the result.