mirror of
https://github.com/archr-linux/Arch-R.git
synced 2026-03-31 14:41:55 -07:00
39 lines
860 B
Diff
39 lines
860 B
Diff
diff -r 6d407d91244b src/parse_utils.c
|
|
--- a/src/parse_utils.c mar sep 15 20:31:33 2009 +0200
|
|
+++ b/src/parse_utils.c mer sep 30 21:26:01 2009 +0200
|
|
@@ -21,7 +21,7 @@
|
|
|
|
#define _GNU_SOURCE
|
|
#include <stdlib.h>
|
|
-#include <locale.h>
|
|
+#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "parse_utils.h"
|
|
@@ -76,12 +76,19 @@
|
|
double
|
|
pl_atof (const char *nptr)
|
|
{
|
|
- double res;
|
|
- locale_t new_locale;
|
|
+ double div = 1.0;
|
|
+ int i, res, integer;
|
|
+ unsigned int frac;
|
|
|
|
- new_locale = newlocale (LC_NUMERIC_MASK, "C", NULL);
|
|
- res = strtod_l (nptr, NULL, new_locale);
|
|
- freelocale (new_locale);
|
|
+ res = sscanf (nptr, "%i.%u", &integer, &frac);
|
|
+ if (res != 2)
|
|
+ return 0.0;
|
|
|
|
- return res;
|
|
+ if (!frac)
|
|
+ return (double) integer;
|
|
+
|
|
+ for (i = pl_count_nb_dec (frac); i; i--)
|
|
+ div *= 10.0;
|
|
+
|
|
+ return (double) integer + (double) frac / div;
|
|
}
|