char* pakfire_path_join(const char* first, const char* second);
-char* pakfire_basename(const char* path);
-char* pakfire_dirname(const char* path);
+const char* pakfire_basename(const char* path);
+const char* pakfire_dirname(const char* path);
int pakfire_access(Pakfire pakfire, const char* dir, const char* file, int mode);
int pakfire_mkdir(Pakfire pakfire, const char* path, mode_t mode);
Id handle = pakfire_package_get_handle(pkg);
- char* dirname = pakfire_dirname(filename);
- char* basename = pakfire_basename(filename);
+ const char* dirname = pakfire_dirname(filename);
+ const char* basename = pakfire_basename(filename);
Id did = repodata_str2dir(repodata, dirname, 1);
if (!did)
char* cache_path = pakfire_get_cache_path(pakfire, path);
// Ensure that the parent directory exists
- char* cache_dirname = pakfire_dirname(cache_path);
+ const char* cache_dirname = pakfire_dirname(cache_path);
int r = pakfire_mkdir(pakfire, cache_dirname, S_IRUSR|S_IWUSR|S_IXUSR);
if (r)
FAIL:
pakfire_free(cache_path);
- pakfire_free(cache_dirname);
return f;
}
return buffer;
}
-char* pakfire_basename(const char* path) {
+const char* pakfire_basename(const char* path) {
char* name = pakfire_strdup(path);
- return basename(name);
+ const char* r = basename(name);
+ pakfire_free(name);
+
+ return r;
}
-char* pakfire_dirname(const char* path) {
+const char* pakfire_dirname(const char* path) {
char* parent = pakfire_strdup(path);
- return dirname(parent);
+ const char* r = dirname(parent);
+ pakfire_free(parent);
+
+ return r;
}
PAKFIRE_EXPORT int pakfire_access(Pakfire pakfire, const char* dir, const char* file, int mode) {
return 0;
// If parent does not exists, we try to create it.
- char* parent = pakfire_dirname(path);
+ const char* parent = pakfire_dirname(path);
r = pakfire_access(pakfire, parent, NULL, F_OK);
if (r)
r = pakfire_mkdir(pakfire, parent, 0);
- pakfire_free(parent);
-
if (r)
return r;