2018-08-21 16:11:50 +08:00
|
|
|
|
2019-05-16 20:33:42 +08:00
|
|
|
#include <MESA/MESA_htable.h>
|
2018-08-21 16:11:50 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <tfe_utils.h>
|
2018-10-18 12:13:41 +08:00
|
|
|
#include <time.h>
|
2019-05-16 20:33:42 +08:00
|
|
|
#include <assert.h>
|
2018-08-21 16:11:50 +08:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2018-10-18 12:13:41 +08:00
|
|
|
char *tfe_thread_safe_ctime(const time_t *tp, char *buf, int len)
|
|
|
|
|
{
|
2019-02-26 19:45:31 +06:00
|
|
|
struct tm local_time;
|
|
|
|
|
time_t now;
|
2018-10-18 12:13:41 +08:00
|
|
|
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"
|
|
|
|
|
};
|
2019-02-26 19:45:31 +06:00
|
|
|
time(&now);
|
|
|
|
|
if(NULL == (localtime_r(&now, &local_time)))
|
|
|
|
|
return NULL;
|
|
|
|
|
len = snprintf(buf, len, "%s %s %d %02d:%02d:%02d %d", weekday_str[local_time.tm_wday],
|
|
|
|
|
month_str[local_time.tm_mon], local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, local_time.tm_year+1900);
|
2018-10-18 12:13:41 +08:00
|
|
|
return buf;
|
|
|
|
|
}
|
2018-11-02 20:38:06 +08:00
|
|
|
//replacement of glibc scandir, to adapt dictator malloc wrap
|
|
|
|
|
int tfe_scandir(const char *dir, struct dirent ***namelist,
|
|
|
|
|
int(*filter)(const struct dirent *),
|
|
|
|
|
int(*compar)(const void *, const void *))
|
|
|
|
|
{
|
|
|
|
|
DIR * od;
|
|
|
|
|
int n = 0;
|
|
|
|
|
int ENLARGE_STEP=1024;
|
|
|
|
|
int DIR_ENT_SIZE=ENLARGE_STEP;
|
|
|
|
|
struct dirent ** list = NULL;
|
|
|
|
|
struct dirent * p;
|
|
|
|
|
struct dirent entry,*result;
|
|
|
|
|
|
|
|
|
|
if((dir == NULL) || (namelist == NULL))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
od = opendir(dir);
|
|
|
|
|
if(od == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
list = (struct dirent **)malloc(DIR_ENT_SIZE*sizeof(struct dirent *));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(0==readdir_r(od,&entry,&result))
|
|
|
|
|
{
|
|
|
|
|
if(result==NULL)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if( filter && !filter(&entry))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
p = (struct dirent *)malloc(sizeof(struct dirent));
|
|
|
|
|
memcpy((void *)p,(void *)(&entry),sizeof(struct dirent));
|
|
|
|
|
list[n] = p;
|
|
|
|
|
|
|
|
|
|
n++;
|
|
|
|
|
if(n >= DIR_ENT_SIZE)
|
|
|
|
|
{
|
|
|
|
|
DIR_ENT_SIZE+=ENLARGE_STEP;
|
|
|
|
|
list=(struct dirent **)realloc((void*)list,DIR_ENT_SIZE*sizeof(struct dirent *));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(od);
|
|
|
|
|
|
|
|
|
|
*namelist = list;
|
|
|
|
|
|
|
|
|
|
if(compar)
|
|
|
|
|
qsort((void *)*namelist,n,sizeof(struct dirent *),compar);
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
|
|
|
|
|
}
|
2018-09-30 11:01:18 +08:00
|
|
|
|