P99
Macros
Wrappers for C library functions

Wrap library functions such that they throw an exception on error. More...

+ Collaboration diagram for Wrappers for C library functions:

Macros

#define aligned_alloc_throw(...)   P99_THROW_CALL_VOIDP(aligned_alloc, thrd_nomem, __VA_ARGS__)
 A wrapper arround aligned_alloc that throws an exception on error. More...
 
#define at_quick_exit_throw(...)   P99_THROW_CALL_ZERO(at_quick_exit, EINVAL, __VA_ARGS__)
 A wrapper arround at_quick_exit that throws an exception on error. More...
 
#define atexit_throw(...)   P99_THROW_CALL_ZERO(atexit, EINVAL, __VA_ARGS__)
 A wrapper arround atexit that throws an exception on error. More...
 
#define btowc_throw(...)   P99_THROW_CALL_NEG(btowc, EINVAL, __VA_ARGS__)
 A wrapper arround btowc that throws an exception on error. More...
 
#define calloc_throw(...)   P99_THROW_CALL_VOIDP(calloc, thrd_nomem, __VA_ARGS__)
 A wrapper arround calloc that throws an exception on error. More...
 
#define cnd_broadcast_throw(...)   P99_THROW_CALL_THRD(cnd_broadcast, __VA_ARGS__)
 A wrapper arround cnd_broadcast that throws an exception on error. More...
 
#define cnd_init_throw(...)   P99_THROW_CALL_THRD(cnd_init, __VA_ARGS__)
 A wrapper arround cnd_init that throws an exception on error. More...
 
#define cnd_signal_throw(...)   P99_THROW_CALL_THRD(cnd_signal, __VA_ARGS__)
 A wrapper arround cnd_signal that throws an exception on error. More...
 
#define cnd_timedwait_throw(...)   P99_THROW_CALL_THRD(cnd_timedwait, __VA_ARGS__)
 A wrapper arround cnd_timedwait that throws an exception on error. More...
 
#define cnd_wait_throw(...)   P99_THROW_CALL_THRD(cnd_wait, __VA_ARGS__)
 A wrapper arround cnd_wait that throws an exception on error. More...
 
#define fclose_throw(...)   P99_THROW_CALL_ZERO(fclose, EINVAL, __VA_ARGS__)
 A wrapper arround fclose that throws an exception on error. More...
 
#define feclearexcept_throw(...)   P99_THROW_CALL_ZERO(feclearexcept, EINVAL, __VA_ARGS__)
 A wrapper arround feclearexcept that throws an exception on error. More...
 
#define fegetenv_throw(...)   P99_THROW_CALL_ZERO(fegetenv, EINVAL, __VA_ARGS__)
 A wrapper arround fegetenv that throws an exception on error. More...
 
#define fegetexceptflag_throw(...)   P99_THROW_CALL_ZERO(fegetexceptflag, EINVAL, __VA_ARGS__)
 A wrapper arround fegetexceptflag that throws an exception on error. More...
 
#define fegetround_throw(...)   P99_THROW_CALL_ZERO(fegetround, EINVAL, __VA_ARGS__)
 A wrapper arround fegetround that throws an exception on error. More...
 
#define feholdexcept_throw(...)   P99_THROW_CALL_ZERO(feholdexcept, EINVAL, __VA_ARGS__)
 A wrapper arround feholdexcept that throws an exception on error. More...
 
#define feraiseexcept_throw(...)   P99_THROW_CALL_ZERO(feraiseexcept, EINVAL, __VA_ARGS__)
 A wrapper arround feraiseexcept that throws an exception on error. More...
 
#define fesetenv_throw(...)   P99_THROW_CALL_ZERO(fesetenv, EINVAL, __VA_ARGS__)
 A wrapper arround fesetenv that throws an exception on error. More...
 
#define fesetexceptflag_throw(...)   P99_THROW_CALL_ZERO(fesetexceptflag, EINVAL, __VA_ARGS__)
 A wrapper arround fesetexceptflag that throws an exception on error. More...
 
#define fesetround_throw(...)   P99_THROW_CALL_ZERO(fesetround, EINVAL, __VA_ARGS__)
 A wrapper arround fesetround that throws an exception on error. More...
 
#define fetestexcept_throw(...)   P99_THROW_CALL_ZERO(fetestexcept, EINVAL, __VA_ARGS__)
 A wrapper arround fetestexcept that throws an exception on error. More...
 
#define feupdateenv_throw(...)   P99_THROW_CALL_ZERO(feupdateenv, EINVAL, __VA_ARGS__)
 A wrapper arround feupdateenv that throws an exception on error. More...
 
