| 1693 | } |
| 1694 | |
| 1695 | CBMLanguage cbm_language_for_file(const char *filename, const char *path) { |
| 1696 | size_t probe = cbm_language_probe_bytes(filename); |
| 1697 | if (probe == 0) { |
| 1698 | return cbm_language_classify(filename, NULL, 0, false, true); |
| 1699 | } |
| 1700 | /* One byte past the probe tells a file that ends there from a longer one. */ |
| 1701 | unsigned char head[LANG_PROBE_CFC + SKIP_ONE]; |
| 1702 | size_t n = 0; |
| 1703 | FILE *f = path ? cbm_fopen(path, "rb") : NULL; |
| 1704 | if (!f) { |
| 1705 | return cbm_language_classify(filename, NULL, 0, false, false); |
| 1706 | } |
| 1707 | n = fread(head, SKIP_ONE, probe + SKIP_ONE, f); |
| 1708 | bool failed = ferror(f) != 0; |
| 1709 | (void)fclose(f); |
| 1710 | bool more = n > probe; |
| 1711 | return cbm_language_classify(filename, head, more ? probe : n, more, !failed); |
| 1712 | } |
no test coverage detected