From cb432fd306073bebcbddfeffb704e1101a26e579 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 18 Feb 2023 22:34:17 +0100 Subject: [PATCH] docs: Fix potentially confusing statement First we're saying "reads up to max" and then "always reads up to metadata.size, regardless of max". We actually mean that we never read more than metadata.size, so that's what this patched text says. --- docs/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index 4fc1298..bbf881d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -84,7 +84,7 @@ This function can be called as many times as desired, and at any given point in This function returns the number of bytes read, or 0 on error. 0 might also be a successful return value (if `max` is 0 or the entry's size is 0, for example), which means `errno` should be checked to see if 0 means error or simply 0 bytes read. -`minitar_read_contents()` only reads up to `metadata.size`, regardless of the value in `max`. +`minitar_read_contents()` will never read more than `metadata.size`, regardless of the value in `max`. (so, if `max == SIZE_MAX`, `minitar_read_contents()` will always read `metadata.size` bytes). The contents are not null-terminated. If you want null-termination (keep in mind the contents might not be ASCII and might contain null bytes before the end), just do `buf[nread] = 0;`. In that case, the value of `max` should be one less than the size of the buffer, to make sure the zero byte is not written past the end of `buf` if `max` bytes are read.