156 lines
5.5 KiB
HTML
156 lines
5.5 KiB
HTML
<!--
|
|
Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2013
|
|
The President and Fellows of Harvard College.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions
|
|
are met:
|
|
1. Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
3. Neither the name of the University nor the names of its contributors
|
|
may be used to endorse or promote products derived from this software
|
|
without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
SUCH DAMAGE.
|
|
-->
|
|
<html>
|
|
<head>
|
|
<title>rename</title>
|
|
<link rel="stylesheet" type="text/css" media="all" href="../man.css">
|
|
</head>
|
|
<body bgcolor=#ffffff>
|
|
<h2 align=center>rename</h2>
|
|
<h4 align=center>OS/161 Reference Manual</h4>
|
|
|
|
<h3>Name</h3>
|
|
<p>
|
|
rename - rename or move a file
|
|
</p>
|
|
|
|
<h3>Library</h3>
|
|
<p>
|
|
Standard C Library (libc, -lc)
|
|
</p>
|
|
|
|
<h3>Synopsis</h3>
|
|
<p>
|
|
<tt>#include <unistd.h></tt><br>
|
|
<br>
|
|
<tt>int</tt><br>
|
|
<tt>rename(const char *</tt><em>oldname</em><tt>,
|
|
const char *</tt><em>newname</em><tt>);</tt>
|
|
</p>
|
|
|
|
<h3>Description</h3>
|
|
<p>
|
|
The file (or other object) referenced by <em>oldname</em> is given the
|
|
name <em>newname</em>, and the name <em>oldname</em> is removed. If
|
|
<em>newname</em> already exists, it is removed as well. (The semantics
|
|
for removing files and directories described under
|
|
<A HREF=remove.html>remove</A> and <A HREF=rmdir.html>rmdir</A>
|
|
must be honored.)
|
|
</p>
|
|
|
|
<p>
|
|
If <em>newname</em> exists, it must be a directory if and only if
|
|
<em>oldname</em> also is.
|
|
</p>
|
|
|
|
<p>
|
|
If components of the path prefix of <em>newname</em> do not exist or
|
|
are not directories, rename fails. Additionally, <em>oldname</em> and
|
|
<em>newname</em> must refer to names on the same filesystem.
|
|
</p>
|
|
|
|
<p>
|
|
If <em>oldname</em> and <em>newname</em> are the same file, rename
|
|
succeeds and the state of the filesystem is not altered. This is true
|
|
even if they are not in the same directory. (POSIX says so. This is
|
|
widely considered a bug in POSIX.)
|
|
</p>
|
|
|
|
<p>
|
|
Rename must be atomic; no other process on the system should be able
|
|
to see the filesystem in a state where both (or neither)
|
|
<em>oldname</em> and <em>newname</em> name the file. Additionally, if
|
|
the system crashes, at least one name for the file must remain.
|
|
(If you are implementing a file system with crash recovery, a crash
|
|
during rename must, after recovery, produce a volume where the rename
|
|
has either occurred or not occurred; no intermediate states may be
|
|
exposed.)
|
|
</p>
|
|
|
|
<p>
|
|
If <em>oldname</em> is a directory, <em>newname</em> must not refer to
|
|
a subdirectory of <em>oldname</em>, as this would create a (detached)
|
|
cycle in the directory tree.
|
|
</p>
|
|
|
|
<p>
|
|
Renaming (or overwriting) the <tt>.</tt> or <tt>..</tt> entries in
|
|
directories is prohibited.
|
|
</p>
|
|
|
|
<h3>Return Values</h3>
|
|
<p>
|
|
On success, <tt>rename</tt> returns 0. On error, -1 is returned, and
|
|
<A HREF=errno.html>errno</A> is set according to the error
|
|
encountered.
|
|
</p>
|
|
|
|
<h3>Errors</h3>
|
|
<p>
|
|
The following error codes should be returned under the conditions
|
|
given. Other error codes may be returned for other errors not
|
|
mentioned here.
|
|
|
|
<table width=90%>
|
|
<tr><td width=5% rowspan=13> </td>
|
|
<td width=10% valign=top>ENODEV</td>
|
|
<td>The device prefix of one of the names did
|
|
not exist.</td></tr>
|
|
<tr><td valign=top>ENOTDIR</td> <td>A non-final component of one of the names
|
|
was not a directory.</td></tr>
|
|
<tr><td valign=top>ENOENT</td> <td>A non-final component of <em>newname</em>
|
|
did not exist.</td></tr>
|
|
<tr><td valign=top>ENOENT</td> <td><em>oldname</em> does not exist.</td></tr>
|
|
<tr><td valign=top>ENOTDIR</td> <td><em>oldname</em> is a directory, and
|
|
<em>newname</em> is not.</td></tr>
|
|
<tr><td valign=top>EISDIR</td> <td><em>oldname</em> is not a directory, and
|
|
<em>newname</em> is.</td></tr>
|
|
<tr><td valign=top>ENOTEMPTY</td><td><em>newname</em> is a directory, and it is
|
|
not empty.</td>
|
|
<tr><td valign=top>EXDEV</td> <td>The two names are on different
|
|
filesystems.</td></tr>
|
|
<tr><td valign=top>EINVAL</td> <td><em>newname</em> is a subdirectory of
|
|
<em>oldname</em>.</td></tr>
|
|
<tr><td valign=top>EINVAL</td> <td>An attempt was made to rename a
|
|
<tt>.</tt> or <tt>..</tt> entry.</td></tr>
|
|
<tr><td valign=top>ENOSPC</td> <td>The filesystem involved is full.</td></tr>
|
|
<tr><td valign=top>EIO</td> <td>A hard I/O error occurred.</td></tr>
|
|
<tr><td valign=top>EFAULT</td> <td>One of the arguments was an
|
|
invalid pointer.</td></tr>
|
|
</table>
|
|
</p>
|
|
|
|
<p>
|
|
As with rmdir, attempts to rename with <em>newname</em> equal to
|
|
<tt>..</tt> may generate either EINVAL or ENOTEMPTY.
|
|
</p>
|
|
|
|
</body>
|
|
</html>
|