Blame stdio-common/_itowa.h

Packit 6c4009
/* Internal function for converting integers to ASCII.
Packit 6c4009
   Copyright (C) 1994-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _ITOWA_H
Packit 6c4009
#define _ITOWA_H	1
Packit 6c4009
#include <features.h>
Packit 6c4009
#include <wchar.h>
Packit 6c4009
#include <_itoa.h>
Packit 6c4009
Packit 6c4009
/* Convert VALUE into ASCII in base BASE (2..36).
Packit 6c4009
   Write backwards starting the character just before BUFLIM.
Packit 6c4009
   Return the address of the first (left-to-right) character in the number.
Packit 6c4009
   Use upper case letters iff UPPER_CASE is nonzero.  */
Packit 6c4009
Packit 6c4009
extern wchar_t *_itowa (unsigned long long int value, wchar_t *buflim,
Packit 6c4009
			unsigned int base, int upper_case);
Packit 6c4009
Packit 6c4009
static inline wchar_t *
Packit 6c4009
__attribute__ ((unused, always_inline))
Packit 6c4009
_itowa_word (_ITOA_WORD_TYPE value, wchar_t *buflim,
Packit 6c4009
	     unsigned int base, int upper_case)
Packit 6c4009
{
Packit 6c4009
  extern const wchar_t _itowa_upper_digits[] attribute_hidden;
Packit 6c4009
  extern const wchar_t _itowa_lower_digits[] attribute_hidden;
Packit 6c4009
  const wchar_t *digits = (upper_case
Packit 6c4009
			   ? _itowa_upper_digits : _itowa_lower_digits);
Packit 6c4009
  wchar_t *bp = buflim;
Packit 6c4009
Packit 6c4009
  switch (base)
Packit 6c4009
    {
Packit 6c4009
#define SPECIAL(Base)							      \
Packit 6c4009
    case Base:								      \
Packit 6c4009
      do								      \
Packit 6c4009
	*--bp = digits[value % Base];					      \
Packit 6c4009
      while ((value /= Base) != 0);					      \
Packit 6c4009
      break
Packit 6c4009
Packit 6c4009
      SPECIAL (10);
Packit 6c4009
      SPECIAL (16);
Packit 6c4009
      SPECIAL (8);
Packit 6c4009
    default:
Packit 6c4009
      do
Packit 6c4009
	*--bp = digits[value % base];
Packit 6c4009
      while ((value /= base) != 0);
Packit 6c4009
    }
Packit 6c4009
  return bp;
Packit 6c4009
}
Packit 6c4009
#undef SPECIAL
Packit 6c4009
Packit 6c4009
#if !_ITOA_NEEDED
Packit 6c4009
/* No need for special long long versions.  */
Packit 6c4009
# define _itowa(value, buf, base, upper_case) \
Packit 6c4009
  _itowa_word (value, buf, base, upper_case)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#endif	/* itowa.h */