#include "util-debug.h"
#include "util-path.h"
+#ifdef OS_WIN32
+#define DIRECTORY_SEPARATOR '\\'
+#else
+#define DIRECTORY_SEPARATOR '/'
+#endif
+
/**
* \brief Check if a path is absolute
*
TmEcode PathJoin (char *out_buf, uint16_t buf_len, const char *const dir, const char *const fname)
{
SCEnter();
-#ifdef OS_WIN32
-#define DIRECTORY_SEPARATOR '\\'
-#else
-#define DIRECTORY_SEPARATOR '/'
-#endif
uint16_t max_path_len = MAX(buf_len, PATH_MAX);
int bytes_written = snprintf(out_buf, max_path_len, "%s%c%s", dir, DIRECTORY_SEPARATOR, fname);
if (bytes_written <= 0) {
return realpath(path, resolved_path);
#endif
}
+
+/*
+ * \brief Return the basename of the provided path.
+ * \param path The path on which to compute the basename
+ *
+ * \retval the basename of the path or NULL if the path lacks a non-leaf
+ */
+const char *SCBasename(const char *path)
+{
+ if (!path || strlen(path) == 0)
+ return NULL;
+
+ char *final = strrchr(path, DIRECTORY_SEPARATOR);
+ if (!final)
+ return path;
+
+ if (*(final + 1) == '\0')
+ return NULL;
+
+ return final + 1;
+}
bool SCIsRegularDirectory(const struct dirent *const dir_entry);
bool SCIsRegularFile(const struct dirent *const dir_entry);
char *SCRealPath(const char *path, char *resolved_path);
+const char *SCBasename(const char *path);
#endif /* __UTIL_PATH_H__ */