What part of this quote from the getcwd man-page am I misunderstanding?
char *getcwd(char *buf, size_t size);
...
As an extension to the POSIX.1-2001 standard, Linux (libc4, libc5,
glibc) getcwd() allocates the buffer dynamically using malloc(3) if buf
is NULL. In this case, the allocated buffer has the length size unless
size is zero, when buf is allocated as big as necessary. The caller
should free(3) the returned buffer.
because
21 char * buffer = NULL;
22 size_t bufferSize = 0;
23 getcwd(buffer, bufferSize);
24 printf("%s\n", buffer);
is causing a Seg-Fault at line 24 and gdb's backtrace tells me buffer = 0x0?
EDIT:
getcwd(buffer, bufferSize);
still doesn't work for whatever reason, but
buffer = getcwd(NULL, 0);
does