]> Trent Huber's Code - thus.git/commitdiff
Bug fix for prompt()
authorTrent Huber <trentmhuber@gmail.com>
Mon, 15 Jun 2026 00:40:07 +0000 (20:40 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Mon, 15 Jun 2026 00:40:07 +0000 (20:40 -0400)
src/input.c

index 4b751a3853a2c06171f2e32385a92f689a949f52..7cf395ddf8307e06593ed70847ed24402e1b7b1d 100644 (file)
@@ -75,16 +75,18 @@ static void moveright(void) {
 }
 
 static void prompt(void) {
-   char *p, *oldstart, *oldcursor;
+   char *p, buffer[MAXCHARS + 1], *oldstart, *oldcursor;
 
-   if (!(p = getenv("PROMPT")))
-       fatal("Unable to access $PROMPT$ environment variable");
+   if (!(p = getenv("PROMPT")) && setenv("PROMPT", p = ">", 1) == -1)
+       fatal("Unable to update $PROMPT$ environment variable");
+   strcpy(buffer, p);
+   strcat(buffer, " ");
 
    oldstart = start;
    oldcursor = cursor;
 
    promptlen = 0;
-   cursor = start = p;
+   cursor = start = buffer;
    while (*cursor) moveright();
    promptlen = cursor - start;