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_l (MSVCRT.@)
56 int CDECL _strlwr_s_l(char *str, MSVCRT_size_t len, MSVCRT__locale_t locale)
61 locale = get_locale();
65 *MSVCRT__errno() = MSVCRT_EINVAL;
78 *MSVCRT__errno() = MSVCRT_EINVAL;
84 *str = MSVCRT__tolower_l(*str, locale);
91 /*********************************************************************
92 * _strlwr_s (MSVCRT.@)
94 int CDECL _strlwr_s(char *str, MSVCRT_size_t len)
96 return _strlwr_s_l(str, len, NULL);
99 /*********************************************************************
100 * _strlwr_l (MSVCRT.@)
102 int CDECL _strlwr_l(char *str, MSVCRT__locale_t locale)
104 return _strlwr_s_l(str, -1, locale);
107 /*********************************************************************
110 int CDECL _strlwr(char *str)
112 return _strlwr_s_l(str, -1, NULL);
115 /*********************************************************************
116 * _strnset (MSVCRT.@)
118 char* CDECL MSVCRT__strnset(char* str, int value, MSVCRT_size_t len)
121 while (*str && len--)
126 /*********************************************************************
129 char* CDECL _strrev(char* str)
135 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
145 /*********************************************************************
148 char* CDECL _strset(char* str, int value)
157 /*********************************************************************
160 char * CDECL MSVCRT_strtok( char *str, const char *delim )
162 thread_data_t *data = msvcrt_get_thread_data();
166 if (!(str = data->strtok_next)) return NULL;
168 while (*str && strchr( delim, *str )) str++;
169 if (!*str) return NULL;
171 while (*str && !strchr( delim, *str )) str++;
172 if (*str) *str++ = 0;
173 data->strtok_next = str;
177 /*********************************************************************
178 * strtok_s (MSVCRT.@)
180 char * CDECL MSVCRT_strtok_s(char *str, const char *delim, char **ctx)
182 if (!MSVCRT_CHECK_PMT(delim != NULL) || !MSVCRT_CHECK_PMT(ctx != NULL) ||
183 !MSVCRT_CHECK_PMT(str != NULL || *ctx != NULL)) {
184 *MSVCRT__errno() = MSVCRT_EINVAL;
191 while(*str && strchr(delim, *str))
197 while(**ctx && !strchr(delim, **ctx))
205 /*********************************************************************
208 void CDECL MSVCRT__swab(char* src, char* dst, int len)
212 len = (unsigned)len >> 1;
224 /*********************************************************************
225 * strtod_l (MSVCRT.@)
227 double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t locale)
229 unsigned __int64 d=0, hlp;
234 BOOL found_digit = FALSE;
236 if (!MSVCRT_CHECK_PMT(str != NULL)) {
237 *MSVCRT__errno() = MSVCRT_EINVAL;
242 locale = get_locale();
244 /* FIXME: use *_l functions */
257 hlp = d*10+*(p++)-'0';
258 if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
269 if(*p == *locale->locinfo->lconv->decimal_point)
274 hlp = d*10+*(p++)-'0';
275 if(d>MSVCRT_UI64_MAX/10 || hlp<d)
290 if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
302 if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
308 if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
309 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
312 if(*p=='-' || *p=='+')
318 fpcontrol = _control87(0, 0);
319 _control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
320 |MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
323 ret = (double)sign*d*pow(10, exp);
325 ret = (double)sign*d/pow(10, -exp);
327 _control87(fpcontrol, 0xffffffff);
329 if((d && ret==0.0) || isinf(ret))
330 *MSVCRT__errno() = MSVCRT_ERANGE;
338 /*********************************************************************
341 double CDECL MSVCRT_strtod( const char *str, char **end )
343 return MSVCRT_strtod_l( str, end, NULL );
346 /*********************************************************************
349 double CDECL MSVCRT_atof( const char *str )
351 return MSVCRT_strtod_l(str, NULL, NULL);
354 /*********************************************************************
357 double CDECL MSVCRT__atof_l( const char *str, MSVCRT__locale_t locale)
359 return MSVCRT_strtod_l(str, NULL, locale);
362 /*********************************************************************
363 * _atoflt_l (MSVCRT.@)
365 int CDECL MSVCRT__atoflt_l( MSVCRT__CRT_FLOAT *value, char *str, MSVCRT__locale_t locale)
367 unsigned __int64 d=0, hlp;
372 BOOL found_digit = FALSE;
375 locale = get_locale();
377 /* FIXME: use *_l functions */
390 hlp = d*10+*(p++)-'0';
391 if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
402 if(*p == *locale->locinfo->lconv->decimal_point)
407 hlp = d*10+*(p++)-'0';
408 if(d>MSVCRT_UI64_MAX/10 || hlp<d)
422 if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
434 if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
440 if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
441 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
444 if(*p=='-' || *p=='+')
450 fpcontrol = _control87(0, 0);
451 _control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
452 |MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
455 value->f = (float)sign*d*powf(10, exp);
457 value->f = (float)sign*d/powf(10, -exp);
459 _control87(fpcontrol, 0xffffffff);
461 if((d && value->f==0.0) || isinf(value->f))
462 ret = exp > 0 ? MSVCRT__OVERFLOW : MSVCRT__UNDERFLOW;
467 /*********************************************************************
470 int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
472 /* FIXME: handle Windows locale */
473 return strcoll( str1, str2 );
476 /*********************************************************************
477 * strcpy_s (MSVCRT.@)
479 int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
482 if(!elem) return MSVCRT_EINVAL;
483 if(!dst) return MSVCRT_EINVAL;
487 return MSVCRT_EINVAL;
490 for(i = 0; i < elem; i++)
492 if((dst[i] = src[i]) == '\0') return 0;
495 return MSVCRT_ERANGE;
498 /*********************************************************************
499 * strcat_s (MSVCRT.@)
501 int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
504 if(!dst) return MSVCRT_EINVAL;
505 if(elem == 0) return MSVCRT_EINVAL;
509 return MSVCRT_EINVAL;
512 for(i = 0; i < elem; i++)
516 for(j = 0; (j + i) < elem; j++)
518 if((dst[j + i] = src[j]) == '\0') return 0;
522 /* Set the first element to 0, not the first element after the skipped part */
524 return MSVCRT_ERANGE;
527 /*********************************************************************
528 * strncat_s (MSVCRT.@)
530 int CDECL MSVCRT_strncat_s( char* dst, MSVCRT_size_t elem, const char* src, MSVCRT_size_t count )
533 if(!MSVCRT_CHECK_PMT(dst != 0) || !MSVCRT_CHECK_PMT(elem != 0))
534 return MSVCRT_EINVAL;
535 if(!MSVCRT_CHECK_PMT(src != 0))
538 return MSVCRT_EINVAL;
541 for(i = 0; i < elem; i++)
545 for(j = 0; (j + i) < elem; j++)
547 if(count == MSVCRT__TRUNCATE && j + i == elem - 1)
550 return MSVCRT_STRUNCATE;
552 if(j == count || (dst[j + i] = src[j]) == '\0')
560 /* Set the first element to 0, not the first element after the skipped part */
562 return MSVCRT_ERANGE;
565 /*********************************************************************
568 MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
570 /* FIXME: handle Windows locale */
571 return strxfrm( dest, src, len );
574 /*********************************************************************
575 * _stricoll (MSVCRT.@)
577 int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
579 /* FIXME: handle collates */
580 TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
581 return lstrcmpiA( str1, str2 );
584 /********************************************************************
585 * _atoldbl (MSVCRT.@)
587 int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
589 /* FIXME needs error checking for huge/small values */
592 TRACE("str %s value %p\n",str,value);
594 memcpy(value, &ld, 10);
596 FIXME("stub, str %s value %p\n",str,value);
601 /********************************************************************
602 * __STRINGTOLD (MSVCRT.@)
604 int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
608 FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
610 memcpy(value, &ld, 10);
612 FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
617 /******************************************************************
620 MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
622 /* wrapper to forward libc error code to msvcrt's error codes */
626 ret = strtol(nptr, end, base);
629 case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
630 case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
632 /* cope with the fact that we may use 64bit long integers on libc
633 * while msvcrt always uses 32bit long integers
635 if (ret > MSVCRT_LONG_MAX)
637 ret = MSVCRT_LONG_MAX;
638 *MSVCRT__errno() = MSVCRT_ERANGE;
640 else if (ret < -MSVCRT_LONG_MAX - 1)
642 ret = -MSVCRT_LONG_MAX - 1;
643 *MSVCRT__errno() = MSVCRT_ERANGE;
651 /******************************************************************
654 MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
656 /* wrapper to forward libc error code to msvcrt's error codes */
660 ret = strtoul(nptr, end, base);
663 case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
664 case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
666 /* cope with the fact that we may use 64bit long integers on libc
667 * while msvcrt always uses 32bit long integers
669 if (ret > MSVCRT_ULONG_MAX)
671 ret = MSVCRT_ULONG_MAX;
672 *MSVCRT__errno() = MSVCRT_ERANGE;
680 /******************************************************************
683 MSVCRT_size_t CDECL MSVCRT_strnlen(const char *s, MSVCRT_size_t maxlen)
687 for(i=0; i<maxlen; i++)
693 /*********************************************************************
694 * _strtoi64_l (MSVCRT.@)
696 * FIXME: locale parameter is ignored
698 __int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
700 BOOL negative = FALSE;
703 TRACE("(%s %p %d %p)\n", nptr, endptr, base, locale);
705 if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
706 !MSVCRT_CHECK_PMT(base <= 36)) {
710 while(isspace(*nptr)) nptr++;
715 } else if(*nptr == '+')
718 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
731 char cur = tolower(*nptr);
739 if(cur<'a' || cur>='a'+base-10)
749 if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
750 ret = MSVCRT_I64_MAX;
751 *MSVCRT__errno() = MSVCRT_ERANGE;
752 } else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
753 ret = MSVCRT_I64_MIN;
754 *MSVCRT__errno() = MSVCRT_ERANGE;
760 *endptr = (char*)nptr;
765 /*********************************************************************
766 * _strtoi64 (MSVCRT.@)
768 __int64 CDECL MSVCRT_strtoi64(const char *nptr, char **endptr, int base)
770 return MSVCRT_strtoi64_l(nptr, endptr, base, NULL);
773 /*********************************************************************
774 * _strtoui64_l (MSVCRT.@)
776 * FIXME: locale parameter is ignored
778 unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
780 BOOL negative = FALSE;
781 unsigned __int64 ret = 0;
783 TRACE("(%s %p %d %p)\n", nptr, endptr, base, locale);
785 if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
786 !MSVCRT_CHECK_PMT(base <= 36)) {
790 while(isspace(*nptr)) nptr++;
795 } else if(*nptr == '+')
798 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
811 char cur = tolower(*nptr);
819 if(cur<'a' || cur>='a'+base-10)
826 if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
827 ret = MSVCRT_UI64_MAX;
828 *MSVCRT__errno() = MSVCRT_ERANGE;
834 *endptr = (char*)nptr;
836 return negative ? -ret : ret;
839 /*********************************************************************
840 * _strtoui64 (MSVCRT.@)
842 unsigned __int64 CDECL MSVCRT_strtoui64(const char *nptr, char **endptr, int base)
844 return MSVCRT_strtoui64_l(nptr, endptr, base, NULL);
847 /*********************************************************************
850 int CDECL _ltoa_s(MSVCRT_long value, char *str, MSVCRT_size_t size, int radix)
855 char buffer[33], *pos;
858 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
859 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
864 *MSVCRT__errno() = MSVCRT_EINVAL;
865 return MSVCRT_EINVAL;
868 if (value < 0 && radix == 10)
888 *--pos = '0' + digit;
890 *--pos = 'a' + digit - 10;
897 len = buffer + 33 - pos;
903 /* Copy the temporary buffer backwards up to the available number of
904 * characters. Don't copy the negative sign if present. */
912 for (pos = buffer + 31, i = 0; i < size; i++)
916 MSVCRT_INVALID_PMT("str[size] is too small");
917 *MSVCRT__errno() = MSVCRT_ERANGE;
918 return MSVCRT_ERANGE;
921 memcpy(str, pos, len);
925 /*********************************************************************
928 int CDECL _ltow_s(MSVCRT_long value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
933 MSVCRT_wchar_t buffer[33], *pos;
936 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
937 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
942 *MSVCRT__errno() = MSVCRT_EINVAL;
943 return MSVCRT_EINVAL;
946 if (value < 0 && radix == 10)
966 *--pos = '0' + digit;
968 *--pos = 'a' + digit - 10;
975 len = buffer + 33 - pos;
979 MSVCRT_wchar_t *p = str;
981 /* Copy the temporary buffer backwards up to the available number of
982 * characters. Don't copy the negative sign if present. */
990 for (pos = buffer + 31, i = 0; i < size; i++)
993 MSVCRT_INVALID_PMT("str[size] is too small");
995 *MSVCRT__errno() = MSVCRT_ERANGE;
996 return MSVCRT_ERANGE;
999 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
1003 /*********************************************************************
1004 * _itoa_s (MSVCRT.@)
1006 int CDECL _itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
1008 return _ltoa_s(value, str, size, radix);
1011 /*********************************************************************
1012 * _itow_s (MSVCRT.@)
1014 int CDECL _itow_s(int value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1016 return _ltow_s(value, str, size, radix);
1019 /*********************************************************************
1020 * _ui64toa_s (MSVCRT.@)
1022 int CDECL MSVCRT__ui64toa_s(unsigned __int64 value, char *str,
1023 MSVCRT_size_t size, int radix)
1025 char buffer[65], *pos;
1028 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1029 !MSVCRT_CHECK_PMT(radix>=2) || !MSVCRT_CHECK_PMT(radix<=36)) {
1030 *MSVCRT__errno() = MSVCRT_EINVAL;
1031 return MSVCRT_EINVAL;
1038 digit = value%radix;
1044 *--pos = 'a'+digit-10;
1047 if(buffer-pos+65 > size) {
1048 MSVCRT_INVALID_PMT("str[size] is too small");
1049 *MSVCRT__errno() = MSVCRT_EINVAL;
1050 return MSVCRT_EINVAL;
1053 memcpy(str, pos, buffer-pos+65);
1057 /*********************************************************************
1058 * _ui64tow_s (MSVCRT.@)
1060 int CDECL MSVCRT__ui64tow_s( unsigned __int64 value, MSVCRT_wchar_t *str,
1061 MSVCRT_size_t size, int radix )
1063 MSVCRT_wchar_t buffer[65], *pos;
1066 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1067 !MSVCRT_CHECK_PMT(radix>=2) || !MSVCRT_CHECK_PMT(radix<=36)) {
1068 *MSVCRT__errno() = MSVCRT_EINVAL;
1069 return MSVCRT_EINVAL;
1076 digit = value % radix;
1077 value = value / radix;
1079 *--pos = '0' + digit;
1081 *--pos = 'a' + digit - 10;
1082 } while (value != 0);
1084 if(buffer-pos+65 > size) {
1085 MSVCRT_INVALID_PMT("str[size] is too small");
1086 *MSVCRT__errno() = MSVCRT_EINVAL;
1087 return MSVCRT_EINVAL;
1090 memcpy(str, pos, buffer-pos+65);
1094 /*********************************************************************
1095 * _ultoa_s (MSVCRT.@)
1097 int CDECL _ultoa_s(MSVCRT_ulong value, char *str, MSVCRT_size_t size, int radix)
1100 char buffer[33], *pos;
1103 if (!str || !size || radix < 2 || radix > 36)
1108 *MSVCRT__errno() = MSVCRT_EINVAL;
1109 return MSVCRT_EINVAL;
1117 digit = value % radix;
1121 *--pos = '0' + digit;
1123 *--pos = 'a' + digit - 10;
1127 len = buffer + 33 - pos;
1133 /* Copy the temporary buffer backwards up to the available number of
1136 for (pos = buffer + 31, i = 0; i < size; i++)
1140 *MSVCRT__errno() = MSVCRT_ERANGE;
1141 return MSVCRT_ERANGE;
1144 memcpy(str, pos, len);
1148 /*********************************************************************
1149 * _i64toa_s (MSVCRT.@)
1151 int CDECL _i64toa_s(__int64 value, char *str, MSVCRT_size_t size, int radix)
1153 unsigned __int64 val;
1156 char buffer[65], *pos;
1159 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1160 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
1165 *MSVCRT__errno() = MSVCRT_EINVAL;
1166 return MSVCRT_EINVAL;
1169 if (value < 0 && radix == 10)
1185 digit = val % radix;
1189 *--pos = '0' + digit;
1191 *--pos = 'a' + digit - 10;
1198 len = buffer + 65 - pos;
1204 /* Copy the temporary buffer backwards up to the available number of
1205 * characters. Don't copy the negative sign if present. */
1213 for (pos = buffer + 63, i = 0; i < size; i++)
1217 MSVCRT_INVALID_PMT("str[size] is too small");
1218 *MSVCRT__errno() = MSVCRT_ERANGE;
1219 return MSVCRT_ERANGE;
1222 memcpy(str, pos, len);
1226 /*********************************************************************
1227 * _i64tow_s (MSVCRT.@)
1229 int CDECL _i64tow_s(__int64 value, MSVCRT_wchar_t *str, MSVCRT_size_t size, int radix)
1231 unsigned __int64 val;
1234 MSVCRT_wchar_t buffer[65], *pos;
1237 if (!MSVCRT_CHECK_PMT(str != NULL) || !MSVCRT_CHECK_PMT(size > 0) ||
1238 !MSVCRT_CHECK_PMT(radix >= 2) || !MSVCRT_CHECK_PMT(radix <= 36))
1243 *MSVCRT__errno() = MSVCRT_EINVAL;
1244 return MSVCRT_EINVAL;
1247 if (value < 0 && radix == 10)
1263 digit = val % radix;
1267 *--pos = '0' + digit;
1269 *--pos = 'a' + digit - 10;
1276 len = buffer + 65 - pos;
1280 MSVCRT_wchar_t *p = str;
1282 /* Copy the temporary buffer backwards up to the available number of
1283 * characters. Don't copy the negative sign if present. */
1291 for (pos = buffer + 63, i = 0; i < size; i++)
1294 MSVCRT_INVALID_PMT("str[size] is too small");
1296 *MSVCRT__errno() = MSVCRT_ERANGE;
1297 return MSVCRT_ERANGE;
1300 memcpy(str, pos, len * sizeof(MSVCRT_wchar_t));
1304 #define I10_OUTPUT_MAX_PREC 21
1305 /* Internal structure used by $I10_OUTPUT */
1306 struct _I10_OUTPUT_DATA {
1310 char str[I10_OUTPUT_MAX_PREC+1]; /* add space for '\0' */
1313 /*********************************************************************
1314 * $I10_OUTPUT (MSVCRT.@)
1315 * ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data
1316 * prec - precision of part, we're interested in
1317 * flag - 0 for first prec digits, 1 for fractional part
1318 * data - data to be populated
1321 * 0 if given double is NaN or INF
1325 * Native sets last byte of data->str to '0' or '9', I don't know what
1326 * it means. Current implementation sets it always to '0'.
1328 int CDECL MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
1330 static const char inf_str[] = "1#INF";
1331 static const char nan_str[] = "1#QNAN";
1333 /* MS' long double type wants 12 bytes for Intel's 80 bit FP format.
1334 * Some UNIX have sizeof(long double) == 16, yet only 80 bit are used.
1335 * Assume long double uses 80 bit FP, never seen 128 bit FP. */
1339 char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
1342 memcpy(&ld, &ld80, 10);
1344 TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
1355 memcpy(data->str, inf_str, sizeof(inf_str));
1363 memcpy(data->str, nan_str, sizeof(nan_str));
1369 int exp = 1+floor(log10(d));
1377 if(prec+1 > I10_OUTPUT_MAX_PREC)
1378 prec = I10_OUTPUT_MAX_PREC-1;
1384 sprintf(format, "%%.%dle", prec);
1385 sprintf(buf, format, d);
1388 data->pos = atoi(buf+prec+3);
1392 for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
1395 memcpy(data->str, buf+1, data->len);
1396 data->str[data->len] = '\0';
1398 if(buf[1]!='0' && prec-data->len+1>0)
1399 memcpy(data->str+data->len+1, buf+data->len+1, prec-data->len+1);
1403 #undef I10_OUTPUT_MAX_PREC