robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

taofeat(path): fnamemodify(':h') preserves logical root #40447fa9b3381bc

master
2.4 KiB74 linesraw
1#pragma once
2
3#include <uv.h>
4
5/// Currently supports Windows and is extensible.
6/// @see https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
7typedef enum {
8  kPathUnknown = 0,
9  kPathGeneric,     ///< foo/bar or /foo/bar
10  kPathDrive,       ///< C:/foo/bar
11  kPathUNC,         ///< //server/share/foo/bar
12  kPathDevice,      ///< //?/C:/foo/bar or //?/Volume{xxx}/foo/bar
13  kPathDeviceUNC,   ///< //?/UNC/server/share/foo/bar
14} PathType;
15
16/// Struct which encapsulates file stat and path information.
17///
18/// A path is divided into three parts: prefix, logical root, rest.
19/// Examples:
20///   foo/bar  generic relative path
21///   ^------- rest
22///
23///   /foo/bar  generic absolute path
24///   ^^------- rest
25///   +-------- root & prefix
26///
27///   C:foo/bar  Windows drive path, relative path
28///   ^ ^------- rest
29///   +--------- root & prefix
30///
31///   C:/foo/bar  Windows drive path, absolute path
32///   ^  ^------- rest
33///   +---------- root & prefix
34///
35///   //?/C:/foo/bar  Windows device path
36///   ^   ^  ^------- rest
37///       +---------- root
38///   +-------------- prefix
39///
40///   //server/share/foo/bar  Windows UNC path
41///   ^              ^------- rest
42///   +---------------------- root & prefix
43///
44///   //?/UNC/server/share/foo/bar  Windows device UNC path
45///   ^       ^            ^------- rest
46///           +-------------------- root
47///   +---------------------------- prefix
48typedef struct {
49  uv_stat_t stat;  ///< @private
50
51  size_t prefix_off;  ///< Offset where the type-determining prefix starts.
52  size_t root_off;  ///< Offset where the logical root starts.
53  size_t rest_off;  ///< Offset where the remaining path starts.
54  PathType type;
55} FileInfo;
56
57/// Struct which encapsulates inode/dev_id information.
58typedef struct {
59  uint64_t inode;      ///< @private The inode of the file
60  uint64_t device_id;  ///< @private The id of the device containing the file
61} FileID;
62
63#define FILE_ID_EMPTY (FileID) { .inode = 0, .device_id = 0 }
64
65typedef struct {
66  uv_fs_t request;  ///< @private The request to uv for the directory.
67  uv_dirent_t ent;  ///< @private The entry information.
68} Directory;
69
70// Values returned by os_nodetype()
71#define NODE_NORMAL     0  // file or directory, check with os_isdir()
72#define NODE_WRITABLE   1  // something we can write to (character
73                           // device, fifo, socket, ..)
74#define NODE_OTHER      2  // non-writable thing (e.g., block device)