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,390 of 243,242   
   James Kuyper to James Kuyper   
   Re: is_binary_file()   
   09 Dec 25 16:29:39   
   
   From: jameskuyper@alumni.caltech.edu   
      
   On 2025-12-06 20:37, James Kuyper wrote:   
   ...   
   > "Data read in from a text stream will necessarily compare equal to the   
   > data that were earlier written out to that stream only if: the data   
   > consist only of printing characters and the control characters   
   > horizontal tab and new-line; no new-line character is immediately   
   > preceded by space characters; and the last character is a new-line   
   > character." (7.23.2p2).   
   >   
   > I believe it therefore makes sense to consider something to be a text   
   > file if it meets those requirements, and otherwise is a binary file.   
   > Note that the last requirement implies that an empty file cannot qualify   
   > as text - at a minimum, it must contain a new-line character.   
   >   
   > This implies the use of the isprint() function; the only other   
   > characters you need to handle specifically are '\t', '\n', and ' '.   
   > Since the result returned by isprint() is locale-dependent, the program   
   > should, at least optionally, use setlocale().   
      
   I just realized an annoying complication. Whatever   
   implementation-specific method is used to indicate end-of-line can only   
   be portably identified as such by opening the file in text mode and   
   looking for the newline characters that it gets converted into. But   
   because of 7.23.2p2, text mode cannot be relied upon for precisely the   
   files we're trying to identify.   
      
   --- 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