Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!usenet.ins.cwru.edu!news From: bammi@dsrgsun.ces.cwru.edu (Jwahar R. Bammi) Newsgroups: comp.os.minix Subject: Re: POSIX headers, which of the below are correct Keywords: POSIX Message-ID: <1989Dec1.233711.24354@usenet.ins.cwru.edu> Date: 1 Dec 89 23:37:11 GMT References: <682@augean.OZ: <22014@princeton.Princeton.EDU> Sender: news@usenet.ins.cwru.edu Reply-To: bammi@dsrgsun.ces.cwru.edu (Jwahar R. Bammi) Organization: Case Western Reserve University Lines: 33 In-reply-to: nfs@notecnirp.Princeton.EDU (Norbert Schlenker) In article <22014@princeton.Princeton.EDU>, nfs@notecnirp (Norbert Schlenker) writes: >The only legal way to do this correctly, I believe, is something like: > >FILE *fopen(const char *path, const char *mode) >{ >... > char localpath[PATH_MAX+1]; >... > strcpy(localpath, path); >... > creat(localpath, 0666); >... >} > >So there is extra overhead (both time and space) for doing this right. >I understand why Earl did what he did; I did almost the same thing for >my package, but had the audacity to ignore gcc's complaints. > with gcc atleast (i dont have access to any other ansi C compiler) you can cast a (const char *) to a (char *) without having to make a local copy. (or vise versa). i dont know for sure if these casts are legal ansi C, but gcc -pedantic does'nt complain. (assuming of course you really want to do that). another thing that struck me as strange (unless it has changed recently) are the protos for strchr, strrchr and the like: the proto says `char *strchr(const char *s, int c)' and what you are really doing is returning either a pointer into s or NULL. should'nt the return type be `const char *' ? or are you really supposed to return a pointer into a writable copy of s? i used casts in all such cases. -- bang: {any internet host}!dsrgsun.ces.CWRU.edu!bammi jwahar r. bammi domain: bammi@dsrgsun.ces.CWRU.edu GEnie: J.Bammi