util: Promote path_is_absolute() to header

This is a trivial function that can be used elsewhere. There's no point
in keeping the assert if we are going to crash in the very next
instruction. Rather add the relevant attribute and drop the assert.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
This commit is contained in:
Lucas De Marchi 2024-11-14 09:48:30 -06:00
parent e82a548cb2
commit 63302cf655
2 changed files with 5 additions and 7 deletions

View File

@ -369,13 +369,6 @@ char *freadline_wrapped(FILE *fp, unsigned int *linenum)
/* path handling functions */
/* ************************************************************************ */
static bool path_is_absolute(const char *p)
{
assert(p != NULL);
return p[0] == '/';
}
char *path_make_absolute_cwd(const char *p)
{
_cleanup_free_ char *cwd = NULL;

View File

@ -45,6 +45,11 @@ _nonnull_(1) char *freadline_wrapped(FILE *fp, unsigned int *linenum);
/* path handling functions */
/* ************************************************************************ */
_must_check_ _nonnull_all_ char *path_make_absolute_cwd(const char *p);
static inline _must_check_ _nonnull_all_ bool path_is_absolute(const char *p)
{
return p[0] == '/';
}
int mkdir_p(const char *path, int len, mode_t mode);
int mkdir_parents(const char *path, mode_t mode);
unsigned long long stat_mstamp(const struct stat *st);