diff --git a/util/compressutils.c b/util/compressutils.c index efd8e88c..0a64d4e2 100644 --- a/util/compressutils.c +++ b/util/compressutils.c @@ -304,3 +304,35 @@ gvm_gzip_open_file_reader (const char *path) FILE *file = fopencookie (gz_file, "r", io_functions); return file; } + +/** + * @brief Opens a gzip file as a FILE* stream for reading and decompression. + * + * @param[in] fd File descriptor of the gzip file to open. + * + * @return The FILE* on success, NULL otherwise. + */ +FILE * +gvm_gzip_open_file_reader_fd (int fd) +{ + static cookie_io_functions_t io_functions = { + .read = gz_file_read, + .write = NULL, + .seek = NULL, + .close = gz_file_close, + }; + + if (fd < 0) + { + return NULL; + } + + gzFile gz_file = gzdopen (fd, "r"); + if (gz_file == NULL) + { + return NULL; + } + + FILE *file = fopencookie (gz_file, "r", io_functions); + return file; +} diff --git a/util/compressutils.h b/util/compressutils.h index f319952f..f5debd75 100644 --- a/util/compressutils.h +++ b/util/compressutils.h @@ -25,4 +25,7 @@ gvm_uncompress (const void *, unsigned long, unsigned long *); FILE * gvm_gzip_open_file_reader (const char *); +FILE * +gvm_gzip_open_file_reader_fd (int); + #endif /* not _GVM_COMPRESSUTILS_H */