Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 7 / 0 / 7
Functions: 100.0% 2 / 0 / 2
Branches: 100.0% 2 / 0 / 2

OMCompiler/SimulationRuntime/c/util/omc_numbers.c
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28 /* strtod_l is considered a GNU extension.
29 * It will fail if the correct prototype does not exist. */
30
31 #define _GNU_SOURCE 1
32
33 #include <stdlib.h>
34
35 #if (defined(_MSC_VER) && _MSC_VER >= 1400)
36
37 #include <locale.h>
38
39
40 _locale_t getCLocale(void)
41 {
42 static int init = 0;
43 static _locale_t loc;
44 if (!init) {
45 loc = _create_locale(LC_NUMERIC, "C");
46 init = 1;
47 }
48 return loc;
49 }
50
51 double om_strtod(const char *nptr, char **endptr)
52 {
53 return _strtod_l(nptr, endptr, getCLocale());
54 }
55
56 #elif (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3)) || defined(__APPLE_CC__)
57
58 #if defined(__GLIBC__)
59 #include <locale.h>
60 #elif defined(__APPLE_CC__)
61 #include <xlocale.h>
62 #include <locale.h>
63 #endif
64
65 2391901 locale_t getCLocale(void)
66 {
67 static int init = 0;
68 static locale_t loc;
69
2/2
✓ Branch 0 taken 1424 times.
✓ Branch 1 taken 2390477 times.
2391901 if (!init) {
70 1424 loc = newlocale(LC_NUMERIC, "C", NULL);
71 1424 init = 1;
72 }
73 2391901 return loc;
74 }
75
76 2391901 double om_strtod(const char *nptr, char **endptr)
77 {
78 2391901 return strtod_l(nptr, endptr, getCLocale());
79 }
80
81 #else
82
83 double om_strtod(const char *nptr, char **endptr)
84 {
85 /* Default to just assuming we have the correct locale */
86 return strtod(nptr, endptr);
87 }
88
89 #endif
90