llm
Download
89 lines 4.4 KiBCModified 2026-09-01 raw
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
// A lang for filesystem paths

#pragma once

#include <stdbool.h>
#include <stdint.h>

#include "datatypes/closure.h"
#include "datatypes/path.h" // IWYU pragma: export
#include "datatypes/result.h"
#include "datatypes/typeinfo.h"
#include "integers.h"

// A path with its "." and ".." components resolved, its repeated and trailing
// slashes dropped. Unlike Path$from_str(), which takes a path that is already
// normal (a readdir(2) or glob(3) result) and only wraps it:
Path_t normalized_path(const char *str);
Path_t Path$from_str(const char *str);
Path_t Path$from_text(Text_t text);
const char *Path$as_c_string(Path_t path);
List_t Path$bytes(Path_t path);
#define Path(str) Path$from_str(str)
Path_t Path$_concat(int n, Path_t items[n]);
#define Path$concat(...) Path$_concat((int)sizeof((Path_t[]){__VA_ARGS__}) / sizeof(Path_t), ((Path_t[]){__VA_ARGS__}))
Path_t Path$resolved(Path_t path, Path_t relative_to);
Path_t Path$relative_to(Path_t path, Path_t relative_to);
Path_t Path$expand_home(Path_t path);
bool Path$exists(Path_t path);
bool Path$is_file(Path_t path, bool follow_symlinks);
bool Path$is_directory(Path_t path, bool follow_symlinks);
bool Path$is_pipe(Path_t path, bool follow_symlinks);
bool Path$is_socket(Path_t path, bool follow_symlinks);
bool Path$is_symlink(Path_t path);
bool Path$can_read(Path_t path);
bool Path$can_write(Path_t path);
bool Path$can_execute(Path_t path);
OptionalInt64_t Path$modified(Path_t path, bool follow_symlinks);
OptionalInt64_t Path$accessed(Path_t path, bool follow_symlinks);
OptionalInt64_t Path$changed(Path_t path, bool follow_symlinks);
Result_t Path$write(Path_t path, Text_t text, int permissions);
Result_t Path$write_bytes(Path_t path, List_t bytes, int permissions);
Result_t Path$append(Path_t path, Text_t text, int permissions);
Result_t Path$append_bytes(Path_t path, List_t bytes, int permissions);
Closure_t Path$byte_writer(Path_t path, bool append, int permissions);
Closure_t Path$writer(Path_t path, bool append, int permissions);
OptionalText_t Path$read(Path_t path);
OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t limit);
Result_t Path$set_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks);
OptionalText_t Path$owner(Path_t path, bool follow_symlinks);
OptionalText_t Path$group(Path_t path, bool follow_symlinks);
Result_t Path$remove(Path_t path, bool ignore_missing);
Result_t Path$move(Path_t src, Path_t dest, bool allow_overwriting);
Result_t Path$copy_to(Path_t src, Path_t dest, bool allow_overwriting);
Result_t Path$create_directory(Path_t path, int permissions, bool recursive);
OptionalList_t Path$children(Path_t path, bool include_hidden);
OptionalClosure_t Path$each_child(Path_t path, bool include_hidden);
OptionalList_t Path$files(Path_t path, bool include_hidden);
OptionalList_t Path$subdirectories(Path_t path, bool include_hidden);
OptionalPath_t Path$unique_directory(Path_t path);
OptionalPath_t Path$write_unique(Path_t path, Text_t text);
OptionalPath_t Path$write_unique_bytes(Path_t path, List_t bytes);
OptionalPath_t Path$parent(Path_t path);
OptionalText_t Path$base_name(Path_t path);
OptionalText_t Path$extension(Path_t path, bool full);
bool Path$has_extension(Path_t path, Text_t extension);
OptionalList_t Path$components(Path_t path);
Path_t Path$child(Path_t path, Text_t name);
OptionalPath_t Path$sibling(Path_t path, Text_t name);
Path_t Path$with_extension(Path_t path, Text_t extension, bool replace);
Path_t Path$current_dir(void);
Closure_t Path$by_line(Path_t path);
OptionalClosure_t Path$walk(Path_t dir, bool include_hidden, bool follow_symlinks);
OptionalList_t Path$lines(Path_t path);
OptionalList_t Path$glob(Path_t path, Text_t pattern);
bool Path$matches_glob(Path_t path, Text_t glob);

uint64_t Path$hash(const void *obj, const TypeInfo_t *);
int32_t Path$compare(const void *a, const void *b, const TypeInfo_t *type);
bool Path$equal(const void *a, const void *b, const TypeInfo_t *type);
bool Path$equal_values(Path_t a, Path_t b);
Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type);
bool Path$is_none(const void *obj, const TypeInfo_t *type);
void Path$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
void Path$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type);

extern const TypeInfo_t Path$AbsolutePath$$info;
extern const TypeInfo_t Path$RelativePath$$info;
extern const TypeInfo_t Path$HomePath$$info;
extern const TypeInfo_t Path$info;