BartC said:
I didn't notice anything about it, other than that it worked!
But then your are teaching (surely people will use this only when
leaning) including a .c file with function definitions. This is not
good style. If it were my class, I'd write a conio.h and provide a
"compile" command that silently includes the conio.o module (or a
makefile of whatever).
If you can't do that, I don't think its hard to tell people to "gcc -c
conio.c" once and to tack conio.o onto their compile commands.
I like to have people, when learning, turn up compiler warnings to
SCREAM AND SHOUT levels, and you can get annoying warnings for every
compile if you include a .c file that defines unused static functions
(or indeed anything else). You don't want warnings about code the
student hasn't written.
The static functions sort of make sense, if they will only be used in the
module that includes that file (and won't interfere with any other uses of
kbhit/getch in the project).
Looking at this line now:
memcpy(&new_kbd_mode, &g_old_kbd_mode, sizeof(struct termios));
I was thinking how much neater it would be if C allowed you to simply use an
assignment:
new_kbd_mode = old_kbd_mode;
then realised that it does! (Maybe the original author wasn't aware of it or
automatically used memcpy for any kind of block copy.)
Some things get stuck as idioms. Copying and zeroing OS control
structures using memcpy and memset seem to be one of these. You see it
all the time. It may date back to 1970's C when there was no struct
assignment, or it may be an overly cautious hang-over from OS calls that
have variable length structures.
The code is good, but would be properly useful with just a tiny bit of
tidying up and a README. People could then run old tutorial code on
free OSes unaltered.