Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
989 B

  1. #include "fmt.h"
  2. #include "byte.h"
  3. #include <time.h>
  4. static unsigned int fmt_2digits(char* dest,int i) {
  5. dest[0]=(char)((i/10)+'0');
  6. dest[1]=(char)((i%10)+'0');
  7. return 2;
  8. }
  9. size_t fmt_httpdate(char* dest,time_t t) {
  10. static const char days[] = "SunMonTueWedThuFriSat";
  11. static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
  12. struct tm* x=gmtime(&t);
  13. size_t i;
  14. if (dest==0) return 29;
  15. /* "Sun, 06 Nov 1994 08:49:37 GMT" */
  16. byte_copy(dest,3,days+3*x->tm_wday); i=3;
  17. i+=fmt_str(dest+i,", ");
  18. i+=fmt_2digits(dest+i,x->tm_mday);
  19. i+=fmt_str(dest+i," ");
  20. byte_copy(dest+i,3,months+3*x->tm_mon); i+=3;
  21. i+=fmt_str(dest+i," ");
  22. i+=fmt_2digits(dest+i,(x->tm_year+1900)/100);
  23. i+=fmt_2digits(dest+i,(x->tm_year+1900)%100);
  24. i+=fmt_str(dest+i," ");
  25. i+=fmt_2digits(dest+i,x->tm_hour);
  26. i+=fmt_str(dest+i,":");
  27. i+=fmt_2digits(dest+i,x->tm_min);
  28. i+=fmt_str(dest+i,":");
  29. i+=fmt_2digits(dest+i,x->tm_sec);
  30. i+=fmt_str(dest+i," GMT");
  31. return i;
  32. }