diff options
| author | Preston Pan <preston@nullring.xyz> | 2023-02-06 01:50:56 -0800 |
|---|---|---|
| committer | Preston Pan <preston@nullring.xyz> | 2023-02-06 01:50:56 -0800 |
| commit | fdedca4e02bfcafc1cac049c98c8fa202f8d4c24 (patch) | |
| tree | 862db92b3ae1ca2223357fee4c90e20a34576b1b | |
| parent | a9b12565583da2b2a5d5d42fbcaab3ee141d73c2 (diff) | |
more correct program structure
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | conio.c | 15 | ||||
| -rw-r--r-- | conio.h | 20 |
3 files changed, 23 insertions, 16 deletions
@@ -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) @@ -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; +} @@ -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 |
