fix bad inline usage

This commit is contained in:
Emile Clark-Boman 2025-09-11 17:37:01 +10:00
parent a04cc6a6e5
commit 1f26441c71
3 changed files with 15 additions and 10 deletions

View file

@ -75,7 +75,7 @@ fail:
* NOTE: login_tty() function. It exists as a learning resource. * NOTE: login_tty() function. It exists as a learning resource.
* REF: https://sourceware.org/git/glibc.git -> ./login/login_tty.c * REF: https://sourceware.org/git/glibc.git -> ./login/login_tty.c
*/ */
inline int setctty(const int fdty) { static inline int setctty(const int fdty) {
/* We assume any kernel compiling this defines TIOCSCTTY, /* We assume any kernel compiling this defines TIOCSCTTY,
* otherwise this implementation won't exactly work... */ * otherwise this implementation won't exactly work... */
return (ioctl(fdty, TIOCSCTTY, 0) != -1); return (ioctl(fdty, TIOCSCTTY, 0) != -1);
@ -90,7 +90,7 @@ inline int setctty(const int fdty) {
* WARNING: available at LICENSES/UC-LICENSE in this repo. * WARNING: available at LICENSES/UC-LICENSE in this repo.
* REF: https://sourceware.org/git/glibc.git -> ./login/login_tty.c * REF: https://sourceware.org/git/glibc.git -> ./login/login_tty.c
*/ */
inline void bindpty(const int fdty) { void bindpty(const int fdty) {
/* Adjust stdin/stdout/stderr to refer to fd*/ /* Adjust stdin/stdout/stderr to refer to fd*/
BIND(fdty, STDIN_FILENO); BIND(fdty, STDIN_FILENO);
BIND(fdty, STDOUT_FILENO); BIND(fdty, STDOUT_FILENO);

View file

@ -9,7 +9,7 @@
/* Set ncurses terminal mode (buffering, character processing, /* Set ncurses terminal mode (buffering, character processing,
* Key->SIG handling, and other termios(3) functionality). * Key->SIG handling, and other termios(3) functionality).
*/ */
inline int termmode(enum crs_termmode mode) { int termmode(const enum crs_termmode mode) {
switch (mode) { switch (mode) {
case TMODE_CBREAK: case TMODE_CBREAK:
return cbreak(); return cbreak();
@ -19,14 +19,16 @@ inline int termmode(enum crs_termmode mode) {
return nocbreak(); return nocbreak();
case TMODE_NORAW: case TMODE_NORAW:
return noraw(); return noraw();
default:
/* defaulting is not possible. */ /* defaulting is not possible. */
return 1;
} }
} }
/* Initialise ncurses for our usecase. /* Initialise ncurses for our usecase.
* WARNING: This function should only be called once. * WARNING: This function should only be called once.
*/ */
inline void init_ncurses(void) { void init_ncurses(void) {
// ncurses expects a locale for consistent behaviour // ncurses expects a locale for consistent behaviour
setlocale(LC_ALL, CRS_LOCALE); setlocale(LC_ALL, CRS_LOCALE);
@ -42,16 +44,17 @@ inline void init_ncurses(void) {
/* Apply a default IO configuration for an ncurses WINDOW. /* Apply a default IO configuration for an ncurses WINDOW.
*/ */
static inline void __conf_window(WINDOW *win) { static inline void __conf_window(WINDOW *const win) {
nodelay(win, TRUE); // getch(3x) nonblocking IO nodelay(win, TRUE); // getch(3x) nonblocking IO
keypad(win, TRUE); // allow function keys keypad(win, TRUE); // allow function keys
// intrflush(3x) - flush terminal input buffer on interrupt key // intrflush(3x) - flush terminal input buffer on interrupt key
intrflush(win, FALSE); intrflush(win, FALSE);
} }
/* Initialise (with default IO configuration) a new ncruses WINDOW. /* Initialise (with default IO configuration) a new ncurses WINDOW.
*/ */
WINDOW *new_window(int x, int y, int width, int height) { WINDOW *new_window(const int x, const int y, const int width,
const int height) {
WINDOW *win = newwin(height, width, y, x); WINDOW *win = newwin(height, width, y, x);
__conf_window(win); __conf_window(win);
@ -61,7 +64,7 @@ WINDOW *new_window(int x, int y, int width, int height) {
/* Initialise (with default IO configuration) the root ncurses WINDOW. /* Initialise (with default IO configuration) the root ncurses WINDOW.
* NOTE: This is typically done via initscr(3x) and called "stdscr". * NOTE: This is typically done via initscr(3x) and called "stdscr".
*/ */
inline WINDOW *root_window(void) { WINDOW *root_window(void) {
WINDOW *rootwin = new_window(0, 0, 0, 0); WINDOW *rootwin = new_window(0, 0, 0, 0);
__conf_window(rootwin); __conf_window(rootwin);
return rootwin; return rootwin;

View file

@ -15,9 +15,11 @@ enum crs_termmode {
TMODE_NORAW, TMODE_NORAW,
}; };
int termmode(enum crs_termmode mode); int termmode(const enum crs_termmode mode);
void init_ncurses(void); void init_ncurses(void);
WINDOW *init_window(int x, int y, int width, int height); WINDOW *init_window(const int x, const int y, const int width,
const int height);
WINDOW *root_window(void); WINDOW *root_window(void);
#endif /* DORNE_CURSE_H */ #endif /* DORNE_CURSE_H */