ronantakizawa/codereview-bench huggingface dataset:
Repository: libsdl-org/SDL
File: src/video/haiku/SDL_bvideo.cc (C++)

Code before:
	if (!mouse) {
		return true;
	}

	if (cursor) {
		BCursor *hCursor = cursor->internal->cursor;
		be_app->SetCursor(hCursor);
	} else {
		BCursor *hCursor = new BCursor(B_CURSOR_ID_NO_CURSOR);
		be_app->SetCursor(hCursor);
		delete hCursor;
	}

	return true;
}

static bool HAIKU_SetRelativeMouseMode(bool enabled)
{
    SDL_Window *window = SDL_GetMouseFocus();
    if (!window) {
      return true;
    }

	SDL_BWin *bewin = _ToBeWin(window);
	BGLView *_SDL_GLView = bewin->GetGLView();
	if (!_SDL_GLView) {
		SDL_BView *_SDL_View = bewin->GetView();
		if (!_SDL_View)
			return false;

		bewin->Lock();
		if (enabled)
			_SDL_View->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
		else
			_SDL_View->SetEventMask(0, 0);
		bewin->Unlock();

		return true;
	}

	bewin->Lock();
	if (enabled)
		_SDL_GLView->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
	else
		_SDL_GLView->SetEventMask(0, 0);
	bewin->Unlock();

    return true;
}

static void HAIKU_MouseInit(SDL_VideoDevice *_this)

Review comment (suggestion):
Can you just do something like this?
```c++
    BView *_View = bewin->GetGLView();
    if (!_View) {
        _View = bewin->GetView();
    }
    ...
```

Code after:
	if (!mouse) {
		return true;
	}

	if (cursor) {
		BCursor *hCursor = cursor->internal->cursor;
		be_app->SetCursor(hCursor);
	} else {
		BCursor *hCursor = new BCursor(B_CURSOR_ID_NO_CURSOR);
		be_app->SetCursor(hCursor);
		delete hCursor;
	}

	return true;
}

static bool HAIKU_SetRelativeMouseMode(bool enabled)
{
    SDL_Window *window = SDL_GetMouseFocus();
    if (!window) {
      return true;
    }

	SDL_BWin *bewin = _ToBeWin(window);
	BView *_SDL_View = bewin->GetGLView();
	if (!_SDL_View) {
		_SDL_View = bewin->GetView();
		if (!_SDL_View)
			return false;
	}

	bewin->Lock();
	if (enabled)
		_SDL_View->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
	else
		_SDL_View->SetEventMask(0, 0);
	bewin->Unlock();

    return true;
}

static void HAIKU_MouseInit(SDL_VideoDevice *_this)
{
	SDL_Mouse *mouse = SDL_GetMouse();
	if (!mouse) {
		return;
	}
	mouse->CreateCursor = HAIKU_CreateCursor;
	mouse->CreateSystemCursor = HAIKU_CreateSystemCursor;
	mouse->ShowCursor = HAIKU_ShowCursor;
	mouse->FreeCursor = HAIKU_FreeCursor;
Repository: libsdl-org/SDL
File: src/dialog/windows/SDL_windowsdialog.c (C)

Code before:

    if (pFileDialog) {
        pFileDialog->lpVtbl->Release(pFileDialog);
    }

    if (pItem) {
        pItem->lpVtbl->Release(pItem);
    }

    if (pFolderItem) {
        pFolderItem->lpVtbl->Release(pFolderItem);
    }

    if (pItemArray) {
        pItemArray->lpVtbl->Release(pItemArray);
    }

    if (filePath) {
        CoTaskMemFree(filePath);
    }

    // If both default_file_w and default_folder_w are non-NULL, then
    // default_file_w is a pointer into default_folder_w.
    if (default_folder_w) {
        SDL_free(default_folder_w);
    } else SDL_free(default_file_w);

    SDL_free(title_w);

    SDL_free(accept_w);

    SDL_free(cancel_w);

    SDL_free(filter_data);

    if (files) {
        for (char** files_ptr = files; *files_ptr; files_ptr++) {
            SDL_free(*files_ptr);
        }
        SDL_free(files);
    }

    return success;
}

