#ifndef TRANSTUI_UTIL_H
#define TRANSTUI_UTIL_H
#include <stddef.h>
#include <stdint.h>
void fmt_size(int64_t bytes, char *buf, size_t n);
void fmt_speed(int64_t bytes_per_sec, char *buf, size_t n);
void fmt_eta(int seconds, char *buf, size_t n);
void fmt_ratio(double ratio, char *buf, size_t n);
void fmt_time(long unix_time, char *buf, size_t n);
/* Base64-encodes data into out (NUL-terminated). outsize must be at least
* base64_encoded_size(len)+1. Returns encoded length, or -1 if out is too small. */
size_t base64_encoded_size(size_t len);
long base64_encode(const unsigned char *data, size_t len, char *out, size_t outsize);
/* Reads an entire file into a malloc'd buffer. Returns NULL on failure. */
unsigned char *read_file_all(const char *path, size_t *out_len);
int str_ends_with(const char *s, const char *suffix);
int str_starts_with(const char *s, const char *prefix);
/* Case-insensitive substring test. Empty needle always matches. */
int str_ci_contains(const char *haystack, const char *needle);
/* Tries to become the single running transtui instance for this user, via
* an flock() on a per-user lock file (released automatically by the kernel
* on exit or crash, so a killed process can never leave a stale lock
* around). Returns 1 if this process holds the lock (no other instance is
* running), 0 if another instance already holds it, or -1 if the lock file
* itself couldn't be opened (treat as 1 - fail open rather than block the
* user out over an unrelated filesystem error). */
int single_instance_lock(void);
#endif