ltoa.c 551 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
  2. * This file is part of the Linux-8086 C library and is distributed
  3. * under the GNU Library General Public License.
  4. */
  5. static char buf[12];
  6. extern char *ultoa();
  7. char *ltoa(val)
  8. long val;
  9. {
  10. char *p;
  11. int flg = 0;
  12. if (val < 0) {
  13. flg++;
  14. val = -val;
  15. }
  16. p = ultoa(val);
  17. if (flg)
  18. *--p = '-';
  19. return p;
  20. }
  21. char *ultoa(val)
  22. unsigned long val;
  23. {
  24. char *p;
  25. p = buf + sizeof(buf);
  26. *--p = '\0';
  27. do {
  28. *--p = '0' + val % 10;
  29. val /= 10;
  30. }
  31. while (val);
  32. return p;
  33. }