Back to index

nagios-plugins  1.4.16
Defines | Functions
c-strtod.c File Reference
#include <config.h>
#include "c-strtod.h"
#include <errno.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define C_STRTOD   c_strtod
#define DOUBLE   double
#define STRTOD_L   strtod_l
#define STRTOD   strtod

Functions

DOUBLE C_STRTOD (char const *nptr, char **endptr)

Define Documentation

#define C_STRTOD   c_strtod

Definition at line 34 of file c-strtod.c.

#define DOUBLE   double

Definition at line 35 of file c-strtod.c.

#define STRTOD   strtod

Definition at line 43 of file c-strtod.c.

#define STRTOD_L   strtod_l

Definition at line 36 of file c-strtod.c.


Function Documentation

DOUBLE C_STRTOD ( char const nptr,
char **  endptr 
)

Definition at line 66 of file c-strtod.c.

{
  DOUBLE r;

#ifdef LC_ALL_MASK

  locale_t locale = c_locale ();
  if (!locale)
    {
      if (endptr)
        *endptr = (char *) nptr;
      return 0; /* errno is set here */
    }

  r = STRTOD_L (nptr, endptr, locale);

#else

  char *saved_locale = setlocale (LC_NUMERIC, NULL);

  if (saved_locale)
    {
      saved_locale = strdup (saved_locale);
      if (saved_locale == NULL)
        {
          if (endptr)
            *endptr = (char *) nptr;
          return 0; /* errno is set here */
        }
      setlocale (LC_NUMERIC, "C");
    }

  r = STRTOD (nptr, endptr);

  if (saved_locale)
    {
      int saved_errno = errno;

      setlocale (LC_NUMERIC, saved_locale);
      free (saved_locale);
      errno = saved_errno;
    }

#endif

  return r;
}