Rather than relying on the caller, terminate the string inside this
function. Do this each time we return, whether input is finished or
not. It is not needed when the input is aborted, since the string will
be discarded in that case.
Signed-off-by: Simon Glass <sjg@chromium.org>
if (ichar == '\n') {
putc('\n');
+ buf[cls->eol_num] = '\0'; /* terminate the string */
return 0;
}
break;
}
+ /*
+ * keep the string terminated...if we added a char at the end then we
+ * want a \0 after it
+ */
+ buf[cls->eol_num] = '\0';
+
return -EAGAIN;
}
break;
}
*len = cls->eol_num;
- buf[cls->eol_num] = '\0'; /* lose the newline */
if (buf[0] && buf[0] != CREAD_HIST_CHAR)
cread_add_to_hist(buf);