Back to index

glibc  2.9
_itowa.h
Go to the documentation of this file.
00001 /* Internal function for converting integers to ASCII.
00002    Copyright (C) 1994,95,96,97,98,99,2002,2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _ITOWA_H
00021 #define _ITOWA_H     1
00022 #include <features.h>
00023 #include <wchar.h>
00024 
00025 /* Convert VALUE into ASCII in base BASE (2..36).
00026    Write backwards starting the character just before BUFLIM.
00027    Return the address of the first (left-to-right) character in the number.
00028    Use upper case letters iff UPPER_CASE is nonzero.  */
00029 
00030 extern wchar_t *_itowa (unsigned long long int value, wchar_t *buflim,
00031                      unsigned int base, int upper_case);
00032 
00033 static inline wchar_t *
00034 __attribute__ ((unused, always_inline))
00035 _itowa_word (unsigned long value, wchar_t *buflim,
00036             unsigned int base, int upper_case)
00037 {
00038   extern const wchar_t _itowa_upper_digits[] attribute_hidden;
00039   extern const wchar_t _itowa_lower_digits[] attribute_hidden;
00040   const wchar_t *digits = (upper_case
00041                         ? _itowa_upper_digits : _itowa_lower_digits);
00042   wchar_t *bp = buflim;
00043 
00044   switch (base)
00045     {
00046 #define SPECIAL(Base)                                                       \
00047     case Base:                                                              \
00048       do                                                             \
00049        *--bp = digits[value % Base];                                        \
00050       while ((value /= Base) != 0);                                         \
00051       break
00052 
00053       SPECIAL (10);
00054       SPECIAL (16);
00055       SPECIAL (8);
00056     default:
00057       do
00058        *--bp = digits[value % base];
00059       while ((value /= base) != 0);
00060     }
00061   return bp;
00062 }
00063 #undef SPECIAL
00064 
00065 #endif /* itowa.h */