library/src/javascript/JSON/BP-JSON.cc
// Reads a file and attempts to parse it as json.
Reads a file and attempts to parse it as json.
Reads a file and attempts to parse it as json .
BP_ERROR_T BP_JSONParseFromFile
(
		P_BP_JSON json,
		char *path_to_file,
		size_t max_depth_for_token_allocation,
		size_t max_tokens_total
)
{
	if(!json)
		return ERR_FAILURE;
	if(!path_to_file)
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(path_to_file, bpstrlen(path_to_file), BP_TRUE))
		return ERR_FAILURE;
	BP_FILE_LOAD_EXTRA_INFO load_info;
	BP_ZERO_STACK(load_info);
	char *buff_contents = BP_FileGetContents(path_to_file, &load_info);
	if(!buff_contents)
		return ERR_FAILURE;
	if(!BP_JSONParseFromBuffer(json, buff_contents, load_info.file_size, 40, 500))
	{
		bpfree(buff_contents);
		return ERR_FAILURE;
	}
	bpfree(buff_contents);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSONParseFromFile ( P_BP_JSON json , char * path_to_file , size_t max_depth_for_token_allocation , size_t max_tokens_total ) { if ( ! json ) return ERR_FAILURE ; if ( ! path_to_file ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( path_to_file , bpstrlen ( path_to_file ) , BP_TRUE ) ) return ERR_FAILURE ; BP_FILE_LOAD_EXTRA_INFO load_info ; BP_ZERO_STACK ( load_info ) ; char * buff_contents = BP_FileGetContents ( path_to_file , & load_info ) ; if ( ! buff_contents ) return ERR_FAILURE ; if ( ! BP_JSONParseFromBuffer ( json , buff_contents , load_info . file_size , 40 , 500 ) ) { bpfree ( buff_contents ) ; return ERR_FAILURE ; } bpfree ( buff_contents ) ; return ERR_SUCCESS ; }
Reads a file and attempts to parse it as json.
Reads a file and attempts to parse it as json .
// create load info and zero it // retrieve contents // ensure we could read the contents // attempt to parse JSON from the provided buffer // destroy the buffer contents // return indicating success