runtime moves to common-serivce.
[platform/framework/native/appfw.git] / src / newlib-compat / NewlibCompatStdlib.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // This license applies to all functions, except for the functions under the below mentioned license
17 // in this file.
18 //
19
20
21 //
22 // Copyright (c) 1998, M. Warner Losh <imp@freebsd.org>
23 // All rights reserved.
24 //
25 // Redistribution and use in source and binary forms, with or without
26 // modification, are permitted provided that the following conditions
27 // are met:
28 // 1. Redistributions of source code must retain the above copyright
29 //    notice, this list of conditions and the following disclaimer.c
30 // 2. Redistributions in binary form must reproduce the above copyright
31 //    notice, this list of conditions and the following disclaimer in the
32 //    documentation and/or other materials provided with the distribution.
33 //
34 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
35 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 // ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
38 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 // SUCH DAMAGE.
45 //
46 // This license applies to all the permissions of the below mentioned function.
47 // Function: reallocf
48 //
49
50
51 #include <FOspCompat.h>
52
53 float
54 atoff(const char* pcStr)
55 {
56         return strtof (pcStr, NULL);
57 }
58
59 char*
60 ecvtf(float fval, int ndigit, int* decpt, int* sign)
61 {
62         return ecvt((double)fval, ndigit, decpt, sign);
63 }
64
65
66 char*
67 ecvtbuf(double invalue, int ndigit, int* decpt, int* sign, char* ecvt_buf)
68 {
69         char* pecvt_ret = ecvt(invalue, ndigit, decpt, sign);
70         strcpy(ecvt_buf, pecvt_ret);
71         return ecvt_buf;
72 }
73
74
75 char*
76 fcvtf( float fval, int ndigit, int* decpt, int* sign)
77 {
78         return fcvt((double)fval, ndigit, decpt, sign);
79 }
80
81
82 char*
83 fcvtbuf(double invalue, int ndigit, int* decpt, int* sign, char* fcvt_buf)
84 {
85         char* pfcvt_ret = fcvt( invalue, ndigit, decpt, sign);
86         strcpy(fcvt_buf, pfcvt_ret);
87         return fcvt_buf;
88 }
89
90
91 char*
92 gcvtf( float fval, int ndigit, char* buf)
93 {
94         return gcvt((double)fval, ndigit, buf);
95 }
96
97
98 void*
99 reallocf(void* ptr, unsigned int size)
100 {
101         void* ptemp = NULL;
102         ptemp = realloc( ptr, size);
103         if (!ptemp && ptr)
104         {
105                 free( ptr);
106         }
107         return (ptemp);
108 }