Home | History | Annotate | Line # | Download | only in libtommath
      1 /*	$NetBSD: bn_error.c,v 1.2 2017/01/28 21:31:47 christos Exp $	*/
      2 
      3 #include <tommath.h>
      4 #ifdef BN_ERROR_C
      5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
      6  *
      7  * LibTomMath is a library that provides multiple-precision
      8  * integer arithmetic as well as number theoretic functionality.
      9  *
     10  * The library was designed directly after the MPI library by
     11  * Michael Fromberger but has been written from scratch with
     12  * additional optimizations in place.
     13  *
     14  * The library is free for all purposes without any express
     15  * guarantee it works.
     16  *
     17  * Tom St Denis, tomstdenis (at) gmail.com, http://libtom.org
     18  */
     19 
     20 static const struct {
     21      int code;
     22      const char *msg;
     23 } msgs[] = {
     24      { MP_OKAY, "Successful" },
     25      { MP_MEM,  "Out of heap" },
     26      { MP_VAL,  "Value out of range" }
     27 };
     28 
     29 /* return a char * string for a given code */
     30 const char *mp_error_to_string(int code)
     31 {
     32    int x;
     33 
     34    /* scan the lookup table for the given message */
     35    for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) {
     36        if (msgs[x].code == code) {
     37           return msgs[x].msg;
     38        }
     39    }
     40 
     41    /* generic reply for invalid code */
     42    return "Invalid error code";
     43 }
     44 
     45 #endif
     46 
     47 /* Source: /cvs/libtom/libtommath/bn_error.c,v  */
     48 /* Revision: 1.4  */
     49 /* Date: 2006/12/28 01:25:13  */
     50