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 /*********************************************************************
336 * _atoflt_l (MSVCRT.@)
338 int CDECL MSVCRT__atoflt_l( MSVCRT__CRT_FLOAT *value, char *str, MSVCRT__locale_t locale)
340 unsigned __int64 d=0, hlp;
345 BOOL found_digit = FALSE;
348 locale = get_locale();
350 /* FIXME: use *_l functions */
363 hlp = d*10+*(p++)-'0';
364 if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
375 if(*p == *locale->locinfo->lconv->decimal_point)
380 hlp = d*10+*(p++)-'0';
381 if(d>MSVCRT_UI64_MAX/10 || hlp<d)
395 if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
407 if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
413 if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
414 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
417 if(*p=='-' || *p=='+')
423 fpcontrol = _control87(0, 0);
424 _control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
425 |MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
428 value->f = (float)sign*d*powf(10, exp);
430 value->f = (float)sign*d/powf(10, -exp);
432 _control87(fpcontrol, 0xffffffff);
434 if((d && value->f==0.0) || isinf(value->f))
435 ret = exp > 0 ? MSVCRT__OVERFLOW : MSVCRT__UNDERFLOW;
440 /*********************************************************************
443 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
445 /* FIXME: handle Windows locale */
446 return strcoll( str1, str2 );
449 /*********************************************************************
450 * strcpy_s (MSVCRT.@)
452 int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
455 if(!elem) return MSVCRT_EINVAL;
456 if(!dst) return MSVCRT_EINVAL;
460 return MSVCRT_EINVAL;
463 for(i = 0; i < elem; i++)
465 if((dst[i] = src[i]) == '\0') return 0;
468 return MSVCRT_ERANGE;
471 /*********************************************************************
472 * strcat_s (MSVCRT.@)
474 int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
477 if(!dst) return MSVCRT_EINVAL;
478 if(elem == 0) return MSVCRT_EINVAL;
482 return MSVCRT_EINVAL;
485 for(i = 0; i < elem; i++)
489 for(j = 0; (j + i) < elem; j++)
491 if((dst[j + i] = src[j]) == '\0') return 0;
495 /* Set the first element to 0, not the first element after the skipped part */
497 return MSVCRT_ERANGE;
500 /*********************************************************************
501 * strncat_s (MSVCRT.@)
503 int CDECL MSVCRT_strncat_s( char* dst, MSVCRT_size_t elem, const char* src, MSVCRT_size_t count )
506 if(!MSVCRT_CHECK_PMT(dst != 0) || !MSVCRT_CHECK_PMT(elem != 0))
507 return MSVCRT_EINVAL;
508 if(!MSVCRT_CHECK_PMT(src != 0))
511 return MSVCRT_EINVAL;
514 for(i = 0; i < elem; i++)
518 for(j = 0; (j + i) < elem; j++)
520 if(count == MSVCRT__TRUNCATE && j + i == elem - 1)
523 return MSVCRT_STRUNCATE;
525 if(j == count || (dst[j + i] = src[j]) == '\0')
533 /* Set the first element to 0, not the first element after the skipped part */
535 return MSVCRT_ERANGE;
538 /*********************************************************************
541 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
543 /* FIXME: handle Windows locale */
544 return strxfrm( dest, src, len );
547 /*********************************************************************
548 * _stricoll (MSVCRT.@)
550 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
552 /* FIXME: handle collates */
553 TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
554 return lstrcmpiA( str1, str2 );
557 /********************************************************************
558 * _atoldbl (MSVCRT.@)
560 int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
562 /* FIXME needs error checking for huge/small values */
564 TRACE("str %s value %p\n",str,value);
565 value->x = strtold(str,0);
567 FIXME("stub, str %s value %p\n",str,value);
572 /********************************************************************
573 * __STRINGTOLD (MSVCRT.@)
575 int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
578 FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
579 value->x = strtold(str,endptr);
581 FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
586 /******************************************************************
589 MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
591 /* wrapper to forward libc error code to msvcrt's error codes */
595 ret = strtol(nptr, end, base);
598 case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
599 case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
601 /* cope with the fact that we may use 64bit long integers on libc
602 * while msvcrt always uses 32bit long integers
604 if (ret > MSVCRT_LONG_MAX)
606 ret = MSVCRT_LONG_MAX;
607 *MSVCRT__errno() = MSVCRT_ERANGE;
609 else if (ret < -MSVCRT_LONG_MAX - 1)
611 ret = -MSVCRT_LONG_MAX - 1;
612 *MSVCRT__errno() = MSVCRT_ERANGE;
620 /******************************************************************
623 MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
625 /* wrapper to forward libc error code to msvcrt's error codes */
629 ret = strtoul(nptr, end, base);
632 case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
633 case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
635 /* cope with the fact that we may use 64bit long integers on libc
636 * while msvcrt always uses 32bit long integers
638 if (ret > MSVCRT_ULONG_MAX)
640 ret = MSVCRT_ULONG_MAX;
641 *MSVCRT__errno() = MSVCRT_ERANGE;
649 /******************************************************************
652 MSVCRT_size_t CDECL MSVCRT_strnlen(const char *s, MSVCRT_size_t maxlen)
656 for(i=0; i<maxlen; i++)
662 /*********************************************************************
663 * _strtoi64_l (MSVCRT.@)
665 * FIXME: locale parameter is ignored
667 __int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
669 BOOL negative = FALSE;
672 TRACE("(%s %p %d %p)\n", nptr, endptr, base, locale);
674 if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
675 !MSVCRT_CHECK_PMT(base <= 36)) {
679 while(isspace(*nptr)) nptr++;
684 } else if(*nptr == '+')
687 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
700 char cur = tolower(*nptr);
708 if(cur<'a' || cur>='a'+base-10)
718 if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
719 ret = MSVCRT_I64_MAX;
720 *MSVCRT__errno() = MSVCRT_ERANGE;
721 } else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
722 ret = MSVCRT_I64_MIN;
723 *MSVCRT__errno() = MSVCRT_ERANGE;
729 *endptr = (char*)nptr;
734 /*********************************************************************
735 * _strtoi64 (MSVCRT.@)
737 __int64 CDECL MSVCRT_strtoi64(const char *nptr, char **endptr, int base)
739 return MSVCRT_strtoi64_l(nptr, endptr, base, NULL);
742 /*********************************************************************
743 * _strtoui64_l (MSVCRT.@)
745 * FIXME: locale parameter is ignored
747 unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
749 BOOL negative = FALSE;
750 unsigned __int64 ret = 0;
752 TRACE("(%s %p %d %p)\n", nptr, endptr, base, locale);
754 if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
755 !MSVCRT_CHECK_PMT(base <= 36)) {
759 while(isspace(*nptr)) nptr++;
764 } else if(*nptr == '+')
767 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
780 char cur = tolower(*nptr);
788 if(cur<'a' || cur>='a'+base-10)
795 if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
796 ret = MSVCRT_UI64_MAX;
797 *MSVCRT__errno() = MSVCRT_ERANGE;
803 *endptr = (char*)nptr;
805 return negative ? -ret : ret;
808 /*********************************************************************
809 * _strtoui64 (MSVCRT.@)
811 unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int base)
813 return MSVCRT_strtoui64_l(nptr, endptr, base, NULL);
816 /*********************************************************************
819 int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
824 char buffer[33], *pos;
827 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
828 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
833 *MSVCRT__errno() = MSVCRT_EINVAL;
834 return MSVCRT_EINVAL;
837 if (value < 0 && radix == 10)
857 *--pos = '0' + digit;
859 *--pos = 'a' + digit - 10;
866 len = buffer + 33 - pos;
872 /* Copy the temporary buffer backwards up to the available number of
873 * characters. Don't copy the negative sign if present. */
881 for (pos = buffer + 31, i = 0; i < size; i++)
885 MSVCRT_INVALID_PMT("str[size] is too small");
886 *MSVCRT__errno() = MSVCRT_ERANGE;
887 return MSVCRT_ERANGE;
890 memcpy(str, pos, len);
894 /*********************************************************************
897 int CDECL _ltow_s(MSVCRT_long value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
902 MSVCRT_wchar_t buffer[33], *pos;
905 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
906 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
911 *MSVCRT__errno() = MSVCRT_EINVAL;
912 return MSVCRT_EINVAL;
915 if (value < 0 && radix == 10)
935 *--pos = '0' + digit;
937 *--pos = 'a' + digit - 10;
944 len = buffer + 33 - pos;
948 MSVCRT_wchar_t *p = str;
950 /* Copy the temporary buffer backwards up to the available number of
951 * characters. Don't copy the negative sign if present. */
959 for (pos = buffer + 31, i = 0; i < size; i++)
962 MSVCRT_INVALID_PMT("str[size] is too small");
964 *MSVCRT__errno() = MSVCRT_ERANGE;
965 return MSVCRT_ERANGE;
968 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
972 /*********************************************************************
975 int CDECL _itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
977 return _ltoa_s(value, str, size, radix);
980 /*********************************************************************
983 int CDECL _itow_s(int value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
985 return _ltow_s(value, str, size, radix);
988 /*********************************************************************
989 * _ui64toa_s (MSVCRT.@)
991 int CDECL MSVCRT__ui64toa_s(unsigned __int64 value, char *str,
992 MSVCRT_size_t size, int radix)
994 char buffer[65], *pos;
997 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
998 !MSVCRT_CHECK_PMT(radix>=2) || !MSVCRT_CHECK_PMT(radix<=36)) {
999 *MSVCRT__errno() = MSVCRT_EINVAL;
1000 return MSVCRT_EINVAL;
1007 digit = value%radix;
1013 *--pos = 'a'+digit-10;
1016 if(buffer-pos+65 > size) {
1017 MSVCRT_INVALID_PMT("str[size] is too small");
1018 *MSVCRT__errno() = MSVCRT_EINVAL;
1019 return MSVCRT_EINVAL;
1022 memcpy(str, pos, buffer-pos+65);
1026 /*********************************************************************
1027 * _ui64tow_s (MSVCRT.@)
1029 int CDECL MSVCRT__ui64tow_s( unsigned __int64 value, MSVCRT_wchar_t *str,
1030 MSVCRT_size_t size, int radix )
1032 MSVCRT_wchar_t buffer[65], *pos;
1035 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1036 !MSVCRT_CHECK_PMT(radix>=2) || !MSVCRT_CHECK_PMT(radix<=36)) {
1037 *MSVCRT__errno() = MSVCRT_EINVAL;
1038 return MSVCRT_EINVAL;
1045 digit = value % radix;
1046 value = value / radix;
1048 *--pos = '0' + digit;
1050 *--pos = 'a' + digit - 10;
1051 } while (value != 0);
1053 if(buffer-pos+65 > size) {
1054 MSVCRT_INVALID_PMT("str[size] is too small");
1055 *MSVCRT__errno() = MSVCRT_EINVAL;
1056 return MSVCRT_EINVAL;
1059 memcpy(str, pos, buffer-pos+65);
1063 /*********************************************************************
1064 * _ultoa_s (MSVCRT.@)
1066 int CDECL _ultoa_s(MSVCRT_ulong value, char *str, MSVCRT_size_t size, int radix)
1069 char buffer[33], *pos;
1072 if (!str || !size || radix < 2 || radix > 36)
1077 *MSVCRT__errno() = MSVCRT_EINVAL;
1078 return MSVCRT_EINVAL;
1086 digit = value % radix;
1090 *--pos = '0' + digit;
1092 *--pos = 'a' + digit - 10;
1096 len = buffer + 33 - pos;
1102 /* Copy the temporary buffer backwards up to the available number of
1105 for (pos = buffer + 31, i = 0; i < size; i++)
1109 *MSVCRT__errno() = MSVCRT_ERANGE;
1110 return MSVCRT_ERANGE;
1113 memcpy(str, pos, len);
1117 /*********************************************************************
1118 * _i64toa_s (MSVCRT.@)
1120 int CDECL _i64toa_s(__int64 value, char *str, MSVCRT_size_t size, int radix)
1122 unsigned __int64 val;
1125 char buffer[65], *pos;
1128 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1129 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
1134 *MSVCRT__errno() = MSVCRT_EINVAL;
1135 return MSVCRT_EINVAL;
1138 if (value < 0 && radix == 10)
1154 digit = val % radix;
1158 *--pos = '0' + digit;
1160 *--pos = 'a' + digit - 10;
1167 len = buffer + 65 - pos;
1173 /* Copy the temporary buffer backwards up to the available number of
1174 * characters. Don't copy the negative sign if present. */
1182 for (pos = buffer + 63, i = 0; i < size; i++)
1186 MSVCRT_INVALID_PMT("str[size] is too small");
1187 *MSVCRT__errno() = MSVCRT_ERANGE;
1188 return MSVCRT_ERANGE;
1191 memcpy(str, pos, len);
1195 /*********************************************************************
1196 * _i64tow_s (MSVCRT.@)
1198 int CDECL _i64tow_s(__int64 value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1200 unsigned __int64 val;
1203 MSVCRT_wchar_t buffer[65], *pos;
1206 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1207 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
1212 *MSVCRT__errno() = MSVCRT_EINVAL;
1213 return MSVCRT_EINVAL;
1216 if (value < 0 && radix == 10)
1232 digit = val % radix;
1236 *--pos = '0' + digit;
1238 *--pos = 'a' + digit - 10;
1245 len = buffer + 65 - pos;
1249 MSVCRT_wchar_t *p = str;
1251 /* Copy the temporary buffer backwards up to the available number of
1252 * characters. Don't copy the negative sign if present. */
1260 for (pos = buffer + 63, i = 0; i < size; i++)
1263 MSVCRT_INVALID_PMT("str[size] is too small");
1265 *MSVCRT__errno() = MSVCRT_ERANGE;
1266 return MSVCRT_ERANGE;
1269 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
1273 #define I10_OUTPUT_MAX_PREC 21
1274 /* Internal structure used by $I10_OUTPUT */
1275 struct _I10_OUTPUT_DATA {
1279 char str[I10_OUTPUT_MAX_PREC+1]; /* add space for '\0' */
1282 /*********************************************************************
1283 * $I10_OUTPUT (MSVCRT.@)
1284 * ld - long double to be printed to data
1285 * prec - precision of part, we're interested in
1286 * flag - 0 for first prec digits, 1 for fractional part
1287 * data - data to be populated
1290 * 0 if given double is NaN or INF
1294 * Native sets last byte of data->str to '0' or '9', I don't know what
1295 * it means. Current implementation sets it always to '0'.
1297 int CDECL MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld, int prec, int flag, struct _I10_OUTPUT_DATA *data)
1299 static const char inf_str[] = "1#INF";
1300 static const char nan_str[] = "1#QNAN";
1304 char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
1307 TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
1318 memcpy(data->str, inf_str, sizeof(inf_str));
1326 memcpy(data->str, nan_str, sizeof(nan_str));
1332 int exp = 1+floor(log10(d));
1340 if(prec+1 > I10_OUTPUT_MAX_PREC)
1341 prec = I10_OUTPUT_MAX_PREC-1;
1347 sprintf(format, "%%.%dle", prec);
1348 sprintf(buf, format, d);
1351 data->pos = atoi(buf+prec+3);
1355 for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
1358 memcpy(data->str, buf+1, data->len);
1359 data->str[data->len] = '\0';
1361 if(buf[1]!='0' && prec-data->len+1>0)
1362 memcpy(data->str+data->len+1, buf+data->len+1, prec-data->len+1);
1366 #undef I10_OUTPUT_MAX_PREC