unify file locations

This commit is contained in:
2025-05-03 00:34:26 +03:00
parent c6c1435f8a
commit a4af280cda
28 changed files with 73 additions and 926 deletions

52
src/histring.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef HI_STRING_H_
#define HI_STRING_H_
#include <stddef.h>
/**
* Concatenate two strings into a buffer.
*
* If resulting string would be longer than @a buflen - 1, @a buf remains unchanged.
*
* @param bufsize Size of the destination buffer @a buf
* @param buf The destination buffer
* @param first Null terminated character string
* @param second Null terminated character string
*/
size_t hi_str_concat_buf(size_t bufsize, char buf[bufsize],
const char *first, const char *second);
/**
* Copy file content to a null terminated string, allocating memory while
* reading.
*
* Can be used for reading the virtual file system, where the file size isn't
* known. If @a nmax is non-zero, that amount of bytes is allocated and read at
* once. No more than @a nmax bytes is read in that case.
*
* In all cases, the string is reallocated to match the length before
* returning.
*
* @param filename a complete pathname to the file
* @param nread if not null, this will have the total amount bytes read
* @param nmax if not 0, this amount of memory in bytes is read and used as
* initial allocation
*/
char *hi_str_from_file(const char *filename, size_t *nread,
size_t nmax);
/**
* Return the first string from @a pathlist that is fully included in @a path.
*/
const char *hi_str_starts_with(const char path[static 1], size_t listn,
const char *pathlist[listn]);
/**
* Find if @a filename exists at the end of @a path.
*
* @return 0 if not found, positive if found
*/
int hi_path_has_filename(const char *path, const char *filename);
#endif // HI_STRING_H_