mirror of
https://github.com/linux-msm/qdl.git
synced 2026-10-07 06:29:17 -07:00
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>
27 lines
632 B
C
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
|