the file with the empty name ""

Chris Torek chris at mimsy.UUCP
Fri Dec 30 11:19:44 AEST 1988


In article <662 at sbsvax.UUCP> greim at sbsvax.UUCP (Michael Greim) writes:
>If you do something like 'open ("", 1)', how can you tell what really
>happens (short of looking in the kernel text)?

You cannot.  All you can tell are the effects.  To test that it opens
the current directory, rather than the first file in the current
directory (which is normally `.', and hence just another name for the
current directory) you would have to arrange to find a directory
without `.' as the first element.  This is somewhat difficult, and can
cause the kernel to deadlock or panic in some Unixes, but is not
impossible.  If you manage it, you will find that 4BSD kernels treat

	open(""

as

	open the current working directory.

Of course, it is simpler to just peek at ufs_namei.c (in 4.3BSD-tahoe)
and find the following:

	/*
	 * Check for degenerate name (e.g. / or "")
	 * which is a way of talking about a directory,
	 * e.g. like "/." or ".".
	 */
	if (ndp->ni_dent.d_name[0] == '\0') {
		if (flag != LOOKUP || lockparent) {
			u.u_error = EISDIR;
			goto bad;
		}
		FREE(nbp, M_NAMEI);
		return (dp);
	}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.questions mailing list