Re: chdir/rmdir
- From: Peter Jeremy <peterjeremy@xxxxxxxxxxxxxxxx>
- Date: Sun, 20 Apr 2008 13:07:49 +1000
On Sat, Apr 19, 2008 at 11:02:27AM -0700, Randall Hyde wrote:
Hi,
I recently made a couple of calls like the following
// currently in /x/y/z
chdir( "/x/y" );
rmdir( "/x/y/z" );
Presumably you checked the return codes and both these succeeded.
When I did at "gwd" call, it returned "/x/y/z" along with ENOTDIR.
Is this a known issue?
What do you mean by "gwd"? There's getcwd(3) which uses __getcwd(2) -
but the syscall may fail, in which case getcwd(3) falls back to stat(2)ing
.. until it reaches root and then using directory(3) to translate the
inode numbers to a pathname. And, even if __getcwd(3) succeeds, the
result may need massaging before being returned to the caller.
Note that system calls very rarely both fail and return a value -
normally, any output buffer will be returned untouched if there's an
error.
P.S. I noticed that the man pages said something about using open on
"." and fchdir to more robustly switch back to some previous
directory;
This is for security and reliability reasons: The process can still
get back to the original directory even if components of its pathname
have been renamed.
--
Peter Jeremy
Please excuse any delays as the result of my ISP's inability to implement
an MTA that is either RFC2821-compliant or matches their claimed behaviour.
Attachment:
pgpsiZ9vQnI0y.pgp
Description: PGP signature
- References:
- chdir/rmdir
- From: Randall Hyde
- chdir/rmdir
- Prev by Date: Re: Yarrow's Counter
- Next by Date: symbol table
- Previous by thread: chdir/rmdir
- Next by thread: symbol table
- Index(es):
Relevant Pages
|
|