Length of the volume prefix: "/" on POSIX, "C:/" for a drive, "//srv/share" * for a UNC share. Returns 0 when the path is not absolute. */
| 33 | /* Length of the volume prefix: "/" on POSIX, "C:/" for a drive, "//srv/share" |
| 34 | * for a UNC share. Returns 0 when the path is not absolute. */ |
| 35 | static size_t ws_volume_prefix_len(const char *path) { |
| 36 | if (!path || !path[0]) { |
| 37 | return 0; |
| 38 | } |
| 39 | /* UNC: two separators, a host, then a share. */ |
| 40 | if (ws_is_sep(path[0]) && ws_is_sep(path[1])) { |
| 41 | size_t i = 2; |
| 42 | while (path[i] && !ws_is_sep(path[i])) { /* host */ |
| 43 | i++; |
| 44 | } |
| 45 | while (ws_is_sep(path[i])) { |
| 46 | i++; |
| 47 | } |
| 48 | while (path[i] && !ws_is_sep(path[i])) { /* share */ |
| 49 | i++; |
| 50 | } |
| 51 | return i; |
| 52 | } |
| 53 | if (ws_is_sep(path[0])) { |
| 54 | return 1; |
| 55 | } |
| 56 | /* Drive-letter root, with or without a trailing separator. */ |
| 57 | if (path[1] == ':' && |
| 58 | ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z'))) { |
| 59 | return ws_is_sep(path[2]) ? 3 : 2; |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static bool ws_is_unc(const char *path) { |
| 65 | return path && ws_is_sep(path[0]) && ws_is_sep(path[1]); |
no test coverage detected