of course!

Geoff Clare gwc at root.co.uk
Tue Nov 21 00:05:00 AEST 1989


In article <17303 at rpp386.cactus.org> jfh at 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 at root.co.uk  (Dumb mailers: ...!uunet!root.co.uk!gwc)  Tel: +44-1-315-6600



More information about the Comp.unix.wizards mailing list