Check if the path is absolute or relative

How do you check if a path is absolute or relative using C on Linux?

+8
c linux path
source share
4 answers

Absolute paths usually begin with a / . Everything else is pretty much relative to the working directory.

Even directories with .. sequences in them are considered absolute if they start with / , since they end at the same position in the file system (if you do not change links and things, but this is beyond the scope of the discussion of absolute and relative).

+16
source share

Absolutely if it starts with / , otherwise relative.

+8
source share

Check if the path starts with / or not. if the path starts with / , you can consider it absolute.

+4
source share

Check if the path starts with / or not. if the path starts with /, you can assume that it is absolute, otherwise it's relative means that it will be updated from pwd (current working directory) But in Absolute case path will be updated relative to the root directory

+3
source share

All Articles