sys.h(3)Bark

NAME

sys.h - Bark platform utilities: clocks, KV storage, files, timers, clipboard, local AI.

SYNOPSIS

Classes

struct bark_sys_cbs

Main-thread callbacks dispatched during bark_sys_poll().

struct bark_sys_cfg

Configuration options for bark_sys_create().

Typedefs

typedef struct bark_sys bark_sys_t

Opaque system capability handle.

typedef enum bark_kv_scope bark_kv_scope_t

Key-value storage persistence scope.

typedef struct bark_sys_cbs bark_sys_cbs_t

Main-thread callbacks dispatched during bark_sys_poll().

typedef struct bark_sys_cfg bark_sys_cfg_t

Configuration options for bark_sys_create().

typedef void(* bark_file_pick_fn) (void *user, const char *accept, int multi, const char *tag)

Optional callback invoked when bark_sys_file_pick_open() requests a file chooser.

typedef void(* bark_clipboard_write_fn) (void *user, const char *text)

Optional callback invoked when bark_sys_clipboard_write_text() writes clipboard text.

typedef void(* bark_store_list_cb_fn) (void *user, const char *json_array)

Completion callback for bark_sys_store_list(), delivering a JSON array string.

typedef void(* bark_local_ai_cb_fn) (void *user, int ok, const char *text_or_err)

Completion callback for browser on-device Prompt API requests.

Enumerations

enum bark_kv_scope { BARK_KV_LOCAL = 0, BARK_KV_SESSION = 1 }

Key-value storage persistence scope.

Functions

bark_sys_t * bark_sys_create (const bark_sys_cfg_t *cfg, const bark_sys_cbs_t *cbs, void *user)

Create a system capability handle.

void bark_sys_poll (bark_sys_t *sys)

Pump pending timers and OS/browser system events onto the main thread.

void bark_sys_destroy (bark_sys_t *sys)

Destroy a system handle and release resources.

uint64_t bark_sys_now_utc_ms (void)

Current wall-clock UTC timestamp in milliseconds.

uint64_t bark_sys_now_mono_ms (void)

Monotonic steady clock timestamp in milliseconds.

void bark_sys_random_bytes (uint8_t *out, size_t len)

Fill out with len cryptographically secure random bytes.

void bark_sys_uuid_v4 (char out[37])

Generate a NUL-terminated RFC 4122 version 4 UUID string (36 chars + NUL).

size_t bark_sys_url_decode (const char *src, size_t len, char *out, size_t cap)

Percent-decode src into out. Returns decoded byte length.

const char * bark_sys_guess_mime (const char *filename)

Infer an HTTP MIME content type from a filename extension.

int bark_sys_resolve_config_dir (const char *app_name, char *out, size_t cap)

Resolve the platform-standard per-user config directory for app_name (XDG/AppData/Application Support).

void bark_sys_timer_set (bark_sys_t *sys, uint32_t id, uint32_t ms, int repeat)

Schedule a one-shot or repeating timer with caller-defined id and delay ms.

void bark_sys_timer_clear (bark_sys_t *sys, uint32_t id)

Cancel a previously scheduled timer by id.

int bark_sys_kv_get (bark_sys_t *sys, bark_kv_scope_t scope, const char *key, char *out, size_t cap)

Read a string value from local or session KV storage. Returns length or negative on miss.

void bark_sys_kv_set (bark_sys_t *sys, bark_kv_scope_t scope, const char *key, const char *val)

Write a string value into local or session KV storage.

void bark_sys_kv_del (bark_sys_t *sys, bark_kv_scope_t scope, const char *key)

Delete a key from local or session KV storage.

void bark_sys_set_file_pick_hook (bark_sys_t *sys, bark_file_pick_fn fn, void *user)

Install an in-window or platform file chooser hook (no-op on browser WASM).

void bark_sys_file_pick_open (bark_sys_t *sys, const char *accept, int multi, const char *tag)

Open an asynchronous file picker filtered by accept; delivers results via on_file_picked.

