Recent versions of GNU libc and GCC produce a warning on getcwd(0, PATH_MAX):
test_main.c: In function ‘get_refdir’:
test_main.c:3684:8: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=nonnull]
3684 | pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
This is because getcwd() is marked with the 'write_only (1, 2)' attribute.
Using the alternate getcwd(NULL, 0) path which is supported by GNU libc avoids this.
*/
/* Save current working directory. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
initial_cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
#else
initial_cwd = getcwd(NULL, 0);
failure(
"Current working directory does not return to the initial"
"directory");
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
#else
cwd = getcwd(NULL, 0);
/* Check if the filesystem where CWD on can
* report the number of the holes of a sparse file. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
#else
cwd = getcwd(NULL, 0);
/* Check if the filesystem where CWD on can
* report the number of the holes of a sparse file. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
#else
cwd = getcwd(NULL, 0);
}
/* Get the current dir. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
#else
pwd = getcwd(NULL, 0);
(void)argc; /* UNUSED */
/* Get the current dir. */
-#ifdef PATH_MAX
+#if defined(PATH_MAX) && !defined(__GLIBC__)
pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
#else
pwd = getcwd(NULL, 0);