summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--conio.c15
-rw-r--r--conio.h20
3 files changed, 23 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index f1c9064..a683251 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
CC=gcc
-CFLAGS=-I. -pthread
+CFLAGS=-I. -pthread -fsanitize=address
DESTDIR=/usr/local/bin
generate:
- $(CC) -o snake snake.c vector.c $(CFLAGS)
+ $(CC) -o snake snake.c vector.c conio.c $(CFLAGS)
install:
cp snake $(DESTDIR)
diff --git a/conio.c b/conio.c
new file mode 100644
index 0000000..9b87cc9
--- /dev/null
+++ b/conio.c
@@ -0,0 +1,15 @@
+#include "./conio.h"
+#include <termios.h>
+#include <unistd.h>
+#include <stdio.h>
+int getch(void) {
+ struct termios oldattr, newattr;
+ int ch;
+ tcgetattr(STDIN_FILENO, &oldattr);
+ newattr = oldattr;
+ newattr.c_lflag &= ~(ICANON | ECHO);
+ tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
+ ch = getchar();
+ tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
+ return ch;
+}
diff --git a/conio.h b/conio.h
index fa866f2..520e146 100644
--- a/conio.h
+++ b/conio.h
@@ -1,14 +1,6 @@
-#include <termios.h>
-#include <unistd.h>
-#include <stdio.h>
-int getch(void) {
- struct termios oldattr, newattr;
- int ch;
- tcgetattr(STDIN_FILENO, &oldattr);
- newattr = oldattr;
- newattr.c_lflag &= ~(ICANON | ECHO);
- tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
- ch = getchar();
- tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
- return ch;
-}
+#ifndef CONIO_H
+#define CONIO_H
+
+int getch(void);
+
+#endif