From 869d88068bcd87fcb00306ba9f635a0936e1388f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 13 Nov 2017 11:46:51 +0000 Subject: [PATCH] utils: add "line" Not a very useful command in the normal run of the mill but it's part of the base command list expected so provide it anyway. --- Applications/util/Makefile.z80 | 1 + Applications/util/line.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Applications/util/line.c diff --git a/Applications/util/Makefile.z80 b/Applications/util/Makefile.z80 index bb2c5518..2aa264fc 100644 --- a/Applications/util/Makefile.z80 +++ b/Applications/util/Makefile.z80 @@ -26,6 +26,7 @@ SRCSNS = \ head.c \ init.c \ kill.c \ + line.c \ ln.c \ logname.c \ mkdir.c \ diff --git a/Applications/util/line.c b/Applications/util/line.c new file mode 100644 index 00000000..7d3f3def --- /dev/null +++ b/Applications/util/line.c @@ -0,0 +1,25 @@ +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + char buf[512]; + char *e; + int l; + while((l = read(0, buf, 512)) > 0) { + e = memchr(buf, '\n', l); + if (e) { + l = e + 1 - buf; + write(1, buf, l); + return 0; + } + write(1, buf, l); + } + /* No newline was found */ + write(1, "\n", l); + return 1; +} + + \ No newline at end of file -- 2.34.1