Implementing basename(1) (Update #1)
Quiz: rewrite basename(1) using expr(1)
Solution: see Solaris' /bin/basename
Can't post the solution here due to copyright constraints
but one first has to come to the idea of implementing all this
in one (1) expr(1) call. Neat!
Thinking about the runtime impact, it seems that an empty
loop of 1000 iterations takes 2.39s on my machine here,
one that calls NetBSD's /bin/basename for 1000 times takes
3.87s and running the shell/expr based implementation takes
7.90s ... i guess that's a reason for staying with the current
binary implementation!
Update #1: Michael Engel(?) wrote me mail pointing me
at the
OpenSolaris CVSweb server
for having a look at the Solaris basename(1) implementation.
Interesting to see that there's an (obviously unused???) C
version.
[Tags: basename]
|