diff --git a/librz/include/rz_util/rz_file.h b/librz/include/rz_util/rz_file.h index 14ffeb5038..24e0962d29 100644 --- a/librz/include/rz_util/rz_file.h +++ b/librz/include/rz_util/rz_file.h @@ -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); diff --git a/librz/util/file.c b/librz/util/file.c index b117c33f89..7db372e1e1 100644 --- a/librz/util/file.c +++ b/librz/util/file.c @@ -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");