home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / os2 / programm / 3810 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  2.0 KB

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: dmm@vnet.ibm.com (dave)
  3. Message-ID: <19920727.080118.726@almaden.ibm.com>
  4. Date: Mon, 27 Jul 92 10:53:09 EDT
  5. Newsgroups: comp.os.os2.programmer
  6. Subject: Re: fopen(f,"r") vs fopen(f,"rb") what's the diff?
  7. Organization: IBM Canada Lab
  8. News-Software: UReply 3.0
  9. X-X-From: dmm@vnet.ibm.com (Dave Mooney)
  10. References: <=!jmdvp.feustel@netcom.com> <92Jul25.163359.18069@acs.ucalgary.ca>
  11. Lines: 36
  12.  
  13.             <1992Jul25.175848.29166@unixg.ubc.ca>
  14.  
  15. In <1992Jul25.175848.29166@unixg.ubc.ca> ochealth writes:
  16. > A number of UNIX programs I have ported to OS/2 using emx or gcc
  17. > choke on binary files, unless I modify them.
  18. >
  19. > for example:
  20. > f = fopen(name,"r") must be changed to f=fopen(name,"rb")
  21. > etc.
  22. >
  23. > I was wondering just what happens when you don't open as binary.
  24. > Will it return EOF when it sees ^Z or what?
  25.  
  26. Opening a file in text mode on OS/2 will cause CR/LF (\r\n) to be turned
  27. into a single LF (\n) character, and will cause the EOF flag to be set
  28. when reading a ^Z (\x1a).
  29.  
  30. > This is sort of troubling to me, since EMX is desing to make porting UNIX easier
  31. >
  32. > Was fopen changed to make it more compatible with OS/2 or what. From what I've
  33. > read "r" and "rb" are handled the same in UNIX.
  34.  
  35. The original Unix utilities should *really* have opened files in binary
  36. mode in the first place.  The way that Unix works causes binary mode to
  37. be identical to text mode, so the utilities' authors got away with
  38. reading binary as text on Unix systems -- the two modes are the same, so
  39. it doesn't matter which one you use.  On OS/2, there *is* a difference,
  40. so you have to be more careful.  If the utilities treat files as binary,
  41. then by all means, change the code so that the fopen() call uses "rb".
  42.  
  43. dave
  44.  
  45. -------------------------------------------------------------------------
  46. Dave Mooney                                              dmm@vnet.ibm.com
  47.  C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario
  48.             "If you've got a blacklist, I want to be on it"
  49.