代码拉取完成,页面将自动刷新
同步操作将从 kalimdorsummer/protothreads 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "data_record.h"
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#define PRINTF(...) // printf(__VA_ARGS__)
static int open_file(data_record_t v, const char *file_name, const char *mode)
{
PRINTF("enter: %s\n", __func__);
PRINTF("ins_name: %s\n", v->ins_name);
if (v->enable_record){
if(v->fp != NULL){
PRINTF ( "%s already opened, v->fp: %p\n", file_name, v->fp );
return -1;
}
v->fp = fopen ( file_name, mode );
if ( v->fp == NULL ) {
PRINTF ( "open %s err\n", file_name );
return -1;
}
size_t name_len = strlen(file_name);
if (name_len > DR_FILE_NAME_LEN){
name_len = DR_FILE_NAME_LEN;
}
memcpy(v->file_name, file_name, strlen(file_name));
}
return 0;
}
int dr_open_file(data_record_t v, const char *file_name)
{
PRINTF("enter: %s\n", __func__);
v->open_mode = MODE_ASCII;
return open_file(v, file_name, "w+");
}
int dr_open_bin_create(data_record_t v, const char *file_name)
{
PRINTF("enter: %s\n", __func__);
v->open_mode = MODE_BIN;
return open_file(v, file_name, "wb+");
}
int dr_open_bin_read(data_record_t v, const char *file_name)
{
PRINTF("enter: %s\n", __func__);
v->open_mode = MODE_BIN;
return open_file(v, file_name, "rb");
}
void record_data(data_record_t v, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
PRINTF("enter: %s\n", __func__);
PRINTF("v->ins: %s\n", v->ins_name);
if (v->enable_record){
if (v->fp != NULL){
switch(v->open_mode){
case MODE_ASCII:
vfprintf(v->fp, fmt, args);
break;
// case MODE_BIN:;
// vsnPRINTF(buf, sizeof(buf), fmt, args);
// size_t len = strlen(buf);
// fwrite(buf, sizeof(buf[0]), len, v->fp);
// break;
default:
break;
}
}else{
PRINTF("not open file:---- %s\n", v->ins_name);
}
}
va_end(args);
}
//static uint8_t bin_buf[1024];
//static uint16_t bin_buf_idx;
void record_bin_data(data_record_t v, const void *ptr, size_t size, size_t nmemb)
{
PRINTF("enter: %s\n", __func__);
if (v->enable_record){
if(v->fp == NULL){
PRINTF("not open file:---- %s\n", v->ins_name);
return;
}
fwrite(ptr, size, nmemb, v->fp);
}
}
size_t read_bin_data(data_record_t v, void *ptr, size_t size, size_t nmemb)
{
PRINTF("enter: %s\n", __func__);
size_t read_cnt = 0;(void)read_cnt;
if (v->enable_record){
if(v->fp == NULL){
PRINTF("not open file:---- %s\n", v->ins_name);
return 0;
}
read_cnt = fread(ptr, size, nmemb, v->fp);
PRINTF("read_cnt: %u\n", read_cnt);
}
return read_cnt;
}
int dr_close_file(data_record_t v)
{
PRINTF("enter: %s\n", __func__);
if(v->fp == NULL){
PRINTF("not open file:---- %s\n", v->ins_name);
return -1;
}
int res = fclose(v->fp);
v->fp = NULL;
PRINTF("v->fp: %p\n", v->fp);
return res;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。