#pragma once

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>

typedef struct path {
  char*  data;
  size_t size; // Does not include null terminator. 0 if data is null.
} path;

/// Create a new path.
path path_new(const char*);

/// Free the path's memory.
void path_del(path*);

/// Return a C string from the path.
static inline const char* path_cstr(path p) { return p.data; }

/// Return true if the path is empty, false otherwise.
static inline bool path_empty(path p) {
  assert((p.data != 0) || (p.size == 0)); // null data -> 0 size
  return p.data != 0;
}

/// Returns the parent directory, or empty path if the given path has no parent.
/// The returned path is a slice of the input path; this function does not
/// allocate.
path path_parent_dir(path);

/// Concatenate two paths.
path path_concat(path left, path right);

/// Make a path relative to the parent directory of a file.
bool path_make_relative(
    const char* filepath, const char* path, char* relative,
    size_t relative_length);