ltrace
shows the library call. In this case, it shows the function from the libc
that the source code is calling.
If you see pwd
's source, you will see (coreutils-8.13, file lib/xgetcwd.c):
char *cwd = getcwd (NULL, 0);
So, ltrace
's output is correct: pwd
executes getcwd(NULL, 0)
. According to the Linux man page getcwd(3)
:
getcwd() allocates the buffer dynamically using malloc(3) if buf is NULL.
However, the system call getcwd(2)
always needs a first argument different from NULL, to copy there the pathname. You can see how this is done in the libc source (eglibc-3.13, file sysdeps/unix/sysv/linux/getcwd.c).
The library call getcwd(NULL, 0)
executes the system call getcwd(path, alloc_size)
, where path
is the result of a previous malloc(), and alloc_size
is the page size (4096).
To confirm this, if you run ltrace -S pwd
you will see both the library calls and the system calls: you will see something like:
getcwd(NULL, 0 <unfinished ...>
SYS_getcwd("/root", 4096) = 6
<... getcwd resumed> ) = "/root"