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