lib: membuff: fix readline not returning line in case of overflow
If line overflows readline it will not be returned, fix this behavior, make it optional and documented properly. Signed-off-by: Ion Agorria <ion@agorria.com> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Reviewed-by: Simon Glass <sjg@chromium.org> Link: https://lore.kernel.org/r/20240105072212.6615-6-clamor95@gmail.com Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
This commit is contained in:
committed by
Mattijs Korpershoek
parent
90087dd076
commit
e58bafc35f
@@ -287,7 +287,7 @@ int membuff_free(struct membuff *mb)
|
||||
(mb->end - mb->start) - 1 - membuff_avail(mb);
|
||||
}
|
||||
|
||||
int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch)
|
||||
int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit)
|
||||
{
|
||||
int len; /* number of bytes read (!= string length) */
|
||||
char *s, *end;
|
||||
@@ -309,7 +309,7 @@ int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch)
|
||||
}
|
||||
|
||||
/* couldn't get the whole string */
|
||||
if (!ok) {
|
||||
if (!ok && must_fit) {
|
||||
if (maxlen)
|
||||
*orig = '\0';
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user