向文件中写数据的方法

static inline int raw_write(const char *filename, const void *buffer, size_t bytes) {
        FILE *f = fopen(filename, "ab+"); // this will create file automatically
        if (f != NULL) {
            int ret = fwrite(buffer, 1, bytes, f);
            ret |= fclose(f);
            return ret;
        }
        return -1;
}

#ifdef HAVE_XXXX_AUDIO
#ifdef XXXX_AUDIO_LOGGER
#define MAX_FILE_LENGTH (20000000)
static inline int check_path(const char * path)
{
    char tmp[PATH_MAX];
    int i = 0;

    while(*path)
    {
        tmp[i] = *path;

        if(*path == '/' && i)
        {
            tmp[i] = '\0';
            if(access(tmp, F_OK) != 0)
            {
                if(mkdir(tmp, 0770) == -1)
                {
                    ALOGE("mkdir error! %s",(char*)strerror(errno));
                    return -1;
                }
            }
            tmp[i] = '/';
        }
        i++;
        path++;
    }
    return 0;
}

static inline int dump_recpcm(const char * filepath, const void * buffer, size_t bytes, const char * property)
{
    char value[PROPERTY_VALUE_MAX];
    int ret;
    property_get(property, value, "0");
    int bflag=atoi(value);
    if(bflag)
    {
        ret = check_path(filepath);
        if(ret<0)
        {
            ALOGE("dump fail!!!");
   return -1;
        }
        else
        {
            FILE * fp= fopen(filepath, "ab+");
            if(fp!=NULL)
            {
                long int position =0;
                position = ftell (fp);
                if(position> MAX_FILE_LENGTH)
                {
                    rewind(fp);
                }
                fwrite(buffer,1,count,fp);
                fclose(fp);
    return 1;
            }
            else
            {
                ALOGE("dump %s fail",property);
    return -1;
            }
        }
    }
 else
 {
  ALOGE("bflag %d is fail",bflag);
  return -1;
 }
}
#endif
#endif

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值