FreeBASIC  0.91.0
str_convto_lng.c
Go to the documentation of this file.
1 /* str$ routines for longint, ulongint
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 /*:::::*/
11 FBCALL FBSTRING *fb_LongintToStr ( long long num )
12 {
13  FBSTRING *dst;
14 
15  /* alloc temp string */
16  dst = fb_hStrAllocTemp( NULL, sizeof( long long ) * 3 );
17  if( dst != NULL )
18  {
19  /* convert */
20 #ifdef HOST_MINGW
21  _i64toa( num, dst->data, 10 );
22 #else
23  sprintf( dst->data, "%lld", num );
24 #endif
25 
26  fb_hStrSetLength( dst, strlen( dst->data ) );
27  }
28  else
29  dst = &__fb_ctx.null_desc;
30 
31  return dst;
32 }
33 
34 /*:::::*/
35 FBCALL FBSTRING *fb_ULongintToStr ( unsigned long long num )
36 {
37  FBSTRING *dst;
38 
39  /* alloc temp string */
40  dst = fb_hStrAllocTemp( NULL, sizeof( long long ) * 3 );
41  if( dst != NULL )
42  {
43  /* convert */
44 #ifdef HOST_MINGW
45  _ui64toa( num, dst->data, 10 );
46 #else
47  sprintf( dst->data, "%llu", num );
48 #endif
49 
50  fb_hStrSetLength( dst, strlen( dst->data ) );
51  }
52  else
53  dst = &__fb_ctx.null_desc;
54 
55  return dst;
56 }