libnx/nx/source/runtime/devices/console_debug.c
fincs 4c9b2ac048
Separate debug console code from normal console code, see details:
- consoleDebugInit now lives in a separate source code file
- The devoptab for debugDevice_CONSOLE is now loaded weakly, so that
  normal console code isn't linked in by explicit means
- consoleInit no longer sets up stderr. If stderr to console is desired,
  explicitly use consoleDebugInit(debugDevice_CONSOLE)
- This change makes it possible to use debugDevice_SVC without linking
  in the entire console runtime, which in turn also enabled default
  native window handling (and this can be undesirable)
2020-04-17 16:46:40 +02:00

49 lines
1.2 KiB
C

#include <stdio.h>
#include <string.h>
#include <sys/iosupport.h>
#include "runtime/devices/console.h"
#include "kernel/svc.h"
//---------------------------------------------------------------------------------
static ssize_t debug_write(struct _reent *r, void *fd, const char *ptr, size_t len) {
//---------------------------------------------------------------------------------
svcOutputDebugString(ptr,len);
return len;
}
static const devoptab_t dotab_svc = {
.name = "svc",
.write_r = debug_write,
};
static const devoptab_t dotab_null = {
.name = "null",
};
__attribute__((weak)) const devoptab_t* __nx_get_console_dotab(void) {
return &dotab_null;
}
//---------------------------------------------------------------------------------
void consoleDebugInit(debugDevice device) {
//---------------------------------------------------------------------------------
int buffertype = _IONBF;
switch(device) {
case debugDevice_SVC:
devoptab_list[STD_ERR] = &dotab_svc;
buffertype = _IOLBF;
break;
case debugDevice_CONSOLE:
devoptab_list[STD_ERR] = __nx_get_console_dotab();
break;
case debugDevice_NULL:
devoptab_list[STD_ERR] = &dotab_null;
break;
}
setvbuf(stderr, NULL, buffertype, 0);
}