Document rz_file_slurp_range

This commit is contained in:
Rot127 2025-03-07 08:12:45 -05:00 committed by NOT XVilka
parent feccb9bf85
commit 0d778415f3
2 changed files with 14 additions and 2 deletions

View file

@ -54,7 +54,7 @@ RZ_API ut8 *rz_deflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed,
RZ_API ut8 *rz_file_gzslurp(const char *str, int *outlen, int origonfail);
RZ_API char *rz_stdin_slurp(int *sz);
RZ_API RZ_OWN char *rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz);
RZ_API char *rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz);
RZ_API RZ_OWN char *rz_file_slurp_range(RZ_NONNULL const char *str, ut64 off, int sz, RZ_OUT RZ_NULLABLE int *osz);
RZ_API char *rz_file_slurp_random_line(const char *file);
RZ_API char *rz_file_slurp_random_line_count(const char *file, int *linecount);
RZ_API ut8 *rz_file_slurp_hexpairs(const char *str, int *usz);

View file

@ -592,7 +592,19 @@ RZ_API ut8 *rz_file_slurp_hexpairs(const char *str, int *usz) {
return ret;
}
RZ_API char *rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz) {
/**
* \brief Reads \p sz bytes from the file \p str at \p off. Note, this function
* doesn't support files larger than INT_MAX bytes currently.
*
* \param str The file name.
* \param off The offset to start reading in the file.
* \param sz The number of bytes to read.
* \param osz If not NULL, the number of bytes read.
*
* \return Buffer with the read content. The buffer is always '\0' terminated.
*/
RZ_API RZ_OWN char *rz_file_slurp_range(RZ_NONNULL const char *str, ut64 off, int sz, RZ_OUT RZ_NULLABLE int *osz) {
rz_return_val_if_fail(str, NULL);
char *ret;
size_t read_items;
FILE *fd = rz_sys_fopen(str, "rb");