#define fflush_throw(...)   P99_THROW_CALL_ZERO(fflush, EINVAL, __VA_ARGS__)
 A wrapper arround fflush that throws an exception on error. More...
 
#define fgetc_throw(...)   P99_THROW_CALL_NEG(fgetc, EINVAL, __VA_ARGS__)
 A wrapper arround fgetc that throws an exception on error. More...
 
#define fgetpos_throw(...)   P99_THROW_CALL_ZERO(fgetpos, EINVAL, __VA_ARGS__)
 A wrapper arround fgetpos that throws an exception on error. More...
 
#define fgets_throw(...)   P99_THROW_CALL_VOIDP(fgets, EINVAL, __VA_ARGS__)
 A wrapper arround fgets that throws an exception on error. More...
 
#define fgetwc_throw(...)   P99_THROW_CALL_NEG(fgetwc, EINVAL, __VA_ARGS__)
 A wrapper arround fgetwc that throws an exception on error. More...
 
#define fgetws_throw(...)   P99_THROW_CALL_NEG(fgetws, EINVAL, __VA_ARGS__)
 A wrapper arround fgetws that throws an exception on error. More...
 
#define fopen_throw(...)   P99_THROW_CALL_VOIDP(fopen, EINVAL, __VA_ARGS__)
 A wrapper arround fopen that throws an exception on error. More...
 
#define fprintf_throw(...)   P99_THROW_CALL_NEG(fprintf, EINVAL, __VA_ARGS__)
 A wrapper arround fprintf that throws an exception on error. More...
 
#define fputc_throw(...)   P99_THROW_CALL_NEG(fputc, EINVAL, __VA_ARGS__)
 A wrapper arround fputc that throws an exception on error. More...
 
#define fputs_throw(...)   P99_THROW_CALL_NEG(fputs, EINVAL, __VA_ARGS__)
 A wrapper arround fputs that throws an exception on error. More...
 
#define fputwc_throw(...)   P99_THROW_CALL_NEG(fputwc, EINVAL, __VA_ARGS__)
 A wrapper arround fputwc that throws an exception on error. More...
 
#define fputws_throw(...)   P99_THROW_CALL_NEG(fputws, EINVAL, __VA_ARGS__)
 A wrapper arround fputws that throws an exception on error. More...
 
#define freopen_throw(...)   P99_THROW_CALL_VOIDP(freopen, EINVAL, __VA_ARGS__)
 A wrapper arround freopen that throws an exception on error. More...
 
#define fscanf_throw(...)   P99_THROW_CALL_NEG(fscanf, EINVAL, __VA_ARGS__)
 A wrapper arround fscanf that throws an exception on error. More...
 
#define fseek_throw(...)   P99_THROW_CALL_ZERO(fseek, EINVAL, __VA_ARGS__)
 A wrapper arround fseek that throws an exception on error. More...
 
#define fsetpos_throw(...)   P99_THROW_CALL_ZERO(fsetpos, EINVAL, __VA_ARGS__)
 A wrapper arround fsetpos that throws an exception on error. More...
 
#define ftell_throw(...)   P99_THROW_CALL_NEG(ftell, EINVAL, __VA_ARGS__)
 A wrapper arround ftell that throws an exception on error. More...
 
#define fwprintf_throw(...)   P99_THROW_CALL_NEG(fwprintf, EINVAL, __VA_ARGS__)
 A wrapper arround fwprintf that throws an exception on error. More...
 
#define fwscanf_throw(...)   P99_THROW_CALL_NEG(fwscanf, EINVAL, __VA_ARGS__)
 A wrapper arround fwscanf that throws an exception on error. More...
 
#define getc_throw(...)   P99_THROW_CALL_NEG(getc, EINVAL, __VA_ARGS__)
 A wrapper arround getc that throws an exception on error. More...
 
#define getchar_throw(...)   P99_THROW_CALL_NEG(getchar, EINVAL, __VA_ARGS__)
 A wrapper arround getchar that throws an exception on error. More...
 
#define getenv_throw(...)   P99_THROW_CALL_NEG(getenv, EINVAL, __VA_ARGS__)
 A wrapper arround getenv that throws an exception on error. More...
 
#define getwc_throw(...)   P99_THROW_CALL_NEG(getwc, EINVAL, __VA_ARGS__)
 A wrapper arround getwc that throws an exception on error. More...
 
#define getwchar_throw(...)   P99_THROW_CALL_NEG(getwchar, EINVAL, __VA_ARGS__)
 A wrapper arround getwchar that throws an exception on error. More...
 
