[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rfc: exposing *at functions to shell

From: Eric Blake
Subject: Re: rfc: exposing *at functions to shell
Date: Wed, 11 Nov 2009 22:53:24 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Mike Frysinger <vapier <at> gentoo.org> writes:

> > cd /tmp
> > mkdir -p sub
> > {
> >   ln --at=4 -sf foo bar   # call symlinkat("foo",4,"bar")
> >   readlink --at=4 -m bar  # call areadlinkat(4,"bar")
> > } 4< sub
> > 
> > would output /tmp/sub/foo.
> isnt this possible today under linux by using /proc/self/fd ?  i'm not 
> suggesting this as a clean/portable replacement, just trying to better 
> understand the proposal.

Yes, with sufficient /proc supprt, the above example would be equivalent to:

cd /tmp
mkdir -p sub
  ln -sf foo /proc/self/4/bar
  readlink -m /proc/self/4/bar
} 4< sub

Without /proc, it's similar to doing everything via absolute or anchored paths 
(or using shell variables for shorthand), but then you lose time with O(n^2) on 
deep nesting of directories, as well as the robustness that the *at functions 
give in the case that some other process is modifying the same hierarchy that 
you are operating on:

cd /tmp
mkdir -p sub
  ln -sf foo "$dir"/bar
  readlink -m "$dir"/bar
} 4< "$dir"

> --at-fd might be a better explicit option without getting too verbose ?


Eric Blake

reply via email to

[Prev in Thread] Current Thread [Next in Thread]