Skip to content

Commit

Permalink
Add: Added a function that opens a gzip file for reading via a file d…
Browse files Browse the repository at this point in the history
…escriptor.
  • Loading branch information
jhelmold committed Oct 21, 2024
1 parent a8eb3ce commit 85c071c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions util/compressutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 316 in util/compressutils.c

View check run for this annotation

Codecov / codecov/patch

util/compressutils.c#L316

Added line #L316 was not covered by tests
{
static cookie_io_functions_t io_functions = {
.read = gz_file_read,
.write = NULL,
.seek = NULL,
.close = gz_file_close,
};

if (fd < 0)

Check warning on line 325 in util/compressutils.c

View check run for this annotation

Codecov / codecov/patch

util/compressutils.c#L325

Added line #L325 was not covered by tests
{
return NULL;

Check warning on line 327 in util/compressutils.c

View check run for this annotation

Codecov / codecov/patch

util/compressutils.c#L327

Added line #L327 was not covered by tests
}

gzFile gz_file = gzdopen (fd, "r");
if (gz_file == NULL)

Check warning on line 331 in util/compressutils.c

View check run for this annotation

Codecov / codecov/patch

util/compressutils.c#L330-L331

Added lines #L330 - L331 were not covered by tests
{
return NULL;

Check warning on line 333 in util/compressutils.c

View check run for this annotation

Codecov / codecov/patch

util/compressutils.c#L333

Added line #L333 was not covered by tests
}

FILE *file = fopencookie (gz_file, "r", io_functions);
return file;

Check warning on line 337 in util/compressutils.c

View check run for this annotation

Codecov / codecov/patch

util/compressutils.c#L336-L337

Added lines #L336 - L337 were not covered by tests
}
3 changes: 3 additions & 0 deletions util/compressutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 85c071c

Please sign in to comment.