Blame stdlib/a64l.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.org>, 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
#define TABLE_BASE 0x2e
Packit 6c4009
#define TABLE_SIZE 0x4d
Packit 6c4009
Packit 6c4009
#define XX ((char)0x40)
Packit 6c4009
Packit 6c4009
Packit 6c4009
static const char a64l_table[TABLE_SIZE] =
Packit 6c4009
{
Packit 6c4009
  /* 0x2e */                                                           0,  1,
Packit 6c4009
  /* 0x30 */   2,  3,  4,  5,  6,  7,  8,  9, 10, 11, XX, XX, XX, XX, XX, XX,
Packit 6c4009
  /* 0x40 */  XX, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
Packit 6c4009
  /* 0x50 */  27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, XX, XX, XX, XX, XX,
Packit 6c4009
  /* 0x60 */  XX, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
Packit 6c4009
  /* 0x70 */  53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
long int
Packit 6c4009
a64l (const char *string)
Packit 6c4009
{
Packit 6c4009
  const char *ptr = string;
Packit 6c4009
  unsigned long int result = 0ul;
Packit 6c4009
  const char *end = ptr + 6;
Packit 6c4009
  int shift = 0;
Packit 6c4009
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
      unsigned index;
Packit 6c4009
      unsigned value;
Packit 6c4009
Packit 6c4009
      index = *ptr - TABLE_BASE;
Packit 6c4009
      if ((unsigned int) index >= TABLE_SIZE)
Packit 6c4009
	break;
Packit 6c4009
      value = (int) a64l_table[index];
Packit 6c4009
      if (value == (int) XX)
Packit 6c4009
	break;
Packit 6c4009
      ++ptr;
Packit 6c4009
      result |= value << shift;
Packit 6c4009
      shift += 6;
Packit 6c4009
    }
Packit 6c4009
  while (ptr != end);
Packit 6c4009
Packit 6c4009
  return (long int) result;
Packit 6c4009
}