summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2021-09-06 01:23:00 +0200
committerjonsykkel <jonrevold@gmail.com>2021-09-06 01:23:00 +0200
commite293ff571835f39084305ef2ce33c51a246d3cfe (patch)
tree253ea4912bed504096cf48135a2dc207cf3cf908
parent39cf16d157c1413adf751a9865d73d1d4cb8a36d (diff)
downloadokeffa-e293ff571835f39084305ef2ce33c51a246d3cfe.tar.gz
os
-rw-r--r--calc/os.c26
-rw-r--r--calc/os.h12
2 files changed, 38 insertions, 0 deletions
diff --git a/calc/os.c b/calc/os.c
new file mode 100644
index 0000000..cba2871
--- /dev/null
+++ b/calc/os.c
@@ -0,0 +1,26 @@
+#include "os.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#define SAD EXIT_FAILURE
+
+char read_char(void){
+ char c = fgetc(stdin);
+ if(c == EOF) c = 0;
+ return c;
+}
+
+void write_char(char c){
+ fputc(c,stdout);
+}
+
+void write_nl(void){
+ fputc('\n',stdout);
+}
+
+void eggog(char const *str){
+ fputs(str,stderr);
+ write_nl();
+ exit(SAD);
+}
+
diff --git a/calc/os.h b/calc/os.h
new file mode 100644
index 0000000..f780e06
--- /dev/null
+++ b/calc/os.h
@@ -0,0 +1,12 @@
+#ifndef OKEFFACALC_OS_H
+#define OKEFFACALC_OS_H
+
+#include <stdbool.h>
+
+char read_char (void);
+void write_char (char c);
+void write_nl (void);
+void eggog (char const *str);
+
+#endif
+