Debian Codegraph @

src/utils-paths.c

raw
1 /*
2 * Copyright © 2024 Pierre Le Marre
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "config.h"
7
8 #include "utils.h"
9 #include "utils-paths.h"
10
11
12 /* Caller must ensure that the input is not NULL or empty */
13 bool
14 is_absolute_path(const char *path)
15 {
16 #ifdef _WIN32
17 /*
18 * A file name is relative to the current directory if it does not begin with
19 * one of the following:
20 * - A UNC name of any format, which always start with two backslash characters ("\\").
21 * - A disk designator with a backslash, for example "C:\" or "d:\".
22 * - A single backslash, for example, "\directory" or "\file.txt".
23 * See: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
24 */
25 return is_path_separator(path[0]) ||
26 (strlen_safe(path) >= 3 && path[1] == ':' && is_path_separator(path[2]));
27 #else
28 return is_path_separator(path[0]);
29 #endif
30 }