FreeBASIC  0.91.0
qb_str_convto_lng.c
Go to the documentation of this file.
1 /* QB compatible 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_LongintToStrQB ( 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  dst->data[0] = ' ';
22  _i64toa( num, dst->data + (num >= 0? 1:0), 10 );
23 #else
24  sprintf( dst->data, "% lld", num );
25 #endif
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_ULongintToStrQB ( 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  dst->data[0] = ' ';
46  _ui64toa( num, dst->data + 1, 10 );
47 #else
48  sprintf( dst->data, " %llu", num );
49 #endif
50  fb_hStrSetLength( dst, strlen( dst->data ) );
51  }
52  else
53  dst = &__fb_ctx.null_desc;
54 
55  return dst;
56 }