aboutsummaryrefslogtreecommitdiff
path: root/smash
diff options
context:
space:
mode:
Diffstat (limited to 'smash')
-rw-r--r--smash/main.c47
1 files changed, 2 insertions, 45 deletions
diff --git a/smash/main.c b/smash/main.c
index 645f4eb..e36744d 100644
--- a/smash/main.c
+++ b/smash/main.c
@@ -7,54 +7,11 @@
#include "../lib/sys/dup2.h"
#include "../lib/sys/exit.h"
#include "../lib/malloc/malloc.h"
+#include "../lib/sys/types.h"
#include "../lib/io/io.h"
#include "../lib/sys/errno.h"
-#define BUFSIZ 16384
-
-char buf[BUFSIZ] = {0};
-int io_getline(int fd, char *linebuf)
-{
- u64 size = 0;
- char *line = buf;
-
- while (*line && *line != '\n') line++;
-
- if (!*line) {
- u64 s = cstr_length(buf);
- s = read(fd, buf + s, BUFSIZ - s - 1);
-
- if (s == 0) {
- return -1;
- }
-
- buf[s] = 0;
- while (*line && *line != '\n') line++;
-
- if (!*line) {
- wf(STDERR_FD, "line too long to handle, exiting.\n");
- exit(-1);
- }
- }
-
- *line = 0;
- ++line;
-
- size = cstr_length(buf);
- for (int i = 0; buf[i]; ++i) linebuf[i] = buf[i];
- linebuf[size] = 0;
-
- buf[0] = 0;
- for (int i = 0; *line; ++i) {
- buf[i] = *line;
- buf[i + 1] = 0;
- ++line;
- }
-
- return size;
-}
-
int main(int argc, char *argv[])
{
char prompt[] = "$ ";
@@ -78,7 +35,7 @@ int main(int argc, char *argv[])
if (fd == STDIN_FD)
wstd(prompt);
- line_length = io_getline(fd, linebuf);
+ line_length = get_next_line_from_fd(fd, linebuf);
if (line_length == -1) {
break;