Line data Source code
1 : /* Copyright 1989-2024 Free Software Foundation, Inc. 2 : Written by James Clark (jjc@jclark.com) 3 : 4 : This file is part of groff, the GNU roff typesetting system. 5 : 6 : groff is free software; you can redistribute it and/or modify it under 7 : the terms of the GNU General Public License as published by the Free 8 : Software Foundation, either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 : for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 : 19 : #ifdef HAVE_CONFIG_H 20 : #include <config.h> 21 : #endif 22 : 23 : #include "lib.h" 24 : 25 : #ifdef __cplusplus 26 : extern "C" { 27 : #endif 28 : 29 12057202 : const char *i_to_a(int i) 30 : { 31 : /* Room for INT_DIGITS digits, - and '\0' */ 32 : static char buf[INT_DIGITS + 2]; 33 12057202 : char *p = buf + INT_DIGITS + 1; /* points to terminating '\0' */ 34 12057202 : if (i >= 0) { 35 : do { 36 31731711 : *--p = '0' + (i % 10); 37 31731711 : i /= 10; 38 31731711 : } while (i != 0); 39 11996087 : return p; 40 : } 41 : else { /* i < 0 */ 42 : do { 43 239690 : *--p = '0' - (i % 10); 44 239690 : i /= 10; 45 239690 : } while (i != 0); 46 61115 : *--p = '-'; 47 : } 48 61115 : return p; 49 : } 50 : 51 256396 : const char *ui_to_a(unsigned int i) 52 : { 53 : /* Room for UINT_DIGITS digits and '\0' */ 54 : static char buf[UINT_DIGITS + 1]; 55 256396 : char *p = buf + UINT_DIGITS; /* points to terminating '\0' */ 56 : do { 57 848584 : *--p = '0' + (i % 10); 58 848584 : i /= 10; 59 848584 : } while (i != 0); 60 256396 : return p; 61 : } 62 : 63 : #ifdef __cplusplus 64 : } 65 : #endif 66 : 67 : // Local Variables: 68 : // fill-column: 72 69 : // mode: C++ 70 : // End: 71 : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72: