indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / http_datestring.c
index 2394391f202dc968a244a33e0271d9567f7f0809..d80adf4fe481522cf8209f148dc9f50e04aca5c3 100644 (file)
@@ -1,15 +1,11 @@
-/*
- * $Id$
- */
-/**
- * \defgroup HTTPDateTime Function to generate HTTP-compliant textual time/date stamp
- * (This module was lifted directly from the Citadel server source)
- *
- * \ingroup WebcitHttpServer
- */
-/*@{*/
 #include "webcit.h"
 
+#ifdef __FreeBSD__
+
+/** I like to believe there is a better way to do this. */
+#define HAVE_STRUCT_TM_TM_GMTOFF
+#endif
+
 /** HTTP Months - do not translate - these are not for human consumption */
 static char *httpdate_months[] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
@@ -49,40 +45,39 @@ void http_datestring(char *buf, size_t n, time_t xtime) {
                offset = 0L - offset;
                offsign = '-';
        }
-       offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
+       offset = ((offset / 3600) * 100) + (offset % 60);
 
        snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
-               httpdate_weekdays[t.tm_wday],
-               t.tm_mday,
-               httpdate_months[t.tm_mon],
-               t.tm_year + 1900,
-               t.tm_hour,
-               t.tm_min,
-               t.tm_sec,
-               offsign, offset
-       );
+                httpdate_weekdays[t.tm_wday],
+                t.tm_mday, httpdate_months[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, offsign, offset);
 }
 
 
-void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
-{
+void tmplput_nowstr(StrBuf * Target, WCTemplputParams * TP) {
+       char buf[64];
+       long bufused;
        time_t now;
+
        now = time(NULL);
-       StrEscAppend(Target, NULL, asctime(localtime(&now)), 0, 0);
+#ifdef HAVE_SOLARIS_LOCALTIME_R
+       asctime_r(localtime(&now), buf, sizeof(buf));
+#else
+       asctime_r(localtime(&now), buf);
+#endif
+       bufused = strlen(buf);
+       if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
+               buf[bufused - 1] = '\0';
+               bufused--;
+       }
+       StrEscAppend(Target, NULL, buf, 0, 0);
 }
-void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
-{
+void tmplput_nowno(StrBuf * Target, WCTemplputParams * TP) {
        time_t now;
        now = time(NULL);
        StrBufAppendPrintf(Target, "%ld", now);
 }
 
-void 
-InitModule_DATE
-(void)
-{
+void InitModule_DATE(void) {
        RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, NULL, CTX_NONE);
        RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, NULL, CTX_NONE);
 }
-
-/*@}*/