|
Timing attack against DES 0.1
|
Some utility functions and macros. More...
#include <stdio.h>#include <stdlib.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | ERROR(retval, exitval, s, ...) { myError(__FILE__, __LINE__, __func__, s, ##__VA_ARGS__); exit (exitval); } |
| Print an error message and exit with -1 status. | |
| #define | WARNING(...) warning(__FILE__, __LINE__, __func__, __VA_ARGS__) |
| Print a warning message. | |
| #define | XMALLOC(n) xmalloc(__FILE__, __LINE__, __func__, (n)) |
| Wrapper around the regular malloc memory allocator. | |
| #define | XCALLOC(n, s) xcalloc(__FILE__, __LINE__, __func__, (n), (s)) |
| Wrapper around the regular calloc memory allocator. | |
| #define | XREALLOC(p, s) xrealloc(__FILE__, __LINE__, __func__, (p), (s)) |
| Wrapper around the regular realloc memory allocator. | |
| #define | XFOPEN(f, m) xfopen(__FILE__, __LINE__, __func__, (f), (m)) |
| Wrapper around the regular fopen. | |
Functions | |
| void | myError (const char *file, const int line, const char *fnct, const char *frm,...) |
| Prints an error message and exit with -1 status. | |
| void | warning (const char *file, const int line, const char *fnct, const char *frm,...) |
| Prints a warning message. | |
| void * | xmalloc (const char *file, const int line, const char *fnct, const size_t size) |
| Wrapper around the regular malloc memory allocator. | |
| void * | xcalloc (const char *file, const int line, const char *fnct, const size_t nmemb, const size_t size) |
| Wrapper around the regular calloc memory allocator. | |
| void * | xrealloc (const char *file, const int line, const char *fnct, void *ptr, const size_t size) |
| Wrapper around the regular realloc memory allocator. | |
| FILE * | xfopen (const char *file, const int line, const char *fnct, const char *name, const char *mode) |
| Wrapper around the regular fopen. | |
Some utility functions and macros.
When available the macros are much simpler to use, so if they fit your needs, do not even look at the functions.
| #define ERROR | ( | retval, | |
| exitval, | |||
| s, | |||
| ... | |||
| ) | { myError(__FILE__, __LINE__, __func__, s, ##__VA_ARGS__); exit (exitval); } |
Print an error message and exit with -1 status.
s is the desired exit status, followed by a printf-like formating string and an optional printf-like variable number of arguments. Example: if file foo.c contains:
and the ERROR macro (at line 47 of foo.c) is executed, it will print the message:
*** error in file foo.c, line 47, function bar: *** invalid value of parameter A: 15
on the standard error and then exit with status -1.
| #define WARNING | ( | ... | ) | warning(__FILE__, __LINE__, __func__, __VA_ARGS__) |
Print a warning message.
Takes a printf-like formating string followed by an optional printf-like variable number of arguments. Example: if file foo.c contains:
and the WARNING macro (at line 47 of foo.c) is executed, it will print the message:
*** warning in file foo.c, line 47, function bar: *** invalid value of parameter A: 15
on the standard error.
| #define XMALLOC | ( | n | ) | xmalloc(__FILE__, __LINE__, __func__, (n)) |
Wrapper around the regular malloc memory allocator.
Allocates n bytes and returns a pointer to the allocated memory. Errors are catched, no need to check result.
| #define XCALLOC | ( | n, | |
| s | |||
| ) | xcalloc(__FILE__, __LINE__, __func__, (n), (s)) |
Wrapper around the regular calloc memory allocator.
Allocates memory for an array of n elements of s bytes each and returns a pointer to the allocated memory. Errors are catched, no need to check result.
| #define XREALLOC | ( | p, | |
| s | |||
| ) | xrealloc(__FILE__, __LINE__, __func__, (p), (s)) |
Wrapper around the regular realloc memory allocator.
Resize the memory area pointed to by p to s bytes and returns a pointer to the allocated memory. Errors are catched, no need to check result.
| #define XFOPEN | ( | f, | |
| m | |||
| ) | xfopen(__FILE__, __LINE__, __func__, (f), (m)) |
Wrapper around the regular fopen.
Opens file f in mode m. Errors are catched, no need to check result.
| void myError | ( | const char * | file, |
| const int | line, | ||
| const char * | fnct, | ||
| const char * | frm, | ||
| ... | |||
| ) |
Prints an error message and exit with -1 status.
Takes a variable number of arguments, as printf.
| file | File name. |
| line | Line number. |
| fnct | Name of calling function. |
| frm | A printf-like formatting string |
| ... | A variable number of arguments. |
| void warning | ( | const char * | file, |
| const int | line, | ||
| const char * | fnct, | ||
| const char * | frm, | ||
| ... | |||
| ) |
Prints a warning message.
Takes a variable number of arguments, as printf.
| file | File name. |
| line | Line number. |
| fnct | Name of calling function. |
| frm | A printf-like formatting string |
| ... | A variable number of arguments. |
| void * xmalloc | ( | const char * | file, |
| const int | line, | ||
| const char * | fnct, | ||
| const size_t | size | ||
| ) |
Wrapper around the regular malloc memory allocator.
Errors are catched, no need to check result.
| file | File name. |
| line | Line number. |
| fnct | Name of calling function. |
| size | Size of an element. |
| void * xcalloc | ( | const char * | file, |
| const int | line, | ||
| const char * | fnct, | ||
| const size_t | nmemb, | ||
| const size_t | size | ||
| ) |
Wrapper around the regular calloc memory allocator.
Errors are catched, no need to check result.
| file | File name. |
| line | Line number. |
| fnct | Name of calling function. |
| nmemb | Number of elements to allocate. |
| size | Size of an element. |
| void * xrealloc | ( | const char * | file, |
| const int | line, | ||
| const char * | fnct, | ||
| void * | ptr, | ||
| const size_t | size | ||
| ) |
Wrapper around the regular realloc memory allocator.
Errors are catched, no need to check result.
| file | File name. |
| line | Line number. |
| fnct | Name of calling function. |
| ptr | Source pointer. |
| size | Size of new memory area. |
| FILE * xfopen | ( | const char * | file, |
| const int | line, | ||
| const char * | fnct, | ||
| const char * | name, | ||
| const char * | mode | ||
| ) |
Wrapper around the regular fopen.
Errors are catched, no need to check result.
| file | File name. |
| line | Line number. |
| fnct | Name of calling function. |
| name | File name |
| mode | Mode |