libzahl

big integer library
git clone git://git.suckless.org/libzahl
Log | Files | Refs | README | LICENSE

zerror.c (667B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "internals.h"
      3 
      4 
      5 #define LIST_ERRORS\
      6 	X(ZERROR_0_POW_0,  "indeterminate form: 0:th power of 0")\
      7 	X(ZERROR_0_DIV_0,  "indeterminate form: 0 divided by 0")\
      8 	X(ZERROR_DIV_0,    "undefined result: division by 0")\
      9 	X(ZERROR_NEGATIVE, "argument must be non-negative")
     10 
     11 
     12 enum zerror
     13 zerror(const char **desc)
     14 {
     15 	if (libzahl_error >= 0) {
     16 		if (desc)
     17 			*desc = strerror(libzahl_error);
     18 		errno = libzahl_error;
     19 		return ZERROR_ERRNO_SET;
     20 	}
     21 
     22 	if (desc) {
     23 		switch (-libzahl_error) {
     24 #define X(V, D) case V: *desc = D; break;
     25 		LIST_ERRORS
     26 #undef X
     27 		default:
     28 			abort();
     29 		}
     30 	}
     31 	return -libzahl_error;
     32 }