bool yyjson_val_write_file()

in include/yyjson/yyjson.c [8820:8844]


bool yyjson_val_write_file(const char *path,
                           const yyjson_val *val,
                           yyjson_write_flag flg,
                           const yyjson_alc *alc_ptr,
                           yyjson_write_err *err) {
    yyjson_write_err dummy_err;
    u8 *dat;
    usize dat_len = 0;
    yyjson_val *root = constcast(yyjson_val *)val;
    bool suc;
    
    alc_ptr = alc_ptr ? alc_ptr : &YYJSON_DEFAULT_ALC;
    err = err ? err : &dummy_err;
    if (unlikely(!path || !*path)) {
        err->msg = "input path is invalid";
        err->code = YYJSON_READ_ERROR_INVALID_PARAMETER;
        return false;
    }
    
    dat = (u8 *)yyjson_val_write_opts(root, flg, alc_ptr, &dat_len, err);
    if (unlikely(!dat)) return false;
    suc = write_dat_to_file(path, dat, dat_len, err);
    alc_ptr->free(alc_ptr->ctx, dat);
    return suc;
}