asc_conv.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <time.h>
  2. #include <string.h>
  3. /*
  4. * Internal ascii conversion routine, avoid use of printf, it's a bit big!
  5. */
  6. static void hit(buf, val)
  7. char *buf;
  8. int val;
  9. {
  10. *buf = '0' + val % 10;
  11. }
  12. void __asctime(buffer, ptm)
  13. register char *buffer;
  14. struct tm *ptm;
  15. {
  16. static char days[] = "SunMonTueWedThuFriSat";
  17. static char mons[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
  18. int year;
  19. /* 012345678901234567890123456 */
  20. strcpy(buffer, "Err Err .. ..:..:.. ....\n");
  21. if ((ptm->tm_wday >= 0) && (ptm->tm_wday <= 6))
  22. memcpy(buffer, days + 3 * (ptm->tm_wday), 3);
  23. if ((ptm->tm_mon >= 0) && (ptm->tm_mon <= 11))
  24. memcpy(buffer + 4, mons + 3 * (ptm->tm_mon), 3);
  25. hit(buffer + 8, ptm->tm_mday / 10);
  26. hit(buffer + 9, ptm->tm_mday);
  27. hit(buffer + 11, ptm->tm_hour / 10);
  28. hit(buffer + 12, ptm->tm_hour);
  29. hit(buffer + 14, ptm->tm_min / 10);
  30. hit(buffer + 15, ptm->tm_min);
  31. hit(buffer + 17, ptm->tm_sec / 10);
  32. hit(buffer + 18, ptm->tm_sec);
  33. year = ptm->tm_year + 1900;
  34. hit(buffer + 20, year / 1000);
  35. hit(buffer + 21, year / 100);
  36. hit(buffer + 22, year / 10);
  37. hit(buffer + 23, year);
  38. }