Blame lib/anytostr.c

Packit 33f14e
/* anytostr.c -- convert integers to printable strings
Packit 33f14e
Packit 33f14e
   Copyright (C) 2001, 2006, 2008-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* Written by Paul Eggert */
Packit 33f14e
Packit 33f14e
/* Tell gcc not to warn about the (i < 0) test, below.  */
Packit 33f14e
#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
Packit 33f14e
# pragma GCC diagnostic ignored "-Wtype-limits"
Packit 33f14e
#elif defined __clang__
Packit 33f14e
# pragma clang diagnostic ignored "-Wtautological-compare"
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
#include <config.h>
Packit 33f14e
Packit 33f14e
#include "inttostr.h"
Packit 33f14e
Packit 33f14e
/* Convert I to a printable string in BUF, which must be at least
Packit 33f14e
   INT_BUFSIZE_BOUND (INTTYPE) bytes long.  Return the address of the
Packit 33f14e
   printable string, which need not start at BUF.  */
Packit 33f14e
Packit 33f14e
char * __attribute_warn_unused_result__
Packit 33f14e
anytostr (inttype i, char *buf)
Packit 33f14e
{
Packit 33f14e
  char *p = buf + INT_STRLEN_BOUND (inttype);
Packit 33f14e
  *p = 0;
Packit 33f14e
Packit 33f14e
  if (i < 0)
Packit 33f14e
    {
Packit 33f14e
      do
Packit 33f14e
        *--p = '0' - i % 10;
Packit 33f14e
      while ((i /= 10) != 0);
Packit 33f14e
Packit 33f14e
      *--p = '-';
Packit 33f14e
    }
Packit 33f14e
  else
Packit 33f14e
    {
Packit 33f14e
      do
Packit 33f14e
        *--p = '0' + i % 10;
Packit 33f14e
      while ((i /= 10) != 0);
Packit 33f14e
    }
Packit 33f14e
Packit 33f14e
  return p;
Packit 33f14e
}