shithub: util

Download patch

ref: bfa694f3ddb1c7784f82e9017814d10b73ee4ce8
parent: 5b790b347f51baee12eeb2dfced7ef5cc0065a7e
author: eli <eli@singularity>
date: Fri Sep 5 12:39:08 EDT 2025

read_stdin

--- a/llama2.c
+++ b/llama2.c
@@ -1151,13 +1151,13 @@
 }
 
 void read_stdin(const char* guide, char* buffer, long bufsize) {
+	int r;
     // read a line from stdin, up to but not including \n
     print("%s", guide);
-    if (read(0, buffer, bufsize) > 0) {
-        long len = strlen(buffer);
-        if (len > 0 && buffer[len - 1] == '\n') {
-            buffer[len - 1] = '\0'; // strip newline
-        }
+	buffer[0] = '\0';
+    if ((r = read(0, buffer, bufsize)) > 0) {
+		buffer[r] = '\0';
+       	buffer[strcspn(buffer, "\r\n")] = '\0'; // strip newline
     }
 }
 
--