From 98cc66070be74da84804544ea357d571b709055f Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 7 Nov 2022 16:05:18 +0900 Subject: [PATCH] readnum.c: provide obsolete functions. - mrb_int_read() - mrb_float_read() Both functions should not be use and this file should not be linked. This is just for compatibility. --- src/readnum.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/readnum.c diff --git a/src/readnum.c b/src/readnum.c new file mode 100644 index 000000000..3c459d068 --- /dev/null +++ b/src/readnum.c @@ -0,0 +1,43 @@ +/* this file defines obsolete functions: mrb_int_read() and mrb_float_read() */ +/* use mrb_read_int() and mrb_read_float() instead */ + +#include +#include +#include + +/* mrb_int_read(): read mrb_int from a string (base 10 only) */ +/* const char *p - string to read */ +/* const char *e - end of string */ +/* char **endp - end of parsed integer */ + +/* if integer overflows, errno will be set to ERANGE */ +/* also endp will be set to NULL on overflow */ +MRB_API mrb_int +mrb_int_read(const char *p, const char *e, char **endp) +{ + mrb_int n; + + if (!mrb_read_int(p, e, endp, &n)) { + if (endp) *endp = NULL; + errno = ERANGE; + return MRB_INT_MAX; + } + if (endp) *endp = (char*)p; + return n; +} + +#ifndef MRB_NO_FLOAT +//#include +//#include + +MRB_API double +mrb_float_read(const char *str, char **endp) +{ + double d; + + if (!mrb_read_float(str, endp, &d)) { + errno = ERANGE; + } + return d; +} +#endif