// TODO: The new version of file dialogs
void windows_ShowFileDialog(void *ptr)
{

    winArgs *args = (winArgs *) ptr;
    bool is_save = args->is_save;

Review comment (suggestion):
```suggestion
    } else {
        SDL_free(default_file_w);
    }
```

Code after:

    if (pFileDialog) {
        pFileDialog->lpVtbl->Release(pFileDialog);
    }

    if (pItem) {
        pItem->lpVtbl->Release(pItem);
    }

    if (pFolderItem) {
        pFolderItem->lpVtbl->Release(pFolderItem);
    }

    if (pItemArray) {
        pItemArray->lpVtbl->Release(pItemArray);
    }

    if (filePath) {
        CoTaskMemFree(filePath);
    }

    // If both default_file_w and default_folder_w are non-NULL, then
    // default_file_w is a pointer into default_folder_w.
    if (default_folder_w) {
        SDL_free(default_folder_w);
    } else {
        SDL_free(default_file_w);
    }

    SDL_free(title_w);

    SDL_free(accept_w);

    SDL_free(cancel_w);

    SDL_free(filter_data);

    if (files) {
        for (char** files_ptr = files; *files_ptr; files_ptr++) {
            SDL_free(*files_ptr);
        }
        SDL_free(files);
    }

    return success;
}

// TODO: The new version of file dialogs
void windows_ShowFileDialog(void *ptr)
{
Repository: libsdl-org/SDL
File: src/test/SDL_test_common.c (C)

Code before:

/* Ported from original test/common.c file. */
#include <SDL3/SDL_test.h>

#define SDL_MAIN_NOIMPL
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL_main.h>

static const char *common_usage[] = {
    "[-h | --help]",
    "[--trackmem]",
    "[--randmem]",
    "[--info all|video|modes|render|event|event_motion]",
    "[--log all|error|system|audio|video|render|input]",
    NULL
};

static const char *video_usage[] = {
    "[--always-on-top]",
    "[--aspect min-max]",
    "[--auto-scale-content]",
    "[--center | --position X,Y]",
    "[--confine-cursor X,Y,W,H]",
    "[--depth N]",
    "[--display N]",
    "[--exit-after-ms N]",
    "[--flash-on-focus-loss]",
    "[--fullscreen | --fullscreen-desktop | --windows N]",
    "[--geometry WxH]",
    "[--gldebug]",
    "[--grab]",
    "[--hidden]",
    "[--hide-cursor]",
    "[--high-pixel-density]",
    "[--icon icon.bmp]",
    "[--input-focus]",
    "[--keyboard-grab]",
    "[--logical-presentation disabled|match|stretch|letterbox|overscan|integer_scale]",
    "[--logical WxH]",
    "[--max-geometry WxH]",
    "[--maximize]",
    "[--metal-window | --opengl-window | --vulkan-window]",
    "[--min-geometry WxH]",
    "[--minimize]",
    "[--mouse-focus]",
    "[--noframe]",
    "[--refresh R]",
    "[--renderer driver]",
    "[--resizable]",
    "[--scale N]",
    "[--title title]",

Review comment (suggestion):
```suggestion
    "[--quit-after-ms N]",
```
Minor suggestion, since we're sending `SDL_EVENT_QUIT`

Code after:

/* Ported from original test/common.c file. */
#include <SDL3/SDL_test.h>

#define SDL_MAIN_NOIMPL
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL_main.h>

static const char *common_usage[] = {
    "[-h | --help]",
    "[--trackmem]",
    "[--randmem]",
    "[--info all|video|modes|render|event|event_motion]",
    "[--log all|error|system|audio|video|render|input]",
    NULL
};

static const char *video_usage[] = {
    "[--always-on-top]",
    "[--aspect min-max]",
    "[--auto-scale-content]",
    "[--center | --position X,Y]",
    "[--confine-cursor X,Y,W,H]",
    "[--depth N]",
    "[--display N]",
    "[--flash-on-focus-loss]",
    "[--fullscreen | --fullscreen-desktop | --windows N]",
    "[--geometry WxH]",
    "[--gldebug]",
    "[--grab]",
    "[--hidden]",
    "[--hide-cursor]",
    "[--high-pixel-density]",
    "[--icon icon.bmp]",
    "[--input-focus]",
    "[--keyboard-grab]",
    "[--logical-presentation disabled|match|stretch|letterbox|overscan|integer_scale]",
    "[--logical WxH]",
    "[--max-geometry WxH]",
    "[--maximize]",
    "[--metal-window | --opengl-window | --vulkan-window]",
    "[--min-geometry WxH]",
    "[--minimize]",
    "[--mouse-focus]",
    "[--noframe]",
    "[--quit-after-ms N]",
    "[--refresh R]",
    "[--renderer driver]",
    "[--resizable]",
    "[--scale N]",
    "[--title title]",
Repository: libsdl-org/SDL
File: src/core/freebsd/SDL_evdev_kbd_freebsd.c (C)

Code before:

    kbd->accents = SDL_calloc(1, sizeof(accentmap_t));
    kbd->key_map = SDL_calloc(1, sizeof(keymap_t));
    kbd->kbInfo = SDL_calloc(1, sizeof(keyboard_info_t));

    ioctl(kbd->console_fd, KDGKBINFO, kbd->kbInfo);

    if (ioctl(kbd->console_fd, KDGKBSTATE, &flag_state) == 0) {
        kbd->ledflagstate = flag_state;
    }

    if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) {
        SDL_free(kbd->accents);
        kbd->accents = &accentmap_default_us_acc;
    }

    if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
        // Set the keyboard in XLATE mode and load the keymaps
        ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE));
        if (!SDL_EVDEV_kbd_load_keymaps(kbd)) {
            SDL_free(kbd->key_map);
            kbd->key_map = &keymap_default_us_acc;
        }

        if (!kbd_vt_init(kbd->console_fd))
            SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, "kbd_vt_init failed");

        kbd->keyboard_fd = kbd->console_fd;

        if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) {
            kbd_register_emerg_cleanup(kbd);
        }
    }

    vt_update_mouse(kbd, MOUSE_HIDE);

    return kbd;
}

