Timing attack against DES 0.1
Macros | Functions
utils.h File Reference

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.
 

Detailed Description

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.

Author
Renaud Pacalet, renau.nosp@m.d.pa.nosp@m.calet.nosp@m.@tel.nosp@m.ecom-.nosp@m.pari.nosp@m.s.fr
Date
2009-07-08

Macro Definition Documentation

◆ ERROR

#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:

void bar(void)
{
...
A = 15;
ERROR (-1, "invalid value of parameter A: %d", A);
...
}
#define ERROR(retval, exitval, s,...)
Print an error message and exit with -1 status.
Definition utils.h:45

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.

◆ WARNING

#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:

void bar(void)
{
...
A = 15;
WARNING ("invalid value of parameter A: %d", A);
...
}
#define WARNING(...)
Print a warning message.
Definition utils.h:63

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.

◆ XMALLOC

#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.

Returns
pointer to allocated memory area.

◆ XCALLOC

#define XCALLOC (   n,
 
)    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.

Returns
pointer to allocated memory area.

◆ XREALLOC

#define XREALLOC (   p,
 
)    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.

Returns
pointer to allocated memory area.

◆ XFOPEN

#define XFOPEN (   f,
 
)    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.

Returns
The FILE pointer to the opened file.

Function Documentation

◆ myError()

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.

Parameters
fileFile name.
lineLine number.
fnctName of calling function.
frmA printf-like formatting string
...A variable number of arguments.

◆ warning()

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.

Parameters
fileFile name.
lineLine number.
fnctName of calling function.
frmA printf-like formatting string
...A variable number of arguments.

◆ xmalloc()

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.

Returns
pointer to allocated memory area.
Parameters
fileFile name.
lineLine number.
fnctName of calling function.
sizeSize of an element.

◆ xcalloc()

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.

Returns
pointer to allocated memory area.
Parameters
fileFile name.
lineLine number.
fnctName of calling function.
nmembNumber of elements to allocate.
sizeSize of an element.

◆ xrealloc()

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.

Returns
pointer to allocated memory area.
Parameters
fileFile name.
lineLine number.
fnctName of calling function.
ptrSource pointer.
sizeSize of new memory area.

◆ xfopen()

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.

Returns
The FILE pointer to the opened file.
Parameters
fileFile name.
lineLine number.
fnctName of calling function.
nameFile name
modeMode