fopen code

来源:互联网 发布:获取网站源码工具 编辑:程序博客网 时间:2024/06/16 07:19
static result_t __read_dns_config(const char *file_name, char *output_buf, size_t output_buf_len){    FILE *fp = NULL;    size_t flen;    LOGD(C_DNS_TAG, "read livepush config, file_name=%s", file_name);    fp = fopen(file_name, "r");    if (NULL == fp) {        LOGE(C_DNS_TAG, "open livepush dns config file failed");        goto L_ERROR;    }    fseek(fp, 0L, SEEK_END);    flen=ftell(fp);    if (output_buf_len < flen) {        LOGE(C_DNS_TAG, "livepush config length=%u, but output buf length=%u", flen, output_buf_len);        goto L_ERROR;    }    fseek(fp,0L,SEEK_SET);    fread(output_buf, flen, 1, fp);    fclose(fp);    return E_OK;L_ERROR:    if (NULL != fp) {        fclose(fp);        fp = NULL;    }    return E_FAILED;}