getcwd マンページからのこの引用のどの部分を誤解していますか?
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.
なぜなら
21 char * buffer = NULL;
22 size_t bufferSize = 0;
23 getcwd(buffer, bufferSize);
24 printf("%s\n", buffer);
行 24 で Seg-Fault が発生しており、gdb のバックトレースで buffer = 0x0 と表示されますか?
編集:
getcwd(buffer, bufferSize);
何らかの理由でまだ機能しませんが、
buffer = getcwd(NULL, 0);
する