2 * MSVCRT string functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define _ISOC99_SOURCE
26 #include "wine/port.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
38 /*********************************************************************
42 char* CDECL
_strdup(const char* str
)
46 char * ret
= MSVCRT_malloc(strlen(str
)+1);
47 if (ret
) strcpy( ret
, str
);
53 /*********************************************************************
54 * _strlwr_s (MSVCRT.@)
56 int CDECL
_strlwr_s(char *str
, MSVCRT_size_t len
)
62 *MSVCRT__errno() = MSVCRT_EINVAL
;
75 *MSVCRT__errno() = MSVCRT_EINVAL
;
88 /*********************************************************************
91 char* CDECL
MSVCRT__strnset(char* str
, int value
, MSVCRT_size_t len
)
99 /*********************************************************************
102 char* CDECL
_strrev(char* str
)
108 for (p1
= str
, p2
= str
+ strlen(str
) - 1; p2
> p1
; ++p1
, --p2
)
118 /*********************************************************************
121 char* CDECL
_strset(char* str
, int value
)
130 /*********************************************************************
133 char * CDECL
MSVCRT_strtok( char *str
, const char *delim
)
135 thread_data_t
*data
= msvcrt_get_thread_data();
139 if (!(str
= data
->strtok_next
)) return NULL
;
141 while (*str
&& strchr( delim
, *str
)) str
++;
142 if (!*str
) return NULL
;
144 while (*str
&& !strchr( delim
, *str
)) str
++;
145 if (*str
) *str
++ = 0;
146 data
->strtok_next
= str
;
150 /*********************************************************************
151 * strtok_s (MSVCRT.@)
153 char * CDECL
MSVCRT_strtok_s(char *str
, const char *delim
, char **ctx
)
155 if (!MSVCRT_CHECK_PMT(delim
!= NULL
) || !MSVCRT_CHECK_PMT(ctx
!= NULL
) ||
156 !MSVCRT_CHECK_PMT(str
!= NULL
|| *ctx
!= NULL
)) {
157 *MSVCRT__errno() = MSVCRT_EINVAL
;
164 while(*str
&& strchr(delim
, *str
))
170 while(**ctx
&& !strchr(delim
, **ctx
))
178 /*********************************************************************
181 void CDECL
MSVCRT__swab(char* src
, char* dst
, int len
)
185 len
= (unsigned)len
>> 1;
197 /*********************************************************************
198 * strtod_l (MSVCRT.@)
200 double CDECL
MSVCRT_strtod_l( const char *str
, char **end
, MSVCRT__locale_t locale
)
202 unsigned __int64 d
=0, hlp
;
207 BOOL found_digit
= FALSE
;
209 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) {
210 *MSVCRT__errno() = MSVCRT_EINVAL
;
215 locale
= get_locale();
217 /* FIXME: use *_l functions */
230 hlp
= d
*10+*(p
++)-'0';
231 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
) {
242 if(*p
== *locale
->locinfo
->lconv
->decimal_point
)
247 hlp
= d
*10+*(p
++)-'0';
248 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
)
263 if(*p
=='e' || *p
=='E' || *p
=='d' || *p
=='D') {
275 if(e
>INT_MAX
/10 || (e
=e
*10+*p
-'0')<0)
281 if(exp
<0 && e
<0 && exp
+e
>=0) exp
= INT_MIN
;
282 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
285 if(*p
=='-' || *p
=='+')
291 fpcontrol
= _control87(0, 0);
292 _control87(MSVCRT__EM_DENORMAL
|MSVCRT__EM_INVALID
|MSVCRT__EM_ZERODIVIDE
293 |MSVCRT__EM_OVERFLOW
|MSVCRT__EM_UNDERFLOW
|MSVCRT__EM_INEXACT
, 0xffffffff);
296 ret
= (double)sign
*d
*pow(10, exp
);
298 ret
= (double)sign
*d
/pow(10, -exp
);
300 _control87(fpcontrol
, 0xffffffff);
302 if((d
&& ret
==0.0) || isinf(ret
))
303 *MSVCRT__errno() = MSVCRT_ERANGE
;
311 /*********************************************************************
314 double CDECL
MSVCRT_strtod( const char *str
, char **end
)
316 return MSVCRT_strtod_l( str
, end
, NULL
);
319 /*********************************************************************
322 double CDECL
MSVCRT_atof( const char *str
)
324 return MSVCRT_strtod_l(str
, NULL
, NULL
);
327 /*********************************************************************
330 double CDECL
MSVCRT__atof_l( const char *str
, MSVCRT__locale_t locale
)
332 return MSVCRT_strtod_l(str
, NULL
, locale
);
335 /*********************************************************************
338 int CDECL
MSVCRT_strcoll( const char* str1
, const char* str2
)
340 /* FIXME: handle Windows locale */
341 return strcoll( str1
, str2
);
344 /*********************************************************************
345 * strcpy_s (MSVCRT.@)
347 int CDECL
MSVCRT_strcpy_s( char* dst
, MSVCRT_size_t elem
, const char* src
)
350 if(!elem
) return MSVCRT_EINVAL
;
351 if(!dst
) return MSVCRT_EINVAL
;
355 return MSVCRT_EINVAL
;
358 for(i
= 0; i
< elem
; i
++)
360 if((dst
[i
] = src
[i
]) == '\0') return 0;
363 return MSVCRT_ERANGE
;
366 /*********************************************************************
367 * strcat_s (MSVCRT.@)
369 int CDECL
MSVCRT_strcat_s( char* dst
, MSVCRT_size_t elem
, const char* src
)
372 if(!dst
) return MSVCRT_EINVAL
;
373 if(elem
== 0) return MSVCRT_EINVAL
;
377 return MSVCRT_EINVAL
;
380 for(i
= 0; i
< elem
; i
++)
384 for(j
= 0; (j
+ i
) < elem
; j
++)
386 if((dst
[j
+ i
] = src
[j
]) == '\0') return 0;
390 /* Set the first element to 0, not the first element after the skipped part */
392 return MSVCRT_ERANGE
;
395 /*********************************************************************
396 * strncat_s (MSVCRT.@)
398 int CDECL
MSVCRT_strncat_s( char* dst
, MSVCRT_size_t elem
, const char* src
, MSVCRT_size_t count
)
401 if(!MSVCRT_CHECK_PMT(dst
!= 0) || !MSVCRT_CHECK_PMT(elem
!= 0))
402 return MSVCRT_EINVAL
;
403 if(!MSVCRT_CHECK_PMT(src
!= 0))
406 return MSVCRT_EINVAL
;
409 for(i
= 0; i
< elem
; i
++)
413 for(j
= 0; (j
+ i
) < elem
; j
++)
415 if(count
== MSVCRT__TRUNCATE
&& j
+ i
== elem
- 1)
418 return MSVCRT_STRUNCATE
;
420 if(j
== count
|| (dst
[j
+ i
] = src
[j
]) == '\0')
428 /* Set the first element to 0, not the first element after the skipped part */
430 return MSVCRT_ERANGE
;
433 /*********************************************************************
436 MSVCRT_size_t CDECL
MSVCRT_strxfrm( char *dest
, const char *src
, MSVCRT_size_t len
)
438 /* FIXME: handle Windows locale */
439 return strxfrm( dest
, src
, len
);
442 /*********************************************************************
443 * _stricoll (MSVCRT.@)
445 int CDECL
MSVCRT__stricoll( const char* str1
, const char* str2
)
447 /* FIXME: handle collates */
448 TRACE("str1 %s str2 %s\n", debugstr_a(str1
), debugstr_a(str2
));
449 return lstrcmpiA( str1
, str2
);
452 /********************************************************************
453 * _atoldbl (MSVCRT.@)
455 int CDECL
MSVCRT__atoldbl(MSVCRT__LDOUBLE
*value
, const char *str
)
457 /* FIXME needs error checking for huge/small values */
459 TRACE("str %s value %p\n",str
,value
);
460 value
->x
= strtold(str
,0);
462 FIXME("stub, str %s value %p\n",str
,value
);
467 /********************************************************************
468 * __STRINGTOLD (MSVCRT.@)
470 int CDECL
__STRINGTOLD( MSVCRT__LDOUBLE
*value
, char **endptr
, const char *str
, int flags
)
473 FIXME("%p %p %s %x partial stub\n", value
, endptr
, str
, flags
);
474 value
->x
= strtold(str
,endptr
);
476 FIXME("%p %p %s %x stub\n", value
, endptr
, str
, flags
);
481 /******************************************************************
484 MSVCRT_long CDECL
MSVCRT_strtol(const char* nptr
, char** end
, int base
)
486 /* wrapper to forward libc error code to msvcrt's error codes */
490 ret
= strtol(nptr
, end
, base
);
493 case ERANGE
: *MSVCRT__errno() = MSVCRT_ERANGE
; break;
494 case EINVAL
: *MSVCRT__errno() = MSVCRT_EINVAL
; break;
496 /* cope with the fact that we may use 64bit long integers on libc
497 * while msvcrt always uses 32bit long integers
499 if (ret
> MSVCRT_LONG_MAX
)
501 ret
= MSVCRT_LONG_MAX
;
502 *MSVCRT__errno() = MSVCRT_ERANGE
;
504 else if (ret
< -MSVCRT_LONG_MAX
- 1)
506 ret
= -MSVCRT_LONG_MAX
- 1;
507 *MSVCRT__errno() = MSVCRT_ERANGE
;
515 /******************************************************************
518 MSVCRT_ulong CDECL
MSVCRT_strtoul(const char* nptr
, char** end
, int base
)
520 /* wrapper to forward libc error code to msvcrt's error codes */
524 ret
= strtoul(nptr
, end
, base
);
527 case ERANGE
: *MSVCRT__errno() = MSVCRT_ERANGE
; break;
528 case EINVAL
: *MSVCRT__errno() = MSVCRT_EINVAL
; break;
530 /* cope with the fact that we may use 64bit long integers on libc
531 * while msvcrt always uses 32bit long integers
533 if (ret
> MSVCRT_ULONG_MAX
)
535 ret
= MSVCRT_ULONG_MAX
;
536 *MSVCRT__errno() = MSVCRT_ERANGE
;
544 /******************************************************************
547 MSVCRT_size_t CDECL
MSVCRT_strnlen(const char *s
, MSVCRT_size_t maxlen
)
551 for(i
=0; i
<maxlen
; i
++)
557 /*********************************************************************
558 * _strtoi64_l (MSVCRT.@)
560 * FIXME: locale parameter is ignored
562 __int64 CDECL
MSVCRT_strtoi64_l(const char *nptr
, char **endptr
, int base
, MSVCRT__locale_t locale
)
564 BOOL negative
= FALSE
;
567 TRACE("(%s %p %d %p)\n", nptr
, endptr
, base
, locale
);
569 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
) || !MSVCRT_CHECK_PMT(base
== 0 || base
>= 2) ||
570 !MSVCRT_CHECK_PMT(base
<= 36)) {
574 while(isspace(*nptr
)) nptr
++;
579 } else if(*nptr
== '+')
582 if((base
==0 || base
==16) && *nptr
=='0' && tolower(*(nptr
+1))=='x') {
595 char cur
= tolower(*nptr
);
603 if(cur
<'a' || cur
>='a'+base
-10)
613 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
614 ret
= MSVCRT_I64_MAX
;
615 *MSVCRT__errno() = MSVCRT_ERANGE
;
616 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
617 ret
= MSVCRT_I64_MIN
;
618 *MSVCRT__errno() = MSVCRT_ERANGE
;
624 *endptr
= (char*)nptr
;
629 /*********************************************************************
630 * _strtoi64 (MSVCRT.@)
632 __int64 CDECL
MSVCRT_strtoi64(const char *nptr
, char **endptr
, int base
)
634 return MSVCRT_strtoi64_l(nptr
, endptr
, base
, NULL
);
637 /*********************************************************************
638 * _strtoui64_l (MSVCRT.@)
640 * FIXME: locale parameter is ignored
642 unsigned __int64 CDECL
MSVCRT_strtoui64_l(const char *nptr
, char **endptr
, int base
, MSVCRT__locale_t locale
)
644 BOOL negative
= FALSE
;
645 unsigned __int64 ret
= 0;
647 TRACE("(%s %p %d %p)\n", nptr
, endptr
, base
, locale
);
649 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
) || !MSVCRT_CHECK_PMT(base
== 0 || base
>= 2) ||
650 !MSVCRT_CHECK_PMT(base
<= 36)) {
654 while(isspace(*nptr
)) nptr
++;
659 } else if(*nptr
== '+')
662 if((base
==0 || base
==16) && *nptr
=='0' && tolower(*(nptr
+1))=='x') {
675 char cur
= tolower(*nptr
);
683 if(cur
<'a' || cur
>='a'+base
-10)
690 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
691 ret
= MSVCRT_UI64_MAX
;
692 *MSVCRT__errno() = MSVCRT_ERANGE
;
698 *endptr
= (char*)nptr
;
700 return negative
? -ret
: ret
;
703 /*********************************************************************
704 * _strtoui64 (MSVCRT.@)
706 unsigned __int64 CDECL
MSVCRT_strtoui64(const char *nptr
, char **endptr
, int base
)
708 return MSVCRT_strtoui64_l(nptr
, endptr
, base
, NULL
);
711 /*********************************************************************
714 int CDECL
_ltoa_s(MSVCRT_long value
, char *str
, MSVCRT_size_t size
, int radix
)
719 char buffer
[33], *pos
;
722 if (!MSVCRT_CHECK_PMT(str
!= NULL
) || !MSVCRT_CHECK_PMT(size
> 0) ||
723 !MSVCRT_CHECK_PMT(radix
>= 2) || !MSVCRT_CHECK_PMT(radix
<= 36))
728 *MSVCRT__errno() = MSVCRT_EINVAL
;
729 return MSVCRT_EINVAL
;
732 if (value
< 0 && radix
== 10)
752 *--pos
= '0' + digit
;
754 *--pos
= 'a' + digit
- 10;
761 len
= buffer
+ 33 - pos
;
767 /* Copy the temporary buffer backwards up to the available number of
768 * characters. Don't copy the negative sign if present. */
776 for (pos
= buffer
+ 31, i
= 0; i
< size
; i
++)
780 MSVCRT_INVALID_PMT("str[size] is too small");
781 *MSVCRT__errno() = MSVCRT_ERANGE
;
782 return MSVCRT_ERANGE
;
785 memcpy(str
, pos
, len
);
789 /*********************************************************************
792 int CDECL
_ltow_s(MSVCRT_long value
, MSVCRT_wchar_t
*str
, MSVCRT_size_t size
, int radix
)
797 MSVCRT_wchar_t buffer
[33], *pos
;
800 if (!MSVCRT_CHECK_PMT(str
!= NULL
) || !MSVCRT_CHECK_PMT(size
> 0) ||
801 !MSVCRT_CHECK_PMT(radix
>= 2) || !MSVCRT_CHECK_PMT(radix
<= 36))
806 *MSVCRT__errno() = MSVCRT_EINVAL
;
807 return MSVCRT_EINVAL
;
810 if (value
< 0 && radix
== 10)
830 *--pos
= '0' + digit
;
832 *--pos
= 'a' + digit
- 10;
839 len
= buffer
+ 33 - pos
;
843 MSVCRT_wchar_t
*p
= str
;
845 /* Copy the temporary buffer backwards up to the available number of
846 * characters. Don't copy the negative sign if present. */
854 for (pos
= buffer
+ 31, i
= 0; i
< size
; i
++)
857 MSVCRT_INVALID_PMT("str[size] is too small");
859 *MSVCRT__errno() = MSVCRT_ERANGE
;
860 return MSVCRT_ERANGE
;
863 memcpy(str
, pos
, len
* sizeof(MSVCRT_wchar_t
));
867 /*********************************************************************
870 int CDECL
_itoa_s(int value
, char *str
, MSVCRT_size_t size
, int radix
)
872 return _ltoa_s(value
, str
, size
, radix
);
875 /*********************************************************************
878 int CDECL
_itow_s(int value
, MSVCRT_wchar_t
*str
, MSVCRT_size_t size
, int radix
)
880 return _ltow_s(value
, str
, size
, radix
);
883 /*********************************************************************
884 * _ui64toa_s (MSVCRT.@)
886 int CDECL
MSVCRT__ui64toa_s(unsigned __int64 value
, char *str
,
887 MSVCRT_size_t size
, int radix
)
889 char buffer
[65], *pos
;
892 if (!MSVCRT_CHECK_PMT(str
!= NULL
) || !MSVCRT_CHECK_PMT(size
> 0) ||
893 !MSVCRT_CHECK_PMT(radix
>=2) || !MSVCRT_CHECK_PMT(radix
<=36)) {
894 *MSVCRT__errno() = MSVCRT_EINVAL
;
895 return MSVCRT_EINVAL
;
908 *--pos
= 'a'+digit
-10;
911 if(buffer
-pos
+65 > size
) {
912 MSVCRT_INVALID_PMT("str[size] is too small");
913 *MSVCRT__errno() = MSVCRT_EINVAL
;
914 return MSVCRT_EINVAL
;
917 memcpy(str
, pos
, buffer
-pos
+65);
921 /*********************************************************************
922 * _ui64tow_s (MSVCRT.@)
924 int CDECL
MSVCRT__ui64tow_s( unsigned __int64 value
, MSVCRT_wchar_t
*str
,
925 MSVCRT_size_t size
, int radix
)
927 MSVCRT_wchar_t buffer
[65], *pos
;
930 if (!MSVCRT_CHECK_PMT(str
!= NULL
) || !MSVCRT_CHECK_PMT(size
> 0) ||
931 !MSVCRT_CHECK_PMT(radix
>=2) || !MSVCRT_CHECK_PMT(radix
<=36)) {
932 *MSVCRT__errno() = MSVCRT_EINVAL
;
933 return MSVCRT_EINVAL
;
940 digit
= value
% radix
;
941 value
= value
/ radix
;
943 *--pos
= '0' + digit
;
945 *--pos
= 'a' + digit
- 10;
946 } while (value
!= 0);
948 if(buffer
-pos
+65 > size
) {
949 MSVCRT_INVALID_PMT("str[size] is too small");
950 *MSVCRT__errno() = MSVCRT_EINVAL
;
951 return MSVCRT_EINVAL
;
954 memcpy(str
, pos
, buffer
-pos
+65);
958 /*********************************************************************
959 * _ultoa_s (MSVCRT.@)
961 int CDECL
_ultoa_s(MSVCRT_ulong value
, char *str
, MSVCRT_size_t size
, int radix
)
964 char buffer
[33], *pos
;
967 if (!str
|| !size
|| radix
< 2 || radix
> 36)
972 *MSVCRT__errno() = MSVCRT_EINVAL
;
973 return MSVCRT_EINVAL
;
981 digit
= value
% radix
;
985 *--pos
= '0' + digit
;
987 *--pos
= 'a' + digit
- 10;
991 len
= buffer
+ 33 - pos
;
997 /* Copy the temporary buffer backwards up to the available number of
1000 for (pos
= buffer
+ 31, i
= 0; i
< size
; i
++)
1004 *MSVCRT__errno() = MSVCRT_ERANGE
;
1005 return MSVCRT_ERANGE
;
1008 memcpy(str
, pos
, len
);
1012 /*********************************************************************
1013 * _i64toa_s (MSVCRT.@)
1015 int CDECL
_i64toa_s(__int64 value
, char *str
, MSVCRT_size_t size
, int radix
)
1017 unsigned __int64 val
;
1020 char buffer
[65], *pos
;
1023 if (!MSVCRT_CHECK_PMT(str
!= NULL
) || !MSVCRT_CHECK_PMT(size
> 0) ||
1024 !MSVCRT_CHECK_PMT(radix
>= 2) || !MSVCRT_CHECK_PMT(radix
<= 36))
1029 *MSVCRT__errno() = MSVCRT_EINVAL
;
1030 return MSVCRT_EINVAL
;
1033 if (value
< 0 && radix
== 10)
1049 digit
= val
% radix
;
1053 *--pos
= '0' + digit
;
1055 *--pos
= 'a' + digit
- 10;
1062 len
= buffer
+ 65 - pos
;
1068 /* Copy the temporary buffer backwards up to the available number of
1069 * characters. Don't copy the negative sign if present. */
1077 for (pos
= buffer
+ 63, i
= 0; i
< size
; i
++)
1081 MSVCRT_INVALID_PMT("str[size] is too small");
1082 *MSVCRT__errno() = MSVCRT_ERANGE
;
1083 return MSVCRT_ERANGE
;
1086 memcpy(str
, pos
, len
);
1090 /*********************************************************************
1091 * _i64tow_s (MSVCRT.@)
1093 int CDECL
_i64tow_s(__int64 value
, MSVCRT_wchar_t
*str
, MSVCRT_size_t size
, int radix
)
1095 unsigned __int64 val
;
1098 MSVCRT_wchar_t buffer
[65], *pos
;
1101 if (!MSVCRT_CHECK_PMT(str
!= NULL
) || !MSVCRT_CHECK_PMT(size
> 0) ||
1102 !MSVCRT_CHECK_PMT(radix
>= 2) || !MSVCRT_CHECK_PMT(radix
<= 36))
1107 *MSVCRT__errno() = MSVCRT_EINVAL
;
1108 return MSVCRT_EINVAL
;
1111 if (value
< 0 && radix
== 10)
1127 digit
= val
% radix
;
1131 *--pos
= '0' + digit
;
1133 *--pos
= 'a' + digit
- 10;
1140 len
= buffer
+ 65 - pos
;
1144 MSVCRT_wchar_t
*p
= str
;
1146 /* Copy the temporary buffer backwards up to the available number of
1147 * characters. Don't copy the negative sign if present. */
1155 for (pos
= buffer
+ 63, i
= 0; i
< size
; i
++)
1158 MSVCRT_INVALID_PMT("str[size] is too small");
1160 *MSVCRT__errno() = MSVCRT_ERANGE
;
1161 return MSVCRT_ERANGE
;
1164 memcpy(str
, pos
, len
* sizeof(MSVCRT_wchar_t
));
1168 #define I10_OUTPUT_MAX_PREC 21
1169 /* Internal structure used by $I10_OUTPUT */
1170 struct _I10_OUTPUT_DATA
{
1174 char str
[I10_OUTPUT_MAX_PREC
+1]; /* add space for '\0' */
1177 /*********************************************************************
1178 * $I10_OUTPUT (MSVCRT.@)
1179 * ld - long double to be printed to data
1180 * prec - precision of part, we're interested in
1181 * flag - 0 for first prec digits, 1 for fractional part
1182 * data - data to be populated
1185 * 0 if given double is NaN or INF
1189 * Native sets last byte of data->str to '0' or '9', I don't know what
1190 * it means. Current implementation sets it always to '0'.
1192 int CDECL
MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld
, int prec
, int flag
, struct _I10_OUTPUT_DATA
*data
)
1194 static const char inf_str
[] = "1#INF";
1195 static const char nan_str
[] = "1#QNAN";
1199 char buf
[I10_OUTPUT_MAX_PREC
+9]; /* 9 = strlen("0.e+0000") + '\0' */
1202 TRACE("(%lf %d %x %p)\n", d
, prec
, flag
, data
);
1213 memcpy(data
->str
, inf_str
, sizeof(inf_str
));
1221 memcpy(data
->str
, nan_str
, sizeof(nan_str
));
1227 int exp
= 1+floor(log10(d
));
1235 if(prec
+1 > I10_OUTPUT_MAX_PREC
)
1236 prec
= I10_OUTPUT_MAX_PREC
-1;
1242 sprintf(format
, "%%.%dle", prec
);
1243 sprintf(buf
, format
, d
);
1246 data
->pos
= atoi(buf
+prec
+3);
1250 for(p
= buf
+prec
+1; p
>buf
+1 && *p
=='0'; p
--);
1253 memcpy(data
->str
, buf
+1, data
->len
);
1254 data
->str
[data
->len
] = '\0';
1256 if(buf
[1]!='0' && prec
-data
->len
+1>0)
1257 memcpy(data
->str
+data
->len
+1, buf
+data
->len
+1, prec
-data
->len
+1);
1261 #undef I10_OUTPUT_MAX_PREC