Path: utzoo!attcan!uunet!mcsun!ukc!stc!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.wizards Subject: Re: of course! Message-ID: <1051@root44.co.uk> Date: 20 Nov 89 13:05:00 GMT References: <152@norsat.UUCP> <2586@unisoft.UUCP> <15769@bloom-beacon.MIT.EDU> <17264@rpp386.cactus.org> <4526@ski.cs.vu.nl> <17303@rpp386.cactus.org> Reply-To: gwc@root.co.uk (Geoff Clare) Organization: UniSoft Ltd, London, England Lines: 25 In article <17303@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes: >> isadir(char *path) >> { >> char dir[PATH_MAX]; >> >> strcpy(dir, path); >> strcat(dir, "/."); >> >> return access(dir, 0); >> } > >On the other hand, not all file systems are going to contain `.' and `..'. They don't have to *contain* `.' and `..' for this to work, they only have to interpret them correctly in pathnames. The pathname resolution rules in POSIX.1 guarantee this behaviour. The fact that the strcat() may write past the end of dir[] is more of a problem. Another is that PATH_MAX might not be defined (it should always be obtained via pathconf() in portable applications). Anyway, using a maximum length array is rather wasteful - malloc(strlen(path)+3) would be much better all round. -- Geoff Clare, UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH gwc@root.co.uk (Dumb mailers: ...!uunet!root.co.uk!gwc) Tel: +44-1-315-6600