*/
EAPI char *eina_file_path_sanitize(const char *path);
+/**
+ * @brief When given a path, delete everything up to last slash and return
+ * the result.
+ *
+ * @param path The path string
+ * @param suffix An optional suffix to strip out
+ *
+ * @return an allocated string with the base name.
+ *
+ * When @c suffix is not NULL, it's stripped out from the final path. When
+ * the suffix doesn't match the actual suffix of the base name, nothing is
+ * stripped. Path delimiters used depend on the operating system.
+ *
+ * @since 1.11
+ */
+EAPI char *eina_file_path_basename(const char *path, const char *suffix);
/**
* @typedef Eina_File_Copy_Progress
return _eina_file_escape(eina_file_cleanup(result), len);
}
+EAPI char *
+eina_file_path_basename(const char *path, const char *suffix)
+{
+ char *str = eina_file_path_sanitize(path), *fname, *ret;
+ Eina_Array *arr = eina_file_split(str);
+ if (!arr)
+ {
+ free(str);
+ return NULL;
+ }
+ fname = eina_array_data_get(arr, eina_array_count_get(arr) - 1);
+ if (suffix && suffix[0])
+ {
+ size_t flen = strlen(fname);
+ size_t slen = strlen(suffix);
+ if (slen <= flen)
+ {
+ char *sf = fname + flen - slen;
+ if (!strcmp(suffix, sf)) *sf = '\0';
+ }
+ }
+ ret = strdup(fname);
+ free(str);
+ eina_array_free(arr);
+ return ret;
+}
+
EAPI Eina_File *
eina_file_virtualize(const char *virtual_name, const void *data, unsigned long long length, Eina_Bool copy)
{