
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tfe_utils.h>
#include <time.h>

int addr_sock_to_layer(struct sockaddr * sock_addr, int sockaddrlen, struct layer_addr * layer_addr)
{
	return 0;
}

int addr_layer_to_sock(struct layer_addr * layer_addr, struct sockaddr * sock_addr)
{
	int sockaddrlen=-1;
	return sockaddrlen;
}

//functioned as strdup, for dictator compatible.
char* tfe_strdup(const char* s)
{
	char*d=NULL;
	if(s==NULL)
	{
		return NULL;
	}

	d=(char*)malloc(strlen(s)+1);
	memcpy(d,s,strlen(s)+1);
	return d;
}
char *tfe_thread_safe_ctime(const time_t *tp, char *buf, int len)
{
    unsigned int year, month, day, weekday, hour, min, sec;
    unsigned int year_days = 365;
    unsigned int month_days[12] =
    {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    static unsigned char weekday_str[7][4] =
    {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr",
                                             "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
                                            };
    sec = * tp;
    min = sec / 60; sec = sec % 60;
    hour = min / 60; min = min % 60; hour += 8;
    day = hour / 24; hour = hour % 24;
    weekday = day % 7; weekday = (weekday + 4) % 7;

    for(year = 1970; day >= year_days;)
    {
        day -= year_days;
        year ++;

        if(0 == year % 4 && (0 != year % 100 || 0 == year % 400))
            year_days = 366;
        else year_days = 365;
    }

    if(366 == year_days) month_days[1] = 29;

	//bug fix by yw 20120808
    for(month = 0; day >= month_days[month];)
    {
        day -= month_days[month];
        month ++;
    }

    /*
    snprintf(buf, len, "%02d:%02d:%02d, %04d/%02d/%02d, %s",
        hour, min, sec, year, month, day, weekday_str[week_day]);
    */
    snprintf(buf, len, "%s %s %d %02d:%02d:%02d %d", weekday_str[weekday],
             month_str[month], day + 1, hour, min, sec, year);
    return buf;
}

