]> Trent Huber's Code - thus.git/commitdiff
Fix empty file creation bug
authorTrent Huber <trentmhuber@gmail.com>
Tue, 9 Dec 2025 03:05:06 +0000 (22:05 -0500)
committerTrent Huber <trentmhuber@gmail.com>
Tue, 9 Dec 2025 03:05:06 +0000 (22:05 -0500)
src/input.c
src/run.c

index e6b363d1c20dfcc9698132b39fcd2c3978bac7d2..1505b7695dbeb8b2011b37d8c6fd3a2d14bcaab5 100644 (file)
@@ -114,6 +114,7 @@ static void newline(void) {
    if (OFFSET(cursor) > OFFSET(end)) putchar('\n');
    if (OFFSET(end)) putchar('\n');
    putchar('\r');
+   fflush(stdout);
 }
 
 void getcolumns(void) {
index b426607558a8dce8361ad92dc0af6d37c504f012..9fd4e0cc89015d7285f94cbf49538caadb003227 100644 (file)
--- a/src/run.c
+++ b/src/run.c
@@ -30,12 +30,13 @@ static int closepipe(struct command command) {
 }
 
 static void redirectfiles(struct redirect *r) {
-   int access, fd;
+   int access;
 
    for (; r->mode; ++r) {
        if (r->oldname) {
            switch (r->mode) {
            case READ:
+           default:
                access = O_RDONLY;
                break;
            case WRITE:
@@ -46,12 +47,9 @@ static void redirectfiles(struct redirect *r) {
                break;
            case APPEND:
                access = O_WRONLY | O_CREAT | O_APPEND;
-           default:
-               break;
            }
-           if ((fd = open(r->oldname, access, 0644)) == -1)
+           if ((r->oldfd = open(r->oldname, access, 0644)) == -1)
                fatal("Unable to open `%s'", r->oldname);
-           r->oldfd = fd;
        }
        if (dup2(r->oldfd, r->newfd) == -1)
            fatal("Unable to redirect file descriptor %d to %d", r->newfd, r->oldfd);