Holtorf Holtorf - 1 year ago 63
Linux Question

"getting" path in linux

I am writing a c program in linux. Commands like execv() require a path in the form of a c string. Is there a command that will return the current path in the form of a c style string?

Answer Source



#include <unistd.h>

char *getcwd(char *buf, size_t size);


The getcwd() function shall place an absolute pathname of the current working directory in the array pointed to by buf, and return buf. The pathname copied to the array shall contain no components that are symbolic links. The size argument is the size in bytes of the character array pointed to by the buf argument. If buf is a null pointer, the behavior of getcwd() is unspecified.


Upon successful completion, getcwd() shall return the buf argument. Otherwise, getcwd() shall return a null pointer and set errno to indicate the error. The contents of the array pointed to by buf are then undefined....

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download