void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{
    if (!kbd) {
        return;
    }

    kbd_vt_quit(kbd->console_fd);

    vt_update_mouse(kbd, MOUSE_SHOW);

    kbd_unregister_emerg_cleanup();


Review comment (bug):
```suggestion
        if (!kbd_vt_init(kbd->console_fd)) {
            SDL_LogInfo(SDL_LOG_CATEGORY_INPUT, "kbd_vt_init failed");
        }
```

Code after:

    kbd->shift_state = 0;

    kbd->accents = SDL_calloc(1, sizeof(accentmap_t));
    kbd->key_map = SDL_calloc(1, sizeof(keymap_t));
    kbd->kbInfo = SDL_calloc(1, sizeof(keyboard_info_t));

    ioctl(kbd->console_fd, KDGKBINFO, kbd->kbInfo);

    if (ioctl(kbd->console_fd, KDGKBSTATE, &flag_state) == 0) {
        kbd->ledflagstate = flag_state;
    }

    if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) {
        SDL_free(kbd->accents);
        kbd->accents = &accentmap_default_us_acc;
    }

    if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
        // Set the keyboard in XLATE mode and load the keymaps
        ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE));
        if (!SDL_EVDEV_kbd_load_keymaps(kbd)) {
            SDL_free(kbd->key_map);
            kbd->key_map = &keymap_default_us_acc;
        }

        if (!kbd_vt_init(kbd->console_fd)) {
            SDL_LogInfo(SDL_LOG_CATEGORY_INPUT, "kbd_vt_init failed");
        }

        kbd->keyboard_fd = kbd->console_fd;

        if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) {
            kbd_register_emerg_cleanup(kbd);
        }
    }

    vt_update_mouse(kbd, MOUSE_HIDE);

    return kbd;
}