#define malloc_throw(...)   P99_THROW_CALL_VOIDP(malloc, thrd_nomem, __VA_ARGS__)
 A wrapper arround malloc that throws an exception on error. More...
 
#define mblen_throw(...)   P99_THROW_CALL_NEG(mblen, EINVAL, __VA_ARGS__)
 A wrapper arround mblen that throws an exception on error. More...
 
#define mbtowc_throw(...)   P99_THROW_CALL_NEG(mbtowc, EINVAL, __VA_ARGS__)
 A wrapper arround mbtowc that throws an exception on error. More...
 
#define mtx_init_throw(...)   P99_THROW_CALL_THRD(mtx_init, __VA_ARGS__)
 A wrapper arround mtx_init that throws an exception on error. More...
 
#define mtx_lock_throw(...)   P99_THROW_CALL_THRD(mtx_lock, __VA_ARGS__)
 A wrapper arround mtx_lock that throws an exception on error. More...
 
#define mtx_timedlock_throw(...)   P99_THROW_CALL_THRD(mtx_timedlock, __VA_ARGS__)
 A wrapper arround mtx_timedlock that throws an exception on error. More...
 
#define mtx_unlock_throw(...)   P99_THROW_CALL_THRD(mtx_unlock, __VA_ARGS__)
 A wrapper arround mtx_unlock that throws an exception on error. More...
 
#define printf_throw(...)   P99_THROW_CALL_NEG(printf, EINVAL, __VA_ARGS__)
 A wrapper arround printf that throws an exception on error. More...
 
#define putc_throw(...)   P99_THROW_CALL_NEG(putc, EINVAL, __VA_ARGS__)
 A wrapper arround putc that throws an exception on error. More...
 
#define putchar_throw(...)   P99_THROW_CALL_NEG(putchar, EINVAL, __VA_ARGS__)
 A wrapper arround putchar that throws an exception on error. More...
 
#define puts_throw(...)   P99_THROW_CALL_NEG(puts, EINVAL, __VA_ARGS__)
 A wrapper arround puts that throws an exception on error. More...
 
#define putwc_throw(...)   P99_THROW_CALL_NEG(putwc, EINVAL, __VA_ARGS__)
 A wrapper arround putwc that throws an exception on error. More...
 
#define putwchar_throw(...)   P99_THROW_CALL_NEG(putwchar, EINVAL, __VA_ARGS__)
 A wrapper arround putwchar that throws an exception on error. More...
 
#define raise_throw(...)   P99_THROW_CALL_ZERO(raise, EINVAL, __VA_ARGS__)
 A wrapper arround raise that throws an exception on error. More...
 
#define realloc_throw(...)   P99_THROW_CALL_VOIDP(realloc, thrd_nomem, __VA_ARGS__)
 A wrapper arround realloc that throws an exception on error. More...
 
#define remove_throw(...)   P99_THROW_CALL_NEG(remove, EINVAL, __VA_ARGS__)
 A wrapper arround remove that throws an exception on error. More...
 
#define rename_throw(...)   P99_THROW_CALL_NEG(rename, EINVAL, __VA_ARGS__)
 A wrapper arround rename that throws an exception on error. More...
 
#define scanf_throw(...)   P99_THROW_CALL_NEG(scanf, EINVAL, __VA_ARGS__)
 A wrapper arround scanf that throws an exception on error. More...
 
#define setvbuf_throw(...)   P99_THROW_CALL_ZERO(setvbuf, EINVAL, __VA_ARGS__)
 A wrapper arround setvbuf that throws an exception on error. More...
 
#define snprintf_throw(...)   P99_THROW_CALL_NEG(snprintf, EINVAL, __VA_ARGS__)
 A wrapper arround snprintf that throws an exception on error. More...
 
#define sprintf_throw(...)   P99_THROW_CALL_NEG(sprintf, EINVAL, __VA_ARGS__)
 A wrapper arround sprintf that throws an exception on error. More...
 
#define sscanf_throw(...)   P99_THROW_CALL_NEG(sscanf, EINVAL, __VA_ARGS__)
 A wrapper arround sscanf that throws an exception on error. More...
 
#define strtod_throw(...)   P99_THROW_CALL_RANGE(strtod, __VA_ARGS__)
 A wrapper arround strtod that throws an exception on error. More...
 
#define strtof_throw(...)   P99_THROW_CALL_RANGE(strtof, __VA_ARGS__)
 A wrapper arround strtof that throws an exception on error. More...
 
#define strtoimax_throw(...)   P99_THROW_CALL_RANGE(strtoimax, __VA_ARGS__)
 A wrapper arround strtoimax that throws an exception on error. More...
 
