home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / amiga / programm / 13209 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  2.5 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!spool.mu.edu!agate!ucbvax!IFI.UIO.NO!jkr
  2. From: jkr@IFI.UIO.NO (Johan Kristian Rosenvold)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: fopen() or Open
  5. Message-ID: <199209090902.AAyrsa.ifi.uio.no19108@yrsa.ifi.uio.no>
  6. Date: 9 Sep 92 09:02:11 GMT
  7. Sender: usenet@ucbvax.BERKELEY.EDU
  8. Lines: 47
  9.  
  10. > Please humor me.  Why why should I use AmigaDOS Open() and Close()
  11. > rather than C's fopen() and fclose()?
  12.  
  13. There's a few things to consider about that: If your code is typical
  14. Amiga-only and there's really no question of ever porting this thing to
  15. another system, you might as well use Open. If you .personally. as a
  16. programmer feel that you'll want general C programming competence I'd advice
  17. you to stick with fopen, as well as buy a book like "C Standard Library"
  18. from QUE (IMHO a VERY good book). (This will make your executables larger
  19. since you most often use .some. of the amiga library functions anyway)
  20.  
  21. Recently I got this job of maintainig a piece of code that used a great
  22. mixture of Open, open and fopen. Passing around filehandles thru functions 
  23. was a pain.....  For efficiency reasons I didn't want to commit myself
  24. to a single method, so I solved this problem by using a lot of #defines
  25. based on the standard C library file (fopen) code. Since all of them use
  26. more or less the same parameters you can define yourself away from 
  27. the design issue by using none of the above :-) This method will
  28. ensure a minimum of portability problems if require efficient code
  29. but you need to keep the portability option open. 
  30. (This is only necessary if you want .fast. portable code, if speed isn't
  31. a major issue use fopen)
  32.  
  33. #define MYFILE FILE * (typedef is more appropriate)
  34. #define READONLY "r"
  35. #define FOPEN(name,mode) fopen(name, mode)
  36. #define FCLOSE(handle) fclose(handle)
  37. #define FREAD(buffer,bsize,blocks,handle) fread(buffer,bsize,blocks,handle)
  38.  
  39. If you'd want to use Open instead of fopen you'd have to do .something. like
  40. this (off the back of my head - no flames please)
  41.  
  42. #define MYFILE BPTR
  43. #define READONLY MODE_OLDFILE
  44. #define FOPEN(name,mode) Open(name, mode)
  45. #define FCLOSE(handle) Close(handle)
  46. #define FREAD(buffer,bsize,blocks,handle) FRead(buffer,blocks,bsize,hanel)
  47.  
  48. 2 warnings on this method:
  49. - FGets has different newline processing from fgets. FGets includes \n, fgets
  50.   doesn't.
  51. - You should redefine *all* the functions you're using. If you go with this
  52.   kind of scheme be consistent.
  53.  
  54. Only fools start flame wars on matters of taste.
  55.  
  56. Kristian Rosenvold
  57.