1 /* $Id: intspc.c,v 1.5 2020-10-13 04:47:53 phil Exp $ */ 2 3 /* 4 * long long to string (systems without long long library support) 5 */ 6 7 #ifdef HAVE_CONFIG_H 8 #include "config.h" 9 #endif /* HAVE_CONFIG_H defined */ 10 11 #include <stdio.h> 12 13 #include "h.h" 14 #include "snotypes.h" 15 #include "macros.h" 16 #include "lib.h" 17 #include "str.h" 18 19 #include "equ.h" 20 21 static VAR char strbuf[32]; /* 2^64 is only 21 chars! */ 22 23 void intspc(struct spec * sp,struct descr * dp)24intspc(struct spec *sp, struct descr *dp) { 25 char *bp; 26 int_t x; 27 unsigned INT_T u; 28 29 bp = strbuf + sizeof(strbuf); 30 *--bp = '\0'; 31 32 x = D_A(dp); 33 if (x < 0) 34 u = -x; 35 else 36 u = x; 37 38 while (u >= 10) { 39 *--bp = (u % 10) + '0'; 40 u /= 10; 41 } 42 *--bp = u + '0'; 43 44 if (x < 0) 45 *--bp = '-'; 46 47 S_A(sp) = (int_t) bp; /* OY! */ 48 S_F(sp) = 0; 49 S_V(sp) = 0; 50 S_O(sp) = 0; 51 S_L(sp) = strlen(bp); 52 CLR_S_UNUSED(sp); 53 } 54