#include "stddef.h"
#include <string.h>
#include <stdio.h>
#include "kk_tsl_common.h"

#define TSL_PATH_FILE "/home/tsl/%s.json"
char* kk_load_json(const char *product_type)
{
	FILE *fp;
	char *buf = NULL;
	char *tslPath = NULL;
	int path_len = 0;
	unsigned int filesize;

	path_len = strlen(TSL_PATH_FILE)+strlen(product_type)+1;
	tslPath = malloc(path_len);
	if(tslPath == NULL){
		return NULL;
	}
	memset(tslPath,0x0,path_len);
	snprintf(tslPath,path_len,TSL_PATH_FILE,product_type);
	printf("\n[%s][%d]tslPath:%s!!!\n",__FUNCTION__,__LINE__,tslPath);
	if(!(fp =  fopen(tslPath,"a+")))
	{
		printf("can't open the file account.txt\n");
		free(tslPath);
		return NULL;
	}
    fseek(fp, 0L, SEEK_END);
    filesize = ftell(fp);	
	printf("filesize :%d\n",filesize);
	buf = malloc(filesize+1);
	if(buf == NULL)
	{
		printf("MALLOC FAIL!!!\n");
		free(tslPath);
		return NULL;

	}
	memset(buf,0x0,filesize+1);
	fseek(fp, 0L, SEEK_SET);
	fread(buf, 1, filesize, fp);
	//printf("%s!!!\n",buf);	
	free(tslPath);
	return buf;
}

