]> git.cworth.org Git - tar/blob - gnu/anytostr.c
Imported Upstream version 1.24
[tar] / gnu / anytostr.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* anytostr.c -- convert integers to printable strings
4
5    Copyright (C) 2001, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* Written by Paul Eggert */
21
22 #include <config.h>
23
24 #include "inttostr.h"
25 #include "verify.h"
26
27 /* Convert I to a printable string in BUF, which must be at least
28    INT_BUFSIZE_BOUND (INTTYPE) bytes long.  Return the address of the
29    printable string, which need not start at BUF.  */
30
31 char * __attribute_warn_unused_result__
32 anytostr (inttype i, char *buf)
33 {
34   verify (TYPE_SIGNED (inttype) == inttype_is_signed);
35   char *p = buf + INT_STRLEN_BOUND (inttype);
36   *p = 0;
37
38 #if inttype_is_signed
39   if (i < 0)
40     {
41       do
42         *--p = '0' - i % 10;
43       while ((i /= 10) != 0);
44
45       *--p = '-';
46     }
47   else
48 #endif
49     {
50       do
51         *--p = '0' + i % 10;
52       while ((i /= 10) != 0);
53     }
54
55   return p;
56 }