libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
util.h File Reference

Various utililty functions. More...

#include <libtransistor/types.h>
#include <libtransistor/fd.h>
#include "stb_sprintf.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ARRAY_LENGTH(x)   (sizeof(x) / sizeof((x)[0]))
 
#define SECONDS_TO_NANOSECONDS(seconds)   ((seconds)*(1000000000))
 
#define ASSERT_OK(label, expr)
 
#define LIB_ASSERT_OK(label, expr)   if((r = expr) != RESULT_OK) { goto label; }
 
#define TRACE   printf("tracing at %s:%d\n", __FILE__, __LINE__);
 
#define DBG_TRACE   dbg_printf("tracing at %s:%d", __FILE__, __LINE__);
 
#define STB_SPRINTF_DECORATE(name)   dbg_##name
 

Functions

uint64_t str2u64 (const char *str)
 Converts a string to a u64. More...
 
char nybble2hex (uint8_t nybble)
 Convert a uint8 nybble to a hex char. More...
 
void hexdump (const void *rawbuf, size_t size)
 Hexdump a buffer. More...
 
void hexdump_dbg (const void *rawbuf, size_t size)
 Hexdump a buffer using the debug logger. More...
 
void hexnum (int num)
 Convert an int number to hex and prints it to stdout. More...
 
int log_string (const char *string, size_t len)
 Log a string to the debug log. More...
 
result_t dbg_connect (const char *host, const char *port, int *fd)
 Connect the debug log over a socket. More...
 
void dbg_disconnect ()
 Disconnect the debug log from the socket.
 
int trn_result_to_errno (result_t r)
 Turns a libtransistor result_t into a POSIX errno. The POSIX errno will be positive. You might want to negate it before returning! More...
 
int dbg_printf (char const *fmt,...)
 
int dbg_vprintf (char const *fmt, va_list va)
 
void dbg_set_file (trn_file_t *file)
 

Detailed Description

Various utililty functions.

Macro Definition Documentation

#define ASSERT_OK (   label,
  expr 
)
Value:
if((r = expr) != RESULT_OK) { \
printf("assertion failed at %s:%d: result 0x%x is not OK\n", __FILE__, __LINE__, r); \
goto label; \
}

Function Documentation

result_t dbg_connect ( const char *  host,
const char *  port,
int *  fd 
)

Connect the debug log over a socket.

Required socket services to be already initialized.

Parameters
hostHost to connect to
portPort to connect to
fdOutput for FD
void hexdump ( const void *  rawbuf,
size_t  size 
)

Hexdump a buffer.

Parameters
rawbufThe buffer you want to dump
sizeThe size of the buffer

Hexdump is written to standard output.

void hexdump_dbg ( const void *  rawbuf,
size_t  size 
)

Hexdump a buffer using the debug logger.

Parameters
rawbufThe buffer you want to dump
sizeThe size of the buffer

Hexdump is written over the basic debug logger.

void hexnum ( int  num)

Convert an int number to hex and prints it to stdout.

Parameters
numThe int that you want converted
int log_string ( const char *  string,
size_t  len 
)

Log a string to the debug log.

Parameters
stringThe string to log
lenLength of the string

The debug log does not depend on newlib or malloc, and is therefore safe to use in environments such as the memory allocation code or threads that do not have context properly set up.

char nybble2hex ( uint8_t  nybble)

Convert a uint8 nybble to a hex char.

Parameters
nybbleThe uint8 that you want converted
uint64_t str2u64 ( const char *  str)

Converts a string to a u64.

Parameters
strString to convert to u64
int trn_result_to_errno ( result_t  r)

Turns a libtransistor result_t into a POSIX errno. The POSIX errno will be positive. You might want to negate it before returning!

Parameters
rThe libtransistor result to transform