From 0582f9189efed23dce3c3f3f55adb35829d127df Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Wed, 6 May 2020 10:37:20 +0200 Subject: [PATCH] Moved tutils --- Makefile | 3 ++- src/ped.c | 12 ------------ src/utils.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 src/utils.c diff --git a/Makefile b/Makefile index 7898662..abff219 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ EXE=bin/ped all: install $(CC) src/tty.c -o tty.o -c - $(CC) $(FLAGS) -o $(EXE) src/ped.c tty.o + $(CC) src/utils.c -o utils.o -c + $(CC) $(FLAGS) -o $(EXE) src/ped.c tty.o utils.o test: clean all ./bin/ped test diff --git a/src/ped.c b/src/ped.c index a3fe878..9137c84 100644 --- a/src/ped.c +++ b/src/ped.c @@ -40,18 +40,6 @@ int main(int argc, char** args) return EXIT_SUCCESS; } -void output(char* string, unsigned int length) -{ - write(0, string, length); -} - -char getChar() -{ - char character; - int b = read(0, &character, 1); - return character; -} - void redraw(struct Session* session) { /* Move cursor back home */ diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..a3dfed8 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,30 @@ +#include +#include + +/** +* Writes a null-terminated string to the tty +*/ +void writeStr(char* ntString) +{ + write(0, ntString, strlen(ntString)); +} + +/** +* Writes bytes from buffer `string` of length +* `length` to the tty +*/ +void output(char* string, unsigned int length) +{ + write(0, string, length); +} + +/** +* Reads and returns the single byte +* read from the tty. +*/ +char getChar() +{ + char character; + int b = read(0, &character, 1); + return character; +}