ReactOS 0.4.15-dev-8058-ga7cbb60
gcvt.c
Go to the documentation of this file.
1/*
2 * msvcrt.dll math functions
3 *
4 * Copyright 2003 Alexandre Julliard <julliard@winehq.org>
5 * Copyright 2010 Piotr Caban <piotr@codeweavers.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23#include <precomp.h>
24
25/***********************************************************************
26 * _gcvt (MSVCRT.@)
27 */
28char* CDECL _gcvt(double number, int ndigit, char* buff)
29{
30 if (!buff) {
31 *_errno() = EINVAL;
32 return NULL;
33 }
34
35 if (ndigit < 0) {
36 *_errno() = ERANGE;
37 return NULL;
38 }
39
40 sprintf(buff, "%.*g", ndigit, number);
41 return buff;
42}
43
44/***********************************************************************
45 * _gcvt_s (MSVCRT.@)
46 */
47int CDECL _gcvt_s(char* buff, size_t size, double number, int digits)
48{
49 int len;
50
51 if (!buff) {
52 *_errno() = EINVAL;
53 return EINVAL;
54 }
55
56 if (digits < 0 || digits >= size) {
57 if (size)
58 buff[0] = '\0';
59
60 *_errno() = ERANGE;
61 return ERANGE;
62 }
63
64 len = _scprintf("%.*g", digits, number);
65 if (len > size) {
66 buff[0] = '\0';
67 *_errno() = ERANGE;
68 return ERANGE;
69 }
70
71 sprintf(buff, "%.*g", digits, number);
72 return 0;
73}
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
#define NULL
Definition: types.h:112
#define CDECL
Definition: compat.h:29
static unsigned char buff[32768]
Definition: fatten.c:17
char *CDECL _gcvt(double number, int ndigit, char *buff)
Definition: gcvt.c:28
int CDECL _gcvt_s(char *buff, size_t size, double number, int digits)
Definition: gcvt.c:47
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_ _CRTIMP int __cdecl _scprintf(_In_z_ _Printf_format_string_ const char *_Format,...)
static const int digits[]
Definition: decode.c:71
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static unsigned int number
Definition: dsound.c:1479
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17