From 93e682644032cc18589bce35cab9e99ebf463e02 Mon Sep 17 00:00:00 2001 From: Extrems Date: Sun, 17 Nov 2024 15:38:04 -0500 Subject: [PATCH] Avoid unnecessary re-initialization --- libogc/console.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libogc/console.c b/libogc/console.c index d853bb8..7cb0cc9 100644 --- a/libogc/console.c +++ b/libogc/console.c @@ -661,9 +661,15 @@ static int __gecko_write_safe(void *c,const char *buf,int n) return usb_sendbuffer_safe(chan,buf,n); } +static int __gecko_close(void *c) +{ + *(s32*)c = -1; + return 0; +} + void CON_EnableGecko(s32 chan,bool safe) { - if(chan>=0 && !usb_isgeckoalive(chan)) return; + if(chan>=0 && (__gecko_chan==chan || !usb_isgeckoalive(chan))) return; fclose(stdcon); stdcon = NULL; @@ -671,7 +677,7 @@ void CON_EnableGecko(s32 chan,bool safe) if(chan<0) return; __gecko_chan = chan; - stdcon = fwopen(&__gecko_chan, safe ? __gecko_write_safe : __gecko_write); + stdcon = funopen(&__gecko_chan, NULL, safe ? __gecko_write_safe : __gecko_write, NULL, __gecko_close); if(!stdcon) return; setvbuf(stdcon, NULL, _IOLBF, 0);