Files
qdl/pathbuf.h
T
Bjorn Andersson 1d52d77ac1 qdl: Introduce pathbuf abstraction
There is a growing number of path concatenation cases, each built on
some memory allocation scheme and some variant of sprintf.

Introduce a pathbuf type and a few primitive operations to reset the
pathbuf, clone a pathbuf, push a path/filename to the pathbuf, get the
path, and truncate the path by dirname().

Also provide a convenient qdl_path_exist() operation to test if the
pathbuf refers to an existing file.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-05-14 16:39:30 -05:00

27 lines
632 B
C

/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
#ifndef __PATHBUF_H__
#define __PATHBUF_H__
#include <stdbool.h>
#include <limits.h>
#include <stddef.h>
struct pathbuf {
char buf[PATH_MAX];
size_t len;
};
void qdl_pathbuf_reset(struct pathbuf *path);
void qdl_pathbuf_dup(struct pathbuf *dst, const struct pathbuf *orig);
int qdl_pathbuf_push(struct pathbuf *path, const char *component);
const char *qdl_pathbuf_str(const struct pathbuf *path);
void qdl_pathbuf_dirname(struct pathbuf *path);
bool qdl_path_exists(const struct pathbuf *path);
#endif