home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,364 of 243,242   
   Michael Sanders to Keith Thompson   
   Re: is_binary_file()   
   08 Dec 25 17:46:22   
   
   From: porkchop@invalid.foo   
      
   On Fri, 05 Dec 2025 17:42:30 -0800, Keith Thompson wrote:   
      
   > There is no completely reliable way to do this, but you might be   
   > able to make a reasonable guess.  A binary file might happen to   
   > contain only byte values that represent printable characters.   
      
   I suspected this was going to be the case actually.   
      
   > Please use the term "null bytes", not "NULL bytes".  NULL is a standard   
   > macro that expands to a null pointer constant.   
      
   Okay, will do.   
      
   > It seems odd to say that a file is assumed to be binary if you can't   
   > open it.  I suggest having the function return more than two distinct   
   > values:   
   >   
   > - File seems to be binary   
   > - File seems to be text   
   > - Could be either   
   > - Something went wrong   
   >   
   > An enum is probably a good choice.   
      
   Aye, that's an interesting way to look at it.   
      
   > 0x00 -> '\0'   
   > 0x20 -> ' '   
   > 0x09 -> '\t'   
   > 0x0A -> '\n'   
   > 0x0D -> '\r'   
      
   Well, I got too fancy there...   
      
   > Depending on how far you want to get into it, distinguishing between   
   > text and binary files is anywhere from difficult to literally   
   > impossible.   
      
   Thanks for your expertise Keith, I appreciate your insight.   
      
   --   
   :wq   
   Mike Sanders   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca