1*18fd37a7SXin LI /* inttostr.h -- convert integers to printable strings 2*18fd37a7SXin LI 3*18fd37a7SXin LI Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 4*18fd37a7SXin LI 5*18fd37a7SXin LI This program is free software; you can redistribute it and/or modify 6*18fd37a7SXin LI it under the terms of the GNU General Public License as published by 7*18fd37a7SXin LI the Free Software Foundation; either version 2, or (at your option) 8*18fd37a7SXin LI any later version. 9*18fd37a7SXin LI 10*18fd37a7SXin LI This program is distributed in the hope that it will be useful, 11*18fd37a7SXin LI but WITHOUT ANY WARRANTY; without even the implied warranty of 12*18fd37a7SXin LI MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*18fd37a7SXin LI GNU General Public License for more details. 14*18fd37a7SXin LI 15*18fd37a7SXin LI You should have received a copy of the GNU General Public License 16*18fd37a7SXin LI along with this program; if not, write to the Free Software Foundation, 17*18fd37a7SXin LI Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 18*18fd37a7SXin LI 19*18fd37a7SXin LI /* Written by Paul Eggert */ 20*18fd37a7SXin LI 21*18fd37a7SXin LI #if HAVE_CONFIG_H 22*18fd37a7SXin LI # include <config.h> 23*18fd37a7SXin LI #endif 24*18fd37a7SXin LI 25*18fd37a7SXin LI #if HAVE_INTTYPES_H 26*18fd37a7SXin LI # include <inttypes.h> 27*18fd37a7SXin LI #endif 28*18fd37a7SXin LI #if HAVE_STDINT_H 29*18fd37a7SXin LI # include <stdint.h> 30*18fd37a7SXin LI #endif 31*18fd37a7SXin LI 32*18fd37a7SXin LI #include <limits.h> 33*18fd37a7SXin LI 34*18fd37a7SXin LI #if HAVE_SYS_TYPES_H 35*18fd37a7SXin LI # include <sys/types.h> 36*18fd37a7SXin LI #endif 37*18fd37a7SXin LI 38*18fd37a7SXin LI /* Upper bound on the string length of an integer converted to string. 39*18fd37a7SXin LI 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; 40*18fd37a7SXin LI add 1 for integer division truncation; add 1 more for a minus sign. */ 41*18fd37a7SXin LI #define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2) 42*18fd37a7SXin LI 43*18fd37a7SXin LI #define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) 44*18fd37a7SXin LI 45*18fd37a7SXin LI char *offtostr (off_t, char *); 46*18fd37a7SXin LI char *imaxtostr (intmax_t, char *); 47*18fd37a7SXin LI char *umaxtostr (uintmax_t, char *); 48