poll tests: Avoid test failure on BSD and Solaris systems.
[gnulib.git] / doc / posix-functions / getcwd.texi
blob9ca0ae377ee63f179c7e0cfa7e52b7ad880af698
1 @node getcwd
2 @section @code{getcwd}
3 @findex getcwd
5 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html}
7 LSB specification:@* @url{https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib-getcwd.html}
9 Gnulib module: getcwd or getcwd-lgpl
11 Portability problems fixed by either Gnulib module @code{getcwd} or
12 @code{getcwd-lgpl}:
13 @itemize
14 @item
15 This function is declared in different header files (namely, @code{<io.h>} or
16 @code{<direct.h>}) on some platforms:
17 mingw, MSVC 14.
18 @item
19 On glibc and Solaris 11.4 platforms,
20 @code{getcwd (NULL, n)} allocates memory for the result.
21 On some other platforms, this call is not allowed.
22 @item
23 On some platforms, the prototype for @code{getcwd} uses @code{int}
24 instead of @code{size_t} for the size argument when using non-standard
25 headers, and the declaration is missing from @code{<unistd.h>}:
26 mingw, MSVC 14.
27 @item
28 On some platforms, @code{getcwd (buf, 0)} crashes:
29 MSVC 14.
30 @item
31 On some platforms, @code{getcwd (buf, 0)} fails with @code{ERANGE}
32 instead of the required @code{EINVAL}:
33 mingw.
34 @end itemize
36 Portability problems fixed by Gnulib module @code{getcwd}:
37 @itemize
38 @item
39 This function does not handle long file names (greater than @code{PATH_MAX})
40 correctly on some platforms:
41 glibc on Linux 2.4.20, Mac OS X 10.13, FreeBSD 6.4, NetBSD 9.0, OpenBSD 4.9, AIX 7.1.
42 @end itemize
44 Portability problems not fixed by Gnulib:
45 @itemize
46 @item
47 When using @code{getcwd(NULL, nonzero)}, some platforms, such as glibc
48 or cygwin, allocate exactly @code{nonzero} bytes and fail with
49 @code{ERANGE} if it was not big enough, while other platforms, such as
50 FreeBSD, mingw, or MSVC 14, ignore the size argument and allocate whatever size
51 is necessary.  If this call succeeds, an application cannot portably
52 access beyond the string length of the result.
53 @end itemize