Blame stdlib/l64a.c

Packit 6c4009
/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
/* Conversion table.  */
Packit 6c4009
static const char conv_table[64] =
Packit 6c4009
{
Packit 6c4009
  '.', '/', '0', '1', '2', '3', '4', '5',
Packit 6c4009
  '6', '7', '8', '9', 'A', 'B', 'C', 'D',
Packit 6c4009
  'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
Packit 6c4009
  'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
Packit 6c4009
  'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
Packit 6c4009
  'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
Packit 6c4009
  'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
Packit 6c4009
  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
char *
Packit 6c4009
l64a (long int n)
Packit 6c4009
{
Packit 6c4009
  unsigned long int m = (unsigned long int) n;
Packit 6c4009
  static char result[7];
Packit 6c4009
  int cnt;
Packit 6c4009
Packit 6c4009
  /* The standard says that only 32 bits are used.  */
Packit 6c4009
  m &= 0xffffffff;
Packit 6c4009
Packit 6c4009
  if (m == 0ul)
Packit 6c4009
    /* The value for N == 0 is defined to be the empty string. */
Packit 6c4009
    return (char *) "";
Packit 6c4009
Packit 6c4009
  for (cnt = 0; m > 0ul; ++cnt)
Packit 6c4009
    {
Packit 6c4009
      result[cnt] = conv_table[m & 0x3f];
Packit 6c4009
      m >>= 6;
Packit 6c4009
    }
Packit 6c4009
  result[cnt] = '\0';
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}