FreeBASIC  0.91.0
str_convto.c
Go to the documentation of this file.
1 /* str$ routines for int, uint
2  *
3  * the result string's len is being "faked" to appear as if it were shorter
4  * than the one that has to be allocated to fit _itoa and _gvct buffers.
5  */
6 
7 #include "fb.h"
8 
9 
10 /*:::::*/
12 {
13  FBSTRING *dst;
14 
15  /* alloc temp string */
16  dst = fb_hStrAllocTemp( NULL, sizeof( int ) * 3 );
17  if( dst != NULL )
18  {
19  /* convert */
20 #ifdef HOST_MINGW
21  _itoa( num, dst->data, 10 );
22 #else
23  sprintf( dst->data, "%d", num );
24 #endif
25  fb_hStrSetLength( dst, strlen( dst->data ) );
26  }
27  else
28  dst = &__fb_ctx.null_desc;
29 
30  return dst;
31 }
32 
33 /*:::::*/
34 FBCALL FBSTRING *fb_UIntToStr ( unsigned int num )
35 {
36  FBSTRING *dst;
37 
38  /* alloc temp string */
39  dst = fb_hStrAllocTemp( NULL, sizeof( int ) * 3 );
40  if( dst != NULL )
41  {
42  /* convert */
43 #ifdef HOST_MINGW
44  _ultoa( num, dst->data, 10 );
45 #else
46  sprintf( dst->data, "%u", num );
47 #endif
48  fb_hStrSetLength( dst, strlen( dst->data ) );
49  }
50  else
51  dst = &__fb_ctx.null_desc;
52 
53  return dst;
54 }