Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: is_binary_file() Date: Tue, 09 Dec 2025 15:42:59 -0800 Organization: None to speak of Lines: 38 Message-ID: <87cy4ngr24.fsf@example.invalid> References: <10gvvh8$1vv6e$1@dont-email.me> <10h2t5s$3m1kg$1@paganini.bofh.team> <10h7402$9q1e$6@dont-email.me> <10h76ag$att7$1@dont-email.me> <10h9uo1$127kq$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Date: Tue, 09 Dec 2025 23:43:00 +0000 (UTC) Injection-Info: dont-email.me; posting-host="e1d01dad4c9bd794b428961eda6dbd0c"; logging-data="1233313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I0sHmLM15zQ8oQGLPPLJ3" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:HauUdleg9d78JD/RnG3YYddwOCk= sha1:Xf8TqYagSrLkWMWEXNChYG4Jca4= Xref: csiph.com comp.lang.c:395747 Michael Sanders writes: > On Mon, 8 Dec 2025 18:44:33 +0000, bart wrote: >> It's not clear what the actual problem is. What is the use-case >> for a function that tells you whether any file /might/ be a >> text-file based on speculative analysis of its contents? Is >> the result /meant/ to be fuzzy? > > Hey bart. > > What I mean is that since I have not yet defined a canonical > standard for my program, the goal here (to determine if my code > can parse the file) is unclear. > > It means I need to plan much more *before* I write more code, no > mean feat when one is excited & ready to jump in =) You say you want to parse the file. That implies that you expect the file to have a certain format/syntax, and for parsing to fail on a file that doesn't satisfy the syntax. In that case, I speculate that determining whether the file is text or binary is not useful. The way to determine whether you can parse it is simply to try to parse it, and see whether that succeeds or fails. For example, if I want to parse a file containing a C translation unit, I can feed it to a C compiler (or just a parser if I have one). If the file contains non-text bytes, that's just a special case of a syntactically incorrect input, and the parser will detect it. It should work similarly for whatever format you're trying to parse. I doubt that you need to distinguish between incorrect input that's pure text and incorrect input that's "binary". If I'm right about this (which is by no means certain), you could have saved a lot of time by telling us up front *why* you want to distinguish between "text" and "binary" files. On the other hand, I've seized on the word "parse", and I may be reading too much into it. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */