rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* 'access' builtin for rc?
@ 1991-08-01  7:12 DaviD W. Sanderson
  1991-08-01  8:40 ` Boyd Roberts
  0 siblings, 1 reply; 4+ messages in thread
From: DaviD W. Sanderson @ 1991-08-01  7:12 UTC (permalink / raw)
  To: rc

I propose adding (perhaps conditionally) a new builtin for rc to
perform the most common functions of "test" for examining the file
system.  I have in mind those operations I would use "test" for that
are nothing more than an access() or a stat().

There are three reasons I am proposing this.

1) Currently it takes rc about 15 seconds to start up with my current
.rcrc, mostly because I'm doing things like testing whether directories
exist before I put them into my path.

I agree it's possible to test this sort of thing without a builtin, but
using /bin/test makes things sooooooo slow in my startup.

2) There is "prior art".  Many other shells have implemented "test" as
a builtin, for performance reasons.  I am not proposing for rc anything
so complicated as "test", since rc already has ways to examine strings
and process boolean expressions.

3) Byron wanted to see what the opinion of the mailing list would be.

So, I propose the following builtin command:

	access [-rwxaefdbcplguk] path ...

	where:
		-r	read permission (as reported by access())
		-w	write permission (as reported by access())
		-x	execute permission (as reported by access())
		-a	existence (as reported by access())

		-e	existence (as reported by lstat() success)
		-f	ordinary file
		-d	directory
		-b	block special
		-c	char special
		-p	named pipe (fifo)
		-l	symbolic link (maybe -L for visibility??)
		-g	setgid bit set
		-u	setuid bit set
		-k	sticky bit set

	If no test is specified the default is -a.

	If multiple tests are specified the result is the "anding"
	of the results of the individual tests.
	If multiple paths are given the result is the "anding"
	of the results for all of the paths.
	(Put more simply, the first failed test causes "access" to
	short-circuit to failure.)

	Tests like -l or -p will of course always fail on systems
	without these features.

	The non-access() tests use stat() except for -l and -e which
	use lstat() if available.

This command does not worry about handling strings or boolean
expressions as /bin/test does; it concentrates entirely on simple file
system probes.  The reason I propose to allow multiple tests and
multiple paths is that it seems stupid to me to arbitrarily allow only
one, and "anding" the results seems to me the natural thing to do.

Possible other options (getting into feeping creaturism here):

	-N
	-O	These would succeed if all the pathnames AFTER the first
		pathname were newer or older, respectively, than the
		first pathname.  They would fail if only one pathname
		argument was given.  They would also fail if stat()
		failed on any of the pathname arguments.

	-E	"Equivalence".   (Maybe "-I" for "Identical"?)
		Test whether the given pathnames refer to the same file.
		Returns true if all the pathname arguments have the
		same st_dev and st_ino numbers as returned by lstat().
		Vacuously succeeds if only one pathname is given and
		lstat() succeeds.

	-t	Test whether the given file descriptors are ttys.
		In this case the "path" argument(s) would be
		decimal numbers.  For consistency with the other
		options, there would be no default file descriptor
		to test.

	-o	"Or" all the tests instead of "And"ing them.
		This would not only Or the results of all the tests,
		but it would also Or the results for all the paths.
		(e.g. the first successful test would cause "access"
		to short-circuit to a success.)

I could write "access" so that it could be conditionally compiled as a
separate command, for those purists who don't want it in the shell.
(Or simply leave it out, if it isn't wanted.)

My impression (having just thought it up) is that "access" is simple,
small, clean, and consistent (hopefully in the style of rc), and offers
quite a performance improvement for common tests.

I am interested in what the rest of you think about this idea.

DaviD W. Sanderson (dws@cs.wisc.edu)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1991-08-01 21:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-08-01  7:12 'access' builtin for rc? DaviD W. Sanderson
1991-08-01  8:40 ` Boyd Roberts
1991-08-01 14:13   ` Hamish Macdonald
1991-08-01 21:35   ` Dave Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).