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.
 
 
 
 

42 lines
1.1 KiB

  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. #ifdef _WIN32
  13. struct tm tmp;
  14. struct tm* x=&tmp;
  15. gmtime_s(&tmp,&t); // can't recover from when this fails
  16. #else
  17. struct tm* x=gmtime(&t);
  18. #endif
  19. size_t i;
  20. if (dest==0) return 29;
  21. /* "Sun, 06 Nov 1994 08:49:37 GMT" */
  22. byte_copy(dest,3,days+3*x->tm_wday); i=3;
  23. i+=fmt_str(dest+i,", ");
  24. i+=fmt_2digits(dest+i,x->tm_mday);
  25. i+=fmt_str(dest+i," ");
  26. byte_copy(dest+i,3,months+3*x->tm_mon); i+=3;
  27. i+=fmt_str(dest+i," ");
  28. i+=fmt_2digits(dest+i,(x->tm_year+1900)/100);
  29. i+=fmt_2digits(dest+i,(x->tm_year+1900)%100);
  30. i+=fmt_str(dest+i," ");
  31. i+=fmt_2digits(dest+i,x->tm_hour);
  32. i+=fmt_str(dest+i,":");
  33. i+=fmt_2digits(dest+i,x->tm_min);
  34. i+=fmt_str(dest+i,":");
  35. i+=fmt_2digits(dest+i,x->tm_sec);
  36. i+=fmt_str(dest+i," GMT");
  37. return i;
  38. }