rename.html 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <html>
  2. <head>
  3. <title>rename</title>
  4. <body bgcolor=#ffffff>
  5. <h2 align=center>rename</h2>
  6. <h4 align=center>OS/161 Reference Manual</h4>
  7. <h3>Name</h3>
  8. rename - rename or move a file
  9. <h3>Library</h3>
  10. Standard C Library (libc, -lc)
  11. <h3>Synopsis</h3>
  12. #include &lt;unistd.h&gt;<br>
  13. <br>
  14. int<br>
  15. rename(const char *<em>oldname</em>, const char *<em>newname</em>);
  16. <h3>Description</h3>
  17. The file (or other object) referenced by <em>oldname</em> is given the
  18. name <em>newname</em>, and the name <em>oldname</em> is removed. If
  19. <em>newname</em> already exists, it is removed as well. (The semantics
  20. for removing files and directories described under
  21. <A HREF=remove.html>remove</A> and <A HREF=rmdir.html>rmdir</A>
  22. must be honored.)
  23. <p>
  24. If <em>newname</em> exists, it must be a directory if and only if
  25. <em>oldname</em> also is.
  26. <p>
  27. If components of the path prefix of <em>newname</em> do not exist or
  28. are not directories, rename fails. Additionally, <em>oldname</em> and
  29. <em>newname</em> must refer to names on the same filesystem.
  30. <p>
  31. If <em>oldname</em> and <em>newname</em> are the same file, rename
  32. succeeds and the state of the filesystem is not altered.
  33. <p>
  34. Rename must be atomic; no other process on the system should be able
  35. to see the filesystem in a state where both (or neither)
  36. <em>oldname</em> and <em>newname</em> name the file. Additionally, if
  37. the system crashes, at least one name for the file must remain.
  38. <p>
  39. If <em>oldname</em> is a directory, <em>newname</em> must not refer to
  40. a subdirectory of <em>oldname</em>, as this would create a cycle in the
  41. directory tree.
  42. <p>
  43. Renaming the "." or ".." entries in directories is prohibited.
  44. <p>
  45. <h3>Return Values</h3>
  46. On success, rename returns 0. On error, -1 is returned, and
  47. <A HREF=errno.html>errno</A> is set according to the error
  48. encountered.
  49. <h3>Errors</h3>
  50. The following error codes should be returned under the conditions
  51. given. Other error codes may be returned for other errors not
  52. mentioned here.
  53. <blockquote><table width=90%>
  54. <td width=10%>&nbsp;</td><td>&nbsp;</td></tr>
  55. <tr><td>ENODEV</td> <td>The device prefix of one of the names did
  56. not exist.</td></tr>
  57. <tr><td>ENOTDIR</td> <td>A non-final component of one of the names
  58. was not a directory.</td></tr>
  59. <tr><td>ENOENT</td> <td>A non-final component of <em>newname</em>
  60. did not exist.</td></tr>
  61. <tr><td>ENOENT</td> <td><em>oldname</em> does not exist.</td></tr>
  62. <tr><td>ENOTDIR</td> <td><em>oldname</em> is a directory, and
  63. <em>newname</em> is not.</td></tr>
  64. <tr><td>EISDIR</td> <td><em>oldname</em> is not a directory, and
  65. <em>newname</em> is.</td></tr>
  66. <tr><td>ENOTEMPTY</td> <td><em>newname</em> is a directory, and it is
  67. not empty.</td>
  68. <tr><td>EXDEV</td> <td>The two names are on different filesystems.</td></tr>
  69. <tr><td>EINVAL</td> <td><em>newname</em> is a subdirectory of
  70. <em>oldname</em>.</td></tr>
  71. <tr><td>EINVAL</td> <td>An attempt was made to rename "."</td></tr>
  72. <tr><td>ENOSPC</td> <td>The filesystem involved is full.</td></tr>
  73. <tr><td>EIO</td> <td>A hard I/O error occurred.</td></tr>
  74. <tr><td>EFAULT</td> <td>One of the arguments was an invalid pointer.</td></tr>
  75. </table></blockquote>
  76. As with rmdir, attempts to rename ".." may generate either EINVAL or
  77. ENOTEMPTY.
  78. </body>
  79. </html>