mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 06:08:02 +02:00
shared: add nm_g_ascii_strtod() to workaround bug
(cherry picked from commit35a9f632a8) (cherry picked from commitf8cae1ed18) (cherry picked from commit0de1c3a53a)
This commit is contained in:
parent
4633d6a8b5
commit
e2bfbd9c81
2 changed files with 40 additions and 0 deletions
|
|
@ -780,6 +780,43 @@ again:
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* see nm_g_ascii_strtoll(). */
|
||||||
|
double
|
||||||
|
nm_g_ascii_strtod (const char *nptr,
|
||||||
|
char **endptr)
|
||||||
|
{
|
||||||
|
int try_count = 2;
|
||||||
|
double v;
|
||||||
|
int errsv;
|
||||||
|
|
||||||
|
nm_assert (nptr);
|
||||||
|
|
||||||
|
again:
|
||||||
|
v = g_ascii_strtod (nptr, endptr);
|
||||||
|
errsv = errno;
|
||||||
|
|
||||||
|
if (errsv == 0)
|
||||||
|
return v;
|
||||||
|
|
||||||
|
if (errsv == ERANGE)
|
||||||
|
return v;
|
||||||
|
|
||||||
|
if (try_count-- > 0)
|
||||||
|
goto again;
|
||||||
|
|
||||||
|
#if NM_MORE_ASSERTS
|
||||||
|
g_critical ("g_ascii_strtod() for \"%s\" failed with errno=%d (%s) and v=%f",
|
||||||
|
nptr,
|
||||||
|
errsv,
|
||||||
|
nm_strerror_native (errsv),
|
||||||
|
v);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Not really much else to do. Return the parsed value and leave errno set
|
||||||
|
* to the unexpected value. */
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
/* _nm_utils_ascii_str_to_int64:
|
/* _nm_utils_ascii_str_to_int64:
|
||||||
*
|
*
|
||||||
* A wrapper for g_ascii_strtoll, that checks whether the whole string
|
* A wrapper for g_ascii_strtoll, that checks whether the whole string
|
||||||
|
|
|
||||||
|
|
@ -543,6 +543,9 @@ gint64 nm_g_ascii_strtoll (const char *nptr,
|
||||||
char **endptr,
|
char **endptr,
|
||||||
guint base);
|
guint base);
|
||||||
|
|
||||||
|
double nm_g_ascii_strtod (const char *nptr,
|
||||||
|
char **endptr);
|
||||||
|
|
||||||
gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
|
gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
|
||||||
guint64 _nm_utils_ascii_str_to_uint64 (const char *str, guint base, guint64 min, guint64 max, guint64 fallback);
|
guint64 _nm_utils_ascii_str_to_uint64 (const char *str, guint base, guint64 min, guint64 max, guint64 fallback);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue