tests: switch from get_current_dir_name to getcwd(0, NULL)

get_current_dir_name exists on GNU libc only, so not portable.
On the other hand, while POSIX leaves a null buffer argument for getcwd
as unspecified behaviour, basically the most used/important Unix
implementations (GNU libc, FreeBSD's libc, etc) allow such value,
returning a new allocated buffer with the current directory.

In any case, the change just affects two tests, so even if it hits a
libc not implementing this behaviour for getcwd, only tests are
affected.
This commit is contained in:
Pino Toscano
2014-10-22 18:13:49 +02:00
parent 3784a42d03
commit 7fcac5f59f
2 changed files with 3 additions and 3 deletions

View File

@@ -28,7 +28,7 @@
int
main (int argc, char *argv[])
{
char *cwd = get_current_dir_name();
char *cwd = getcwd(NULL, 0);
printf("%s", cwd);
exit (EXIT_SUCCESS);

View File

@@ -70,9 +70,9 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
cwd = get_current_dir_name ();
cwd = getcwd (NULL, 0);
if (cwd == NULL) {
perror ("get_current_dir_name");
perror ("getcwd");
exit (EXIT_FAILURE);
}