l64a.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <stdlib.h>
  17. /* Conversion table. */
  18. static const char conv_table[64] =
  19. {
  20. '.', '/', '0', '1', '2', '3', '4', '5',
  21. '6', '7', '8', '9', 'A', 'B', 'C', 'D',
  22. 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  23. 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  24. 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
  25. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  26. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
  27. 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  28. };
  29. char *
  30. l64a (n)
  31. long int n;
  32. {
  33. unsigned long int m = (unsigned long int) n;
  34. static char result[7];
  35. int cnt;
  36. /* The standard says that only 32 bits are used. */
  37. m &= 0xffffffff;
  38. if (m == 0ul)
  39. /* The value for N == 0 is defined to be the empty string. */
  40. return (char *) "";
  41. for (cnt = 0; m > 0ul; ++cnt)
  42. {
  43. result[cnt] = conv_table[m & 0x3f];
  44. m >>= 6;
  45. }
  46. result[cnt] = '\0';
  47. return result;
  48. }