File: fmt_httpdate.c

package info (click to toggle)
libowfat 0.22-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,148 kB
  • ctags: 976
  • sloc: ansic: 10,424; makefile: 42
file content (35 lines) | stat: -rw-r--r-- 976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "fmt.h"
#include "byte.h"
#include <time.h>

static unsigned int fmt_2digits(char* dest,int i) {
  dest[0]=(i/10)+'0';
  dest[1]=(i%10)+'0';
  return 2;
}

unsigned int fmt_httpdate(char* dest,time_t t) {
  static const char days[] = "SunMonTueWedThuFriSat";
  static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
  struct tm* x=gmtime(&t);
  int i;

  if (dest==0) return 29;
  /* "Sun, 06 Nov 1994 08:49:37 GMT" */
  byte_copy(dest,3,days+3*x->tm_wday); i=3;
  i+=fmt_str(dest+i,", ");
  i+=fmt_2digits(dest+i,x->tm_mday);
  i+=fmt_str(dest+i," ");
  byte_copy(dest+i,3,months+3*x->tm_mon); i+=3;
  i+=fmt_str(dest+i," ");
  i+=fmt_2digits(dest+i,(x->tm_year+1900)/100);
  i+=fmt_2digits(dest+i,(x->tm_year+1900)%100);
  i+=fmt_str(dest+i," ");
  i+=fmt_2digits(dest+i,x->tm_hour);
  i+=fmt_str(dest+i,":");
  i+=fmt_2digits(dest+i,x->tm_min);
  i+=fmt_str(dest+i,":");
  i+=fmt_2digits(dest+i,x->tm_sec);
  i+=fmt_str(dest+i," GMT");
  return i;
}