glob+x86_64 +linux

The glob module provides an implementation of file globbing compatible with the behavior described by POSIX.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/glob.html

Index

Types

type flag = enum uint {
	NONE = 0,
	// Slash appending is enabled. A slash character is appended to each
	// pathname that is a directory that matches the pattern.
	MARK = 1,
	// If the pattern does not match any pathname, the pattern string is
	// returned.
	NOCHECK = 1 << 1,
	// Backslash escaping is disabled. A backslash character is treated as
	// an ordinary character.
	NOESCAPE = 1 << 2,
	// Pathname sorting is disabled. The order of pathnames returned is
	// unspecified.
	NOSORT = 1 << 3,
};

// Undocumented types:
type generator = struct {
	pats: strstack,
	matc: size,
	flgs: flag,
	tmpp: pattern,
};
type pattern = struct {
	// TODO: look into working with a couple of string iterators instead
	dir: memio::stream,
	pat: memio::stream,
	rem: memio::stream,
};
type strstack = struct {
	bufv: []memio::stream,
	bufc: size,
};

Errors

type failure = !struct {
	// The path that cannot be opened or read.
	path: str,
	// The actual filesystem error.
	error: fs::error,
};

Functions

fn finish(gen: *generator) void;
fn glob(pattern: str, flags: flag = flag::NONE) generator;
fn next(gen: *generator) (str | done | failure);
fn strerror(err: failure) str;

Types

type flag[link]

type flag = enum uint {
	NONE = 0,
	// Slash appending is enabled. A slash character is appended to each
	// pathname that is a directory that matches the pattern.
	MARK = 1,
	// If the pattern does not match any pathname, the pattern string is
	// returned.
	NOCHECK = 1 << 1,
	// Backslash escaping is disabled. A backslash character is treated as
	// an ordinary character.
	NOESCAPE = 1 << 2,
	// Pathname sorting is disabled. The order of pathnames returned is
	// unspecified.
	NOSORT = 1 << 3,
};

Flags used to control the behavior of next.

type generator[link]

Show undocumented member
type generator = struct {
	pats: strstack,
	matc: size,
	flgs: flag,
	tmpp: pattern,
};

type pattern[link]

Show undocumented member
type pattern = struct {
	// TODO: look into working with a couple of string iterators instead
	dir: memio::stream,
	pat: memio::stream,
	rem: memio::stream,
};

type strstack[link]

Show undocumented member
type strstack = struct {
	bufv: []memio::stream,
	bufc: size,
};

Errors

type failure[link]

type failure = !struct {
	// The path that cannot be opened or read.
	path: str,
	// The actual filesystem error.
	error: fs::error,
};

Information about an unsuccessful search.

Functions

fn finish[link]

fn finish(gen: *generator) void;

Frees all memory allocated by the generator.

fn glob[link]

fn glob(pattern: str, flags: flag = flag::NONE) generator;

Returns a generator of pathnames matching a pattern. The result must be freed using finish.

fn next[link]

fn next(gen: *generator) (str | done | failure);

Returns a generated pathname. The returned string is valid until next is called again. If, during the search, a directory is encountered that cannot be opened or read, a failure object is returned instead. next can be repeatedly called until void is returned.

fn strerror[link]

fn strerror(err: failure) str;

Converts an error info a human-friendly string. The result is statically allocated.