cwk_path_is_relative.md (1810B)
1 --- 2 title: cwk_path_is_relative 3 description: Determine whether the path is relative or not. 4 --- 5 6 _(since v1.0.0)_ 7 Determine whether the path is relative or not. 8 9 ## Description 10 ```c 11 bool cwk_path_is_relative(const char *path); 12 ``` 13 14 This function checks whether the path is a relative path or not. A path is considered to be relative if the root does not end with a separator. 15 16 ## Parameters 17 * **path**: The path which will be checked. 18 19 ## Return Value 20 Returns ``true`` if the path is relative or ``false`` otherwise. 21 22 ## Outcomes 23 24 | Style | Path | Result | 25 |---------|--------------------------|-----------| 26 | UNIX | ``/test/`` | ``false`` | 27 | UNIX | ``test.txt`` | ``true`` | 28 | UNIX | ``C:\test.txt`` | ``true`` | 29 | UNIX | ``\folder\`` | ``true`` | 30 | WINDOWS | ``/test.txt`` | ``false`` | 31 | WINDOWS | ``\test.txt`` | ``false`` | 32 | WINDOWS | ``C:\test.txt`` | ``false`` | 33 | WINDOWS | ``\\server\folder\data`` | ``false`` | 34 | WINDOWS | ``\\.\folder\data`` | ``false`` | 35 | WINDOWS | ``\\?\folder\data`` | ``false`` | 36 | WINDOWS | ``C:test.txt`` | ``true`` | 37 | WINDOWS | ``..\hello\world.txt`` | ``true`` | 38 39 ## Example 40 ```c 41 #include <cwalk.h> 42 #include <stdio.h> 43 #include <stddef.h> 44 #include <stdlib.h> 45 46 int main(int argc, char *argv[]) 47 { 48 if(cwk_path_is_relative("my/path.txt")) { 49 printf("The root is absolute."); 50 } else { 51 printf("The root is relative."); 52 } 53 54 return EXIT_SUCCESS; 55 } 56 ``` 57 58 Ouput: 59 ``` 60 The root is relative. 61 ``` 62 63 ## Changelog 64 65 | Version | Description | 66 |------------|--------------------------------------------------------| 67 | **v1.0.0** | The function is introduced. |