From: Michael Tremer Date: Wed, 1 Jan 2025 16:25:20 +0000 (+0000) Subject: ELF: Store the path X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aeae89389a84a2d8a7e7eed74ec9b36e746ece95;p=people%2Fric9%2Fpakfire.git ELF: Store the path Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/elf.c b/src/libpakfire/elf.c index cb41c4718..1f58f9af9 100644 --- a/src/libpakfire/elf.c +++ b/src/libpakfire/elf.c @@ -19,9 +19,11 @@ #############################################################################*/ #include +#include #include #include +#include // libelf #include @@ -31,6 +33,9 @@ struct pakfire_elf { struct pakfire_ctx* ctx; int nrefs; + // Path + char path[PATH_MAX]; + // File Descriptor int fd; @@ -58,7 +63,8 @@ static void pakfire_elf_free(struct pakfire_elf* self) { free(self); } -int pakfire_elf_open(struct pakfire_elf** elf, struct pakfire_ctx* ctx, int fd) { +int pakfire_elf_open(struct pakfire_elf** elf, + struct pakfire_ctx* ctx, const char* path, int fd) { struct pakfire_elf* self = NULL; int r; @@ -77,6 +83,11 @@ int pakfire_elf_open(struct pakfire_elf** elf, struct pakfire_ctx* ctx, int fd) // Initialize the reference counter self->nrefs = 1; + // Store the path + r = pakfire_string_set(self->path, path); + if (r < 0) + goto ERROR; + // Store the file descriptor self->fd = dup(fd); if (self->fd < 0) { @@ -122,3 +133,7 @@ struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self) { pakfire_elf_free(self); return NULL; } + +const char* pakfire_elf_path(struct pakfire_elf* self) { + return self->path; +} diff --git a/src/libpakfire/include/pakfire/elf.h b/src/libpakfire/include/pakfire/elf.h index 7d5a55e51..7a04a6f25 100644 --- a/src/libpakfire/include/pakfire/elf.h +++ b/src/libpakfire/include/pakfire/elf.h @@ -28,11 +28,14 @@ struct pakfire_elf; #include -int pakfire_elf_open(struct pakfire_elf** elf, struct pakfire_ctx* ctx, int fd); +int pakfire_elf_open(struct pakfire_elf** elf, + struct pakfire_ctx* ctx, const char* path, int fd); struct pakfire_elf* pakfire_elf_ref(struct pakfire_elf* self); struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self); +const char* pakfire_elf_path(struct pakfire_elf* self); + #endif /* PAKFIRE_PRIVATE */ #endif /* PAKFIRE_ELF_H */