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