Read the GGUF metadata table. Values stay in the mmap; we store offsets so * later validation can decode only the keys it needs. */
| 1857 | static bool write_f32_binary_file(const char *path, const float *data, uint64_t n) { |
| 1858 | FILE *fp = fopen(path, "wb"); |
| 1859 | if (!fp) { |
| 1860 | fprintf(stderr, "ds4: failed to open %s for writing: %s\n", path, strerror(errno)); |
| 1861 | return false; |
| 1862 | } |
| 1863 | const size_t nw = fwrite(data, sizeof(float), (size_t)n, fp); |
| 1864 | const bool ok = nw == (size_t)n && fclose(fp) == 0; |
| 1865 | if (!ok) { |
| 1866 | fprintf(stderr, "ds4: failed to write %s\n", path); |
| 1867 | return false; |
| 1868 | } |
| 1869 | return true; |
| 1870 | } |
| 1871 | |
| 1872 | static bool read_f32_binary_file(const char *path, float *data, uint64_t n) { |
| 1873 | struct stat st; |
| 1874 | if (stat(path, &st) != 0) { |
| 1875 | fprintf(stderr, "ds4: failed to stat %s: %s\n", path, strerror(errno)); |
| 1876 | return false; |
| 1877 | } |
| 1878 | if (st.st_size < 0 || (uint64_t)st.st_size != n * sizeof(float)) { |
| 1879 | fprintf(stderr, |
| 1880 | "ds4: %s has size %llu bytes, expected %llu bytes\n", |
| 1881 | path, |
| 1882 | (unsigned long long)st.st_size, |
| 1883 | (unsigned long long)(n * sizeof(float))); |
| 1884 | return false; |
| 1885 | } |
| 1886 | |
| 1887 | FILE *fp = fopen(path, "rb"); |
| 1888 | if (!fp) { |
no test coverage detected