Skip to content

Commit

Permalink
Avoid unnecessary re-initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Nov 17, 2024
1 parent 3048460 commit 93e6826
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libogc/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,17 +661,23 @@ 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;

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);

Expand Down

0 comments on commit 93e6826

Please sign in to comment.