MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_language_for_file

Function cbm_language_for_file

src/discover/language.c:1695–1712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1693}
1694
1695CBMLanguage 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}

Callers 1

detect_file_languageFunction · 0.85

Calls 4

cbm_language_probe_bytesFunction · 0.85
cbm_language_classifyFunction · 0.85
cbm_fopenFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected