FreeBASIC  0.91.0
strw_oct_lng.c
Go to the documentation of this file.
1 /* octw$ routine for long long's */
2 
3 #include "fb.h"
4 
5 FBCALL FB_WCHAR *fb_WstrOctEx_l ( unsigned long long num, int digits )
6 {
7  FB_WCHAR *s;
8  int i;
9  unsigned long long num2;
10 
11  if( digits <= 0 ) {
12  /* Only use the minimum amount of digits needed; need to count
13  the important 3-bit (base 8) chunks in the number.
14  And if it's zero, use 1 digit for 1 zero. */
15  digits = 0;
16  num2 = num;
17  while( num2 ) {
18  digits += 1;
19  num2 >>= 3;
20  }
21  if( digits == 0 )
22  digits = 1;
23  }
24 
25  s = fb_wstr_AllocTemp( digits );
26  if( s == NULL )
27  return NULL;
28 
29  i = digits - 1;
30  while( i >= 0 ) {
31  s[i] = _LC('0') + (num & 7); /* '0'..'7' */
32  num >>= 3;
33  i -= 1;
34  }
35 
36  s[digits] = _LC('\0');
37  return s;
38 }
39 
40 FBCALL FB_WCHAR *fb_WstrOct_l ( unsigned long long num )
41 {
42  return fb_WstrOctEx_l( num, 0 );
43 }