void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{
    if (!kbd) {
        return;
    }

    kbd_vt_quit(kbd->console_fd);

    vt_update_mouse(kbd, MOUSE_SHOW);
Repository: libsdl-org/SDL
File: src/core/freebsd/SDL_evdev_kbd_freebsd.c (C)

Code before:
static void kbd_vt_quit(int console_fd)
{
    struct vt_mode mode;

    if (vt_release_signal) {
        sigaction(vt_release_signal, &old_sigaction[vt_release_signal], NULL);
        vt_release_signal = 0;
    }
    if (vt_acquire_signal) {
        sigaction(vt_acquire_signal, &old_sigaction[vt_acquire_signal], NULL);
        vt_acquire_signal = 0;
    }

    SDL_zero(mode);
    mode.mode = VT_AUTO;
    ioctl(console_fd, VT_SETMODE, &mode);
}

static bool kbd_vt_init(int console_fd)
{
    struct vt_mode mode;

    if (setup_vt_signal(SIGUSR1, kbd_vt_release_signal_action))
        vt_release_signal = SIGUSR1;
    if (setup_vt_signal(SIGUSR2, kbd_vt_acquire_signal_action))
        vt_acquire_signal = SIGUSR2;
    if (!vt_release_signal || !vt_acquire_signal ) {
        kbd_vt_quit(console_fd);
        return false;
    }

    SDL_zero(mode);
    mode.mode = VT_PROCESS;
    mode.relsig = vt_release_signal;
    mode.acqsig = vt_acquire_signal;
    mode.frsig = SIGIO;
    if (ioctl(console_fd, VT_SETMODE, &mode) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Failed VT_SETMODE ioctl: %s", strerror(errno));
        kbd_vt_quit(console_fd);
        return false;
    }
    return true;
}

SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
{
    SDL_EVDEV_keyboard_state *kbd;
    char flag_state;

    kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
    if (!kbd) {

Review comment (suggestion):
```suggestion
    if (setup_vt_signal(SIGUSR1, kbd_vt_release_signal_action)) {
        vt_release_signal = SIGUSR1;
    }
    if (setup_vt_signal(SIGUSR2, kbd_vt_acquire_signal_action)) {
        vt_acquire_signal = SIGUSR2;
    }
```

Code after:
static void kbd_vt_quit(int console_fd)
{
    struct vt_mode mode;

    if (vt_release_signal) {
        sigaction(vt_release_signal, &old_sigaction[vt_release_signal], NULL);
        vt_release_signal = 0;
    }
    if (vt_acquire_signal) {
        sigaction(vt_acquire_signal, &old_sigaction[vt_acquire_signal], NULL);
        vt_acquire_signal = 0;
    }

    SDL_zero(mode);
    mode.mode = VT_AUTO;
    ioctl(console_fd, VT_SETMODE, &mode);
}

static bool kbd_vt_init(int console_fd)
{
    struct vt_mode mode;

    if (setup_vt_signal(SIGUSR1, kbd_vt_release_signal_action)) {
        vt_release_signal = SIGUSR1;
    }
    if (setup_vt_signal(SIGUSR2, kbd_vt_acquire_signal_action)) {
        vt_acquire_signal = SIGUSR2;
    }
    if (!vt_release_signal || !vt_acquire_signal ) {
        kbd_vt_quit(console_fd);
        return false;
    }

    SDL_zero(mode);
    mode.mode = VT_PROCESS;
    mode.relsig = vt_release_signal;
    mode.acqsig = vt_acquire_signal;
    mode.frsig = SIGIO;
    if (ioctl(console_fd, VT_SETMODE, &mode) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed VT_SETMODE ioctl: %s", strerror(errno));
        kbd_vt_quit(console_fd);
        return false;
    }
    return true;
}

SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
{
    SDL_EVDEV_keyboard_state *kbd;
    char flag_state;
Repository: libsdl-org/SDL
File: src/core/freebsd/SDL_evdev_kbd_freebsd.c (C)

Code before:

    SDL_zero(mode);
    mode.mode = VT_AUTO;
    ioctl(console_fd, VT_SETMODE, &mode);
}

static bool kbd_vt_init(int console_fd)
{
    struct vt_mode mode;

    if (setup_vt_signal(SIGUSR1, kbd_vt_release_signal_action))
        vt_release_signal = SIGUSR1;
    if (setup_vt_signal(SIGUSR2, kbd_vt_acquire_signal_action))
        vt_acquire_signal = SIGUSR2;
    if (!vt_release_signal || !vt_acquire_signal ) {
        kbd_vt_quit(console_fd);
        return false;
    }

    SDL_zero(mode);
    mode.mode = VT_PROCESS;
    mode.relsig = vt_release_signal;
    mode.acqsig = vt_acquire_signal;
    mode.frsig = SIGIO;
    if (ioctl(console_fd, VT_SETMODE, &mode) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Failed VT_SETMODE ioctl: %s", strerror(errno));
        kbd_vt_quit(console_fd);
        return false;
    }
    return true;
}

SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
{
    SDL_EVDEV_keyboard_state *kbd;
    char flag_state;

    kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
    if (!kbd) {
        return NULL;
    }

    kbd->npadch = -1;

    // This might fail if we're not connected to a tty (e.g. on the Steam Link)
    kbd->keyboard_fd = kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC);

    kbd->shift_state = 0;

    kbd->accents = SDL_calloc(1, sizeof(accentmap_t));
    kbd->key_map = SDL_calloc(1, sizeof(keymap_t));

Review comment (bug):
```suggestion
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed VT_SETMODE ioctl: %s", strerror(errno));
```

Code after:

    SDL_zero(mode);
    mode.mode = VT_AUTO;
    ioctl(console_fd, VT_SETMODE, &mode);
}

static bool kbd_vt_init(int console_fd)
{
    struct vt_mode mode;

    if (setup_vt_signal(SIGUSR1, kbd_vt_release_signal_action)) {
        vt_release_signal = SIGUSR1;
    }
    if (setup_vt_signal(SIGUSR2, kbd_vt_acquire_signal_action)) {
        vt_acquire_signal = SIGUSR2;
    }
    if (!vt_release_signal || !vt_acquire_signal ) {
        kbd_vt_quit(console_fd);
        return false;
    }

    SDL_zero(mode);
    mode.mode = VT_PROCESS;
    mode.relsig = vt_release_signal;
    mode.acqsig = vt_acquire_signal;
    mode.frsig = SIGIO;
    if (ioctl(console_fd, VT_SETMODE, &mode) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed VT_SETMODE ioctl: %s", strerror(errno));
        kbd_vt_quit(console_fd);
        return false;
    }
    return true;
}

SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
{
    SDL_EVDEV_keyboard_state *kbd;
    char flag_state;

    kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
    if (!kbd) {
        return NULL;
    }

    kbd->npadch = -1;

    // This might fail if we're not connected to a tty (e.g. on the Steam Link)
    kbd->keyboard_fd = kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC);

    kbd->shift_state = 0;
Repository: libsdl-org/SDL
File: src/core/freebsd/SDL_evdev_kbd_freebsd.c (C)

Code before:
        if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) {
            // Give back keyboard.
            ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
        }
        kbd->console_fd = kbd->keyboard_fd = -1;
    }

    SDL_free(kbd);
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted)
{
    struct termios tios;

    SDL_zero(tios);

    if (!state) {
        return;
    }

    if (muted == state->muted) {
        return;
    }

    if(tcgetattr(state->console_fd, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not get terminal mode: %s", strerror(errno));
        return;
    }

    if (muted) {
        if(SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, true)) {
            ioctl(state->console_fd, KDSKBMODE, K_OFF);
            cfmakeraw(&tios);

            if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) {
                kbd_register_emerg_cleanup(state);
            }
        }
    } else {
        kbd_unregister_emerg_cleanup();

        cfmakesane(&tios);
        ioctl(state->console_fd, KDSKBMODE, state->old_kbd_mode);
    }

    if(tcsetattr(state->console_fd, TCSAFLUSH, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set terminal mode to %s: %s", muted ? "raw" : "sane", strerror(errno));
        return;
    }

    state->muted = muted;

Review comment (suggestion):
```suggestion
    if (tcgetattr(state->console_fd, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Could not get terminal mode: %s", strerror(errno));
```

Code after:
        ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);

        close(kbd->keyboard_fd);
        if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) {
            // Give back keyboard.
            ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
        }
        kbd->console_fd = kbd->keyboard_fd = -1;
    }

    SDL_free(kbd);
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted)
{
    struct termios tios;

    SDL_zero(tios);

    if (!state) {
        return;
    }

    if (muted == state->muted) {
        return;
    }

    if (tcgetattr(state->console_fd, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Could not get terminal mode: %s", strerror(errno));
        return;
    }

    if (muted) {
        if (SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, true)) {
            ioctl(state->console_fd, KDSKBMODE, K_OFF);
            cfmakeraw(&tios);

            if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) {
                kbd_register_emerg_cleanup(state);
            }
        }
    } else {
        kbd_unregister_emerg_cleanup();

        cfmakesane(&tios);
        ioctl(state->console_fd, KDSKBMODE, state->old_kbd_mode);
    }

    if (tcsetattr(state->console_fd, TCSAFLUSH, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Could not set terminal mode to %s: %s", muted ? "raw" : "sane", strerror(errno));
        return;
Repository: libsdl-org/SDL
File: src/core/freebsd/SDL_evdev_kbd_freebsd.c (C)

Code before:
    }

    SDL_free(kbd);
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted)
{
    struct termios tios;

    SDL_zero(tios);

    if (!state) {
        return;
    }

    if (muted == state->muted) {
        return;
    }

    if(tcgetattr(state->console_fd, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not get terminal mode: %s", strerror(errno));
        return;
    }

    if (muted) {
        if(SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, true)) {
            ioctl(state->console_fd, KDSKBMODE, K_OFF);
            cfmakeraw(&tios);

            if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) {
                kbd_register_emerg_cleanup(state);
            }
        }
    } else {
        kbd_unregister_emerg_cleanup();

        cfmakesane(&tios);
        ioctl(state->console_fd, KDSKBMODE, state->old_kbd_mode);
    }

    if(tcsetattr(state->console_fd, TCSAFLUSH, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set terminal mode to %s: %s", muted ? "raw" : "sane", strerror(errno));
        return;
    }

    state->muted = muted;
}

