Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can chdir() accept relative paths?

Tags:

c

linux

chdir

In C on linux, can the chdir() function accept a relative path?

like image 617
John Moffitt Avatar asked Feb 14 '11 23:02

John Moffitt


1 Answers

Yes. The current working directory is a property of the process.


To expand on that a little - here are a couple of the relevant POSIX definitions:

  • The current working directory is defined as "a directory, associated with a process, that is used in pathname resolution for pathnames that do not begin with a slash character" (there is more detail in the section on pathname resolution).

  • chdir() is defined to set the current working directory to a pathname.

It seems somewhat circular, but there is nothing special about a "pathname" in the context of the argument chdir(); it is subject to pathname resolution as normal.

like image 72
Matthew Slattery Avatar answered Sep 30 '22 01:09

Matthew Slattery