Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!sunybcs!sbcs!stealth!brnstnd From: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.wizards Subject: Re: of course! Message-ID: <4036@sbcs.sunysb.edu> Date: 23 Nov 89 05:05:00 GMT Sender: news@sbcs.sunysb.edu Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Followup-To: comp.lang.c Distribution: usa Organization: IR Lines: 20 In article <1051@root44.co.uk> gwc@root.co.uk (Geoff Clare) writes: > In article <17303@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes: > > char dir[PATH_MAX]; > > strcpy(dir, path); > > strcat(dir, "/."); > Anyway, > using a maximum length array is rather wasteful - malloc(strlen(path)+3) > would be much better all round. Ummm, no. PATH_MAX is much smaller than the page size on most machines, so it almost certainly won't change the actual memory use of the process. In contrast, malloc(strlen()) is noticeably slower, a bit less readable, and prone to failure. Unless a lot of memory is tied up in such arrays, malloc() isn't worth it. Don't waste dynamic memory for static uses. Followups to comp.lang.c so I don't have to read them. ---Dan