void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void *), void *release_callback_data, void (*acquire_callback)(void *), void *acquire_callback_data)
{
    if (state == NULL) {

Review comment (suggestion):
```suggestion
        if (SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, true)) {
```

Code after:
            ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
        }
        kbd->console_fd = kbd->keyboard_fd = -1;
    }

    SDL_free(kbd);
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, bool muted)
{
    struct termios tios;

    SDL_zero(tios);

    if (!state) {
        return;
    }

    if (muted == state->muted) {
        return;
    }

    if (tcgetattr(state->console_fd, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Could not get terminal mode: %s", strerror(errno));
        return;
    }

    if (muted) {
        if (SDL_GetHintBoolean(SDL_HINT_MUTE_CONSOLE_KEYBOARD, true)) {
            ioctl(state->console_fd, KDSKBMODE, K_OFF);
            cfmakeraw(&tios);

            if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) {
                kbd_register_emerg_cleanup(state);
            }
        }
    } else {
        kbd_unregister_emerg_cleanup();

        cfmakesane(&tios);
        ioctl(state->console_fd, KDSKBMODE, state->old_kbd_mode);
    }

    if (tcsetattr(state->console_fd, TCSAFLUSH, &tios) == -1) {
        SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Could not set terminal mode to %s: %s", muted ? "raw" : "sane", strerror(errno));
        return;
    }

    state->muted = muted;
}