#define strtol_throw(...)   P99_THROW_CALL_RANGE(strtol, __VA_ARGS__)
 A wrapper arround strtol that throws an exception on error. More...
 
#define strtold_throw(...)   P99_THROW_CALL_RANGE(strtold, __VA_ARGS__)
 A wrapper arround strtold that throws an exception on error. More...
 
#define strtoll_throw(...)   P99_THROW_CALL_RANGE(strtoll, __VA_ARGS__)
 A wrapper arround strtoll that throws an exception on error. More...
 
#define strtoul_throw(...)   P99_THROW_CALL_RANGE(strtoul, __VA_ARGS__)
 A wrapper arround strtoul that throws an exception on error. More...
 
#define strtoull_throw(...)   P99_THROW_CALL_RANGE(strtoull, __VA_ARGS__)
 A wrapper arround strtoull that throws an exception on error. More...
 
#define strtoumax_throw(...)   P99_THROW_CALL_RANGE(strtoumax, __VA_ARGS__)
 A wrapper arround strtoumax that throws an exception on error. More...
 
#define swprintf_throw(...)   P99_THROW_CALL_NEG(swprintf, EINVAL, __VA_ARGS__)
 A wrapper arround swprintf that throws an exception on error. More...
 
#define swscanf_throw(...)   P99_THROW_CALL_NEG(swscanf, EINVAL, __VA_ARGS__)
 A wrapper arround swscanf that throws an exception on error. More...
 
#define system_throw(...)   P99_THROW_CALL_NEG(system, EINVAL, __VA_ARGS__)
 A wrapper arround system that throws an exception on error. More...
 
#define thrd_create_throw(...)   P99_THROW_CALL_THRD(thrd_create, __VA_ARGS__)
 A wrapper arround thrd_create that throws an exception on error. More...
 
#define thrd_detach_throw(...)   P99_THROW_CALL_THRD(thrd_detach, __VA_ARGS__)
 A wrapper arround thrd_detach that throws an exception on error. More...
 
#define thrd_equal_throw(...)   P99_THROW_CALL_THRD(thrd_equal, __VA_ARGS__)
 A wrapper arround thrd_equal that throws an exception on error. More...
 
#define thrd_join_throw(...)   P99_THROW_CALL_THRD(thrd_join, __VA_ARGS__)
 A wrapper arround thrd_join that throws an exception on error. More...
 
#define thrd_sleep_throw(...)   P99_THROW_CALL_THRD(thrd_sleep, __VA_ARGS__)
 A wrapper arround thrd_sleep that throws an exception on error. More...
 
#define tmpfile_throw(...)   P99_THROW_CALL_VOIDP(tmpfile, EINVAL, __VA_ARGS__)
 A wrapper arround tmpfile that throws an exception on error. More...
 
#define tmpnam_throw(...)   P99_THROW_CALL_VOIDP(tmpnam, EINVAL, __VA_ARGS__)
 A wrapper arround tmpnam that throws an exception on error. More...
 
#define tss_create_throw(...)   P99_THROW_CALL_THRD(tss_create, __VA_ARGS__)
 A wrapper arround tss_create that throws an exception on error. More...
 
#define tss_set_throw(...)   P99_THROW_CALL_THRD(tss_set, __VA_ARGS__)
 A wrapper arround tss_set that throws an exception on error. More...
 
#define ungetc_throw(...)   P99_THROW_CALL_NEG(ungetc, EINVAL, __VA_ARGS__)
 A wrapper arround ungetc that throws an exception on error. More...
 
#define ungetwc_throw(...)   P99_THROW_CALL_NEG(ungetwc, EINVAL, __VA_ARGS__)
 A wrapper arround ungetwc that throws an exception on error. More...
 
#define vfprintf_throw(...)   P99_THROW_CALL_NEG(vfprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vfprintf that throws an exception on error. More...
 
#define vfscanf_throw(...)   P99_THROW_CALL_NEG(vfscanf, EINVAL, __VA_ARGS__)
 A wrapper arround vfscanf that throws an exception on error. More...
 
#define vfwprintf_throw(...)   P99_THROW_CALL_NEG(vfwprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vfwprintf that throws an exception on error. More...
 
#define vfwscanf_throw(...)   P99_THROW_CALL_NEG(vfwscanf, EINVAL, __VA_ARGS__)
 A wrapper arround vfwscanf that throws an exception on error. More...
 
#define vprintf_throw(...)   P99_THROW_CALL_NEG(vprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vprintf that throws an exception on error. More...
 
