101e04c3fSmrg/* 201e04c3fSmrg * Copyright 2010 VMware, Inc. 301e04c3fSmrg * All Rights Reserved. 401e04c3fSmrg * 501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 601e04c3fSmrg * copy of this software and associated documentation files (the 701e04c3fSmrg * "Software"), to deal in the Software without restriction, including 801e04c3fSmrg * without limitation the rights to use, copy, modify, merge, publish, 901e04c3fSmrg * distribute, sub license, and/or sell copies of the Software, and to 1001e04c3fSmrg * permit persons to whom the Software is furnished to do so, subject to 1101e04c3fSmrg * the following conditions: 1201e04c3fSmrg * 1301e04c3fSmrg * The above copyright notice and this permission notice (including the 1401e04c3fSmrg * next paragraph) shall be included in all copies or substantial portions 1501e04c3fSmrg * of the Software. 1601e04c3fSmrg * 1701e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1801e04c3fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1901e04c3fSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2001e04c3fSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 2101e04c3fSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2201e04c3fSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2301e04c3fSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2401e04c3fSmrg */ 2501e04c3fSmrg 2601e04c3fSmrg 2701e04c3fSmrg#include <stdlib.h> 2801e04c3fSmrg 2901e04c3fSmrg#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) 3001e04c3fSmrg#include <locale.h> 3101e04c3fSmrg#ifdef HAVE_XLOCALE_H 3201e04c3fSmrg#include <xlocale.h> 3301e04c3fSmrg#endif 3401e04c3fSmrgstatic locale_t loc; 3501e04c3fSmrg#endif 3601e04c3fSmrg 3701e04c3fSmrg#include "strtod.h" 3801e04c3fSmrg 3901e04c3fSmrg 4001e04c3fSmrgvoid 4101e04c3fSmrg_mesa_locale_init(void) 4201e04c3fSmrg{ 4301e04c3fSmrg#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) 4401e04c3fSmrg loc = newlocale(LC_CTYPE_MASK, "C", NULL); 4501e04c3fSmrg#endif 4601e04c3fSmrg} 4701e04c3fSmrg 4801e04c3fSmrgvoid 4901e04c3fSmrg_mesa_locale_fini(void) 5001e04c3fSmrg{ 5101e04c3fSmrg#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) 5201e04c3fSmrg freelocale(loc); 5301e04c3fSmrg#endif 5401e04c3fSmrg} 5501e04c3fSmrg 5601e04c3fSmrg/** 5701e04c3fSmrg * Wrapper around strtod which uses the "C" locale so the decimal 5801e04c3fSmrg * point is always '.' 5901e04c3fSmrg */ 6001e04c3fSmrgdouble 6101e04c3fSmrg_mesa_strtod(const char *s, char **end) 6201e04c3fSmrg{ 6301e04c3fSmrg#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) 6401e04c3fSmrg return strtod_l(s, end, loc); 6501e04c3fSmrg#else 6601e04c3fSmrg return strtod(s, end); 6701e04c3fSmrg#endif 6801e04c3fSmrg} 6901e04c3fSmrg 7001e04c3fSmrg 7101e04c3fSmrg/** 7201e04c3fSmrg * Wrapper around strtof which uses the "C" locale so the decimal 7301e04c3fSmrg * point is always '.' 7401e04c3fSmrg */ 7501e04c3fSmrgfloat 7601e04c3fSmrg_mesa_strtof(const char *s, char **end) 7701e04c3fSmrg{ 7801e04c3fSmrg#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) 7901e04c3fSmrg return strtof_l(s, end, loc); 8001e04c3fSmrg#elif defined(HAVE_STRTOF) 8101e04c3fSmrg return strtof(s, end); 8201e04c3fSmrg#else 8301e04c3fSmrg return (float) strtod(s, end); 8401e04c3fSmrg#endif 8501e04c3fSmrg} 86