Fix directory validation after handler
[MonkeyD.git] / src / clock.c
blob68ae35354750d91448f5d49b6775dec02f012ffc
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
3 /* Monkey HTTP Daemon
4 * ------------------
5 * Copyright (C) 2001-2008, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /* clock.c */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <pthread.h>
27 #include <time.h>
28 #include <unistd.h>
30 #include "memory.h"
31 #include "clock.h"
33 void mk_clock_log_set_time()
35 time_t utime;
37 if(!log_current_time.data)
39 log_current_time.data = mk_mem_malloc_z(30);
40 log_current_time.len = 28;
43 if ((utime = time(NULL)) == -1)
45 return;
48 log_current_utime = utime;
49 strftime(log_current_time.data, 30, "[%d/%b/%G %T %z]",
50 (struct tm *)localtime((time_t *) &utime));
53 void mk_clock_header_set_time()
55 int n, len = 30;
56 time_t date;
57 struct tm *gmt_tm;
59 if(!header_current_time.data)
61 header_current_time.data = mk_mem_malloc_z(len);
62 header_current_time.len = len - 1;
65 date = time(NULL);
66 gmt_tm = (struct tm *) gmtime(&date);
67 n = strftime(header_current_time.data, len, GMT_DATEFORMAT, gmt_tm);
70 void *mk_clock_worker_init(void *args)
72 while(1)
74 mk_clock_log_set_time();
75 mk_clock_header_set_time();
76 sleep(1);