uint32_t bark_sys_file_register (bark_sys_t *sys, const char *path, char *name_out, size_t name_cap, uint64_t *size_out)

Register a local file path and return an opaque file handle.

int bark_sys_file_drop (bark_sys_t *sys, const char *tag, const char *path)

Inject a dropped local file path, triggering on_file_picked with tag.

int bark_sys_file_read_chunk (bark_sys_t *sys, uint32_t handle, uint64_t offset, uint8_t *out, size_t cap)

Read up to cap bytes at offset from a registered file handle.

uint8_t * bark_sys_file_read_all (bark_sys_t *sys, uint32_t handle, uint64_t size, size_t max_bytes, size_t *len_out)

Read an entire registered file (bounded by max_bytes) into a malloc()'d buffer.

void bark_sys_file_save_bytes (bark_sys_t *sys, const char *name, const uint8_t *bytes, size_t len)

Save an in-memory buffer as a downloaded file named name.

uint32_t bark_sys_file_stream_open (bark_sys_t *sys, const char *name, uint64_t expected_size)

Open a streaming file download handle for incremental writes.

int bark_sys_file_stream_write (bark_sys_t *sys, uint32_t handle, const uint8_t *bytes, size_t len)

Append a chunk of bytes to an open streaming download handle.

void bark_sys_file_stream_close (bark_sys_t *sys, uint32_t handle, int commit)

Finalize (commit != 0) or abort (commit == 0) a streaming download handle.

void bark_sys_set_clipboard_hook (bark_sys_t *sys, bark_clipboard_write_fn fn, void *user)

Install a platform or window-system clipboard write hook.

void bark_sys_clipboard_write_text (bark_sys_t *sys, const char *text)

Copy UTF-8 text to the system clipboard.

int bark_sys_clipboard_paste_image (bark_sys_t *sys)

Request an image from the clipboard; delivers bytes via on_clipboard_image.

void bark_sys_open_external_url (const char *url)

Open an external HTTP(S) URL in the user's default browser.

int bark_sys_get_hash (bark_sys_t *sys, char *out, size_t cap)

Read the current URL hash fragment into out.

void bark_sys_set_hash (bark_sys_t *sys, const char *hash)

Update the URL hash fragment without reloading (uses history.replaceState on WASM).

int bark_sys_confirm (bark_sys_t *sys, const char *msg)

Show a synchronous confirmation dialog (returns 1 on OK / headless, 0 on cancel).

void bark_sys_store_put (bark_sys_t *sys, const char *ns, const char *key, const char *val)

Store a JSON-encoded record under namespace ns and unique key (IndexedDB on WASM, JSONL on POSIX).

void bark_sys_store_list (bark_sys_t *sys, const char *ns, const char *prefix, bark_store_list_cb_fn cb, void *user)

Asynchronously list all records in ns whose key starts with prefix as a JSON array.

void bark_sys_store_clear (bark_sys_t *sys, const char *ns)

Remove all records stored in namespace ns.

int bark_sys_local_ai_available (void)

Return non-zero if a browser on-device LanguageModel Prompt API is present.

int bark_sys_local_ai_prompt (bark_sys_t *sys, const char *system_prompt, const char *user_prompt, bark_local_ai_cb_fn cb, void *user)

Run a one-shot prompt against the browser on-device LanguageModel API.

Detailed Description

Bark platform utilities: clocks, KV storage, files, timers, clipboard, local AI.

Headless OS and browser platform primitives.

Provides clocks, timer wheel, persistent/session key-value storage, file pickers and streaming saves, clipboard integration, external URL launching, URL hash/query helpers, and CSPRNG utilities. All callbacks in bark_sys_cbs_t fire exclusively on the main thread inside bark_sys_poll().

Enumeration Type Documentation

enum bark_kv_scope

Key-value storage persistence scope.

Enumerator

BARK_KV_LOCAL
Persistent per-machine storage under config_dir (localStorage in WASM).
BARK_KV_SESSION
Ephemeral in-memory session storage (sessionStorage in WASM).

Author

Generated automatically by Doxygen for Bark from the source code.