From: Trent Huber Date: Tue, 9 Dec 2025 03:05:06 +0000 (-0500) Subject: Fix empty file creation bug X-Git-Url: https://trenthuber.com/code?a=commitdiff_plain;h=e296ed8004bc9fbf5695f4293f43d057df3739a2;p=thus.git Fix empty file creation bug --- diff --git a/src/input.c b/src/input.c index e6b363d..1505b76 100644 --- a/src/input.c +++ b/src/input.c @@ -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) { diff --git a/src/run.c b/src/run.c index b426607..9fd4e0c 100644 --- 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);