Various utililty functions.
More...
#include <libtransistor/types.h>
#include <libtransistor/fd.h>
#include "stb_sprintf.h"
Go to the source code of this file.
|
#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 |
|
|
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) |
|
Various utililty functions.
#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; \
}
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
-
host | Host to connect to |
port | Port to connect to |
fd | Output for FD |
void hexdump |
( |
const void * |
rawbuf, |
|
|
size_t |
size |
|
) |
| |
Hexdump a buffer.
- Parameters
-
rawbuf | The buffer you want to dump |
size | The 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
-
rawbuf | The buffer you want to dump |
size | The size of the buffer |
Hexdump is written over the basic debug logger.
Convert an int number to hex and prints it to stdout.
- Parameters
-
num | The int that you want converted |
int log_string |
( |
const char * |
string, |
|
|
size_t |
len |
|
) |
| |
Log a string to the debug log.
- Parameters
-
string | The string to log |
len | Length 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
-
nybble | The uint8 that you want converted |
uint64_t str2u64 |
( |
const char * |
str | ) |
|
Converts a string to a u64.
- Parameters
-
str | String to convert to u64 |
Turns a libtransistor result_t into a POSIX errno. The POSIX errno will be positive. You might want to negate it before returning!
- Parameters
-
r | The libtransistor result to transform |