- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: rename() doesn't fail
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2003 06:27 PM
03-03-2003 06:27 PM
rename() doesn't fail
Hello there.
I expect rename to fail in the following scenario.
===C program====
main ()
{
printf ("rename returns %d\n",
rename ("a", "b"));
}
let us say the compiled output a.out is available
======================
$ touch a
$ ln a b
$ mv a b <== This fails and echo $? gives 1
$ ./a.out <== The output is "rename returns 0"
Both the files are availble as it is but rename() in a.out is expected to return -1 as per the man page. Why is this not happening? How does "mv" command identifies this problem and exits with 1? Any sure way to rename "a" to "b" irrespective of what "b" is, using a C program?
Thank you,
Vimala
04-Mar-2003
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2003 06:55 PM
03-03-2003 06:55 PM
Re: rename() doesn't fail
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2003 07:00 PM
03-03-2003 07:00 PM
Re: rename() doesn't fail
Thank you for your response.
If "rename" moves the file at low level, why is it still existing? Please help me to understand.
Thanks,
Vimala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2003 07:03 PM
03-03-2003 07:03 PM
Re: rename() doesn't fail
So rename is there for making your own programs. So before you use rename(), do the tests on file..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2003 07:10 PM
03-03-2003 07:10 PM
Re: rename() doesn't fail
mv fails in this case because "b" is a hard-link of "a". That is, all you've done with the ln command is to duplicate the directory table entry. A and B have the same inode. You can see this if you use "ll -i".
So the mv fails because you are essentially trying to replace a file with itself.
I think the rename succeeds because it acts on the directory tbale entries and not on the file itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2003 12:55 AM
03-04-2003 12:55 AM
Re: rename() doesn't fail
The answer is quite easy in this case I think.
Why mv fails in this case? Because it checks this situation.
On my system I have:
$ touch a
$ ln a b
$ mv a b
mv: a and b are identical
hovever
$ touch a
$ touch b
$ mv a b
works.
Remember that mv is somewhat more than just a rename() call, because you can mv your files accross the filesystems (and this means real copying then).
Good luck
Adam