#define vscanf_throw(...)   P99_THROW_CALL_NEG(vscanf, EINVAL, __VA_ARGS__)
 A wrapper arround vscanf that throws an exception on error. More...
 
#define vsnprintf_throw(...)   P99_THROW_CALL_NEG(vsnprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vsnprintf that throws an exception on error. More...
 
#define vsprintf_throw(...)   P99_THROW_CALL_NEG(vsprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vsprintf that throws an exception on error. More...
 
#define vsscanf_throw(...)   P99_THROW_CALL_NEG(vsscanf, EINVAL, __VA_ARGS__)
 A wrapper arround vsscanf that throws an exception on error. More...
 
#define vswprintf_throw(...)   P99_THROW_CALL_NEG(vswprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vswprintf that throws an exception on error. More...
 
#define vswscanf_throw(...)   P99_THROW_CALL_NEG(vswscanf, EINVAL, __VA_ARGS__)
 A wrapper arround vswscanf that throws an exception on error. More...
 
#define vwprintf_throw(...)   P99_THROW_CALL_NEG(vwprintf, EINVAL, __VA_ARGS__)
 A wrapper arround vwprintf that throws an exception on error. More...
 
#define vwscanf_throw(...)   P99_THROW_CALL_NEG(vwscanf, EINVAL, __VA_ARGS__)
 A wrapper arround vwscanf that throws an exception on error. More...
 
#define wcstod_throw(...)   P99_THROW_CALL_RANGE(wcstod, __VA_ARGS__)
 A wrapper arround wcstod that throws an exception on error. More...
 
#define wcstof_throw(...)   P99_THROW_CALL_RANGE(wcstof, __VA_ARGS__)
 A wrapper arround wcstof that throws an exception on error. More...
 
#define wcstoimax_throw(...)   P99_THROW_CALL_RANGE(wcstoimax, __VA_ARGS__)
 A wrapper arround wcstoimax that throws an exception on error. More...
 
#define wcstok_throw(...)   P99_THROW_CALL_RANGE(wcstok, __VA_ARGS__)
 A wrapper arround wcstok that throws an exception on error. More...
 
#define wcstol_throw(...)   P99_THROW_CALL_RANGE(wcstol, __VA_ARGS__)
 A wrapper arround wcstol that throws an exception on error. More...
 
#define wcstold_throw(...)   P99_THROW_CALL_RANGE(wcstold, __VA_ARGS__)
 A wrapper arround wcstold that throws an exception on error. More...
 
#define wcstoll_throw(...)   P99_THROW_CALL_RANGE(wcstoll, __VA_ARGS__)
 A wrapper arround wcstoll that throws an exception on error. More...
 
#define wcstoul_throw(...)   P99_THROW_CALL_RANGE(wcstoul, __VA_ARGS__)
 A wrapper arround wcstoul that throws an exception on error. More...
 
#define wcstoull_throw(...)   P99_THROW_CALL_RANGE(wcstoull, __VA_ARGS__)
 A wrapper arround wcstoull that throws an exception on error. More...
 
#define wcstoumax_throw(...)   P99_THROW_CALL_RANGE(wcstoumax, __VA_ARGS__)
 A wrapper arround wcstoumax that throws an exception on error. More...
 
#define wctomb_throw(...)   P99_THROW_CALL_NEG(wctomb, EINVAL, __VA_ARGS__)
 A wrapper arround wctomb that throws an exception on error. More...
 
#define wprintf_throw(...)   P99_THROW_CALL_NEG(wprintf, EINVAL, __VA_ARGS__)
 A wrapper arround wprintf that throws an exception on error. More...
 
#define wscanf_throw(...)   P99_THROW_CALL_NEG(wscanf, EINVAL, __VA_ARGS__)
 A wrapper arround wscanf that throws an exception on error. More...
 

Detailed Description

Wrap library functions such that they throw an exception on error.

All macros here have the form of NAME_throw, where NAME is a C library function. All these macros are classified according to one of the conventions that are present in the C library on the strategies how errors are returned.

Eg. to have a malloc that always checks the return do

double (*A)[n] = malloc_throw(sizeof *A);

In case you want just blend the names of the system calls you could do yourself for the ones that you want something like

#define malloc malloc_throw
...
double (*A)[n] = malloc(sizeof *A);
Warning
Since these are just too many different calls only few of them have been tested. If you find a classification error please let us know.
malloc_throw
#define malloc_throw(...)
A wrapper arround malloc that throws an exception on error.
Definition: p99_c99_throw.h:212
double
struct atomic_double double
Definition: p99_atomic.h:63