libgslutil
1.2.3
|
Functions | |
void | writem_str_cnotation (struct membuf_t *buf, const char *data, int size)) |
Serialise a string in C notation. More... | |
void | writem_str_hexdump (struct membuf_t *buf, const char *data, int size)) |
Perform a hex dump. More... | |
void | membuf_dump_to_file (struct membuf_t *buf, FILE *fp)) |
Dump contents of buffer to FILE*. More... | |
void | writes_str_hexnotation (char *buf, int sz, const char *str, int len)) |
Write string in hex notation. More... | |
FILE * | gsl_var_crash_open (const char *name, int report)) |
Open file for logging in /var/crash . More... | |
void | gsl_var_crash_dump (const char *name, const char *desc, const char *data, size_t len, int report)) |
Write simple crash log with hexdump in /var/crash. More... | |
This set of routines allows printing of strings in various formats for debugging purposes.
void writem_str_cnotation | ( | struct membuf_t * | buf, |
const char * | data, | ||
int | size | ||
) |
Serialise a string in C notation.
[out] | buf | Buffer to write string into. |
data | String to serialise. | |
size | If negative, maximum number of bytes to convert; otherwise, exact length of string. 0 to convert entire string regardless. |
Serialises a string in C notation (i.e. replacing ASCII 10 in data with \n
, etc.). Will escape whitespace chars (except space), double quotes and the backslash character. Other control codes and non-ASCII characters will be represented in hex (i.e. \xNN
). Result is appended to the buffer buf.
The size argument, if greater than zero, specifies the number of bytes in data to convert. It does not require data to be null terminated, and will in fact encode embedded nulls as \0
. If size is exactly zero, then data must be null terminated and the entire string will be serialised. If size is negative, then the string is assumed to be null terminated, and conversion will stop just before the first null, but the magnitude -size is the maximum number of bytes that will be converted.
void writem_str_hexdump | ( | struct membuf_t * | buf, |
const char * | data, | ||
int | size | ||
) |
Perform a hex dump.
[out] | buf | Buffer to write dex dump into. |
data | Pointer to bytes. | |
size | Number of bytes to dump. |
Performs a hex dump, storing the textual result in buf. This is the canonical 16-bytes-per-line dump. The result is appended to buf.
void membuf_dump_to_file | ( | struct membuf_t * | buf, |
FILE * | fp | ||
) |
Dump contents of buffer to FILE*.
buf | Buffer to dump. |
fp | FILE* to dump to. |
Writes the contents of buf to fp. The contents are not interpreted or encoded in any way; they are simply written with fwrite(3)
. The buffer buf is then emptied.
void writes_str_hexnotation | ( | char * | buf, |
int | sz, | ||
const char * | str, | ||
int | len | ||
) |
Write string in hex notation.
buf | Output buffer. |
sz | Size of output buffer. |
str | String to dump. |
len | Number of bytes to dump. |
Writes the string str (of len bytes) bytewise in hex notation into buf, which will be left null-terminated. The output may be truncated if sz is not large enough to contain the complete result (which will require len * 3 bytes).
FILE* gsl_var_crash_open | ( | const char * | name, |
int | report | ||
) |
Open file for logging in /var/crash .
name | Name of application (used for filename). |
report | If non-zero, reports the crash dump via LOG(). |
0 | on error (and see errno). |
This function securely opens a file in /var/crash for writing a crash dump into. It must be passed name which is used as a prefix for the file. It uses a random 2-hex-digit suffix which ensures this directory does not grow indefinitely as older crash dumps will be overwritten.
void gsl_var_crash_dump | ( | const char * | name, |
const char * | desc, | ||
const char * | data, | ||
size_t | len, | ||
int | report | ||
) |
Write simple crash log with hexdump in /var/crash.
name | Name of application (used for filename). |
desc | Description of fault. |
data | Pointer to arbitrary block of data to hexdump. |
len | Length of data. |
report | If non-zero, reports the crash dump via LOG(). |
This function can be used to easily write a bug or crash report with a short description and a hex dump of a block of data.
Wrapper around gsl_var_crash_open(), writem_str_hexdump() and membuf_dump_to_file().