[9] | 1 | .\" Copyright (c) 1983 Regents of the University of California.
|
---|
| 2 | .\" All rights reserved. The Berkeley software License Agreement
|
---|
| 3 | .\" specifies the terms and conditions for redistribution.
|
---|
| 4 | .\"
|
---|
| 5 | .\" @(#)rename.2 6.4 (Berkeley) 5/22/86
|
---|
| 6 | .\"
|
---|
| 7 | .TH RENAME 2 "May 22, 1986"
|
---|
| 8 | .UC 5
|
---|
| 9 | .SH NAME
|
---|
| 10 | rename \- change the name of a file
|
---|
| 11 | .SH SYNOPSIS
|
---|
| 12 | .ft B
|
---|
| 13 | .nf
|
---|
| 14 | #include <stdio.h>
|
---|
| 15 |
|
---|
| 16 | int rename(const char *\fIfrom\fP, const char *\fIto\fP)
|
---|
| 17 | .fi
|
---|
| 18 | .ft R
|
---|
| 19 | .SH DESCRIPTION
|
---|
| 20 | .B Rename
|
---|
| 21 | causes the link named
|
---|
| 22 | .I from
|
---|
| 23 | to be renamed as
|
---|
| 24 | .IR to .
|
---|
| 25 | If
|
---|
| 26 | .I to
|
---|
| 27 | exists, then it is first removed.
|
---|
| 28 | Both
|
---|
| 29 | .I from
|
---|
| 30 | and
|
---|
| 31 | .I to
|
---|
| 32 | must be of the same type (that is, both directories or both
|
---|
| 33 | non-directories), and must reside on the same file system.
|
---|
| 34 | .PP
|
---|
| 35 | .B Rename
|
---|
| 36 | guarantees that an instance of
|
---|
| 37 | .I to
|
---|
| 38 | will always exist, even if the system should crash in
|
---|
| 39 | the middle of the operation.
|
---|
| 40 | .PP
|
---|
| 41 | If the final component of
|
---|
| 42 | .I from
|
---|
| 43 | is a symbolic link,
|
---|
| 44 | the symbolic link is renamed,
|
---|
| 45 | not the file or directory to which it points.
|
---|
| 46 | .SH "RETURN VALUE"
|
---|
| 47 | A 0 value is returned if the operation succeeds, otherwise
|
---|
| 48 | .B rename
|
---|
| 49 | returns \-1 and the global variable
|
---|
| 50 | .B errno
|
---|
| 51 | indicates the reason for the failure.
|
---|
| 52 | .SH "ERRORS
|
---|
| 53 | .B Rename
|
---|
| 54 | will fail and neither of the argument files will be
|
---|
| 55 | affected if any of the following are true:
|
---|
| 56 | .TP 15
|
---|
| 57 | [ENAMETOOLONG]
|
---|
| 58 | A path name exceeds PATH_MAX characters.
|
---|
| 59 | .TP 15
|
---|
| 60 | [ENOENT]
|
---|
| 61 | A component of the \fIfrom\fP path does not exist,
|
---|
| 62 | or a path prefix of \fIto\fP does not exist.
|
---|
| 63 | .TP 15
|
---|
| 64 | [EACCES]
|
---|
| 65 | A component of either path prefix denies search permission.
|
---|
| 66 | .TP 15
|
---|
| 67 | [EACCES]
|
---|
| 68 | The requested link requires writing in a directory with a mode
|
---|
| 69 | that denies write permission.
|
---|
| 70 | .TP 15
|
---|
| 71 | [EPERM]
|
---|
| 72 | The directory containing \fIfrom\fP is marked sticky,
|
---|
| 73 | and neither the containing directory nor \fIfrom\fP
|
---|
| 74 | are owned by the effective user ID.
|
---|
| 75 | .TP 15
|
---|
| 76 | [EPERM]
|
---|
| 77 | The \fIto\fP file exists,
|
---|
| 78 | the directory containing \fIto\fP is marked sticky,
|
---|
| 79 | and neither the containing directory nor \fIto\fP
|
---|
| 80 | are owned by the effective user ID.
|
---|
| 81 | .TP 15
|
---|
| 82 | [ELOOP]
|
---|
| 83 | Too many symbolic links were encountered in translating either pathname.
|
---|
| 84 | (Minix-vmd)
|
---|
| 85 | .TP 15
|
---|
| 86 | [ENOTDIR]
|
---|
| 87 | A component of either path prefix is not a directory.
|
---|
| 88 | .TP 15
|
---|
| 89 | [ENOTDIR]
|
---|
| 90 | .I From
|
---|
| 91 | is a directory, but \fIto\fP is not a directory.
|
---|
| 92 | .TP 15
|
---|
| 93 | [EISDIR]
|
---|
| 94 | .I To
|
---|
| 95 | is a directory, but \fIfrom\fP is not a directory.
|
---|
| 96 | .TP 15
|
---|
| 97 | [EXDEV]
|
---|
| 98 | The link named by \fIto\fP and the file named by \fIfrom\fP
|
---|
| 99 | are on different logical devices (file systems).
|
---|
| 100 | .TP 15
|
---|
| 101 | [ENOSPC]
|
---|
| 102 | The directory in which the entry for the new name is being placed
|
---|
| 103 | cannot be extended because there is no space left on the file
|
---|
| 104 | system containing the directory.
|
---|
| 105 | .ig
|
---|
| 106 | .TP 15
|
---|
| 107 | [EDQUOT]
|
---|
| 108 | The directory in which the entry for the new name
|
---|
| 109 | is being placed cannot be extended because the
|
---|
| 110 | user's quota of disk blocks on the file system
|
---|
| 111 | containing the directory has been exhausted.
|
---|
| 112 | ..
|
---|
| 113 | .TP 15
|
---|
| 114 | [EIO]
|
---|
| 115 | An I/O error occurred while making or updating a directory entry.
|
---|
| 116 | .TP 15
|
---|
| 117 | [EROFS]
|
---|
| 118 | The requested link requires writing in a directory on a read-only file
|
---|
| 119 | system.
|
---|
| 120 | .TP 15
|
---|
| 121 | [EFAULT]
|
---|
| 122 | .I Path
|
---|
| 123 | points outside the process's allocated address space.
|
---|
| 124 | .TP 15
|
---|
| 125 | [EINVAL]
|
---|
| 126 | .I From
|
---|
| 127 | is a parent directory of
|
---|
| 128 | .IR to ,
|
---|
| 129 | or an attempt is made to rename ``.'' or ``..''.
|
---|
| 130 | .TP 15
|
---|
| 131 | [ENOTEMPTY]
|
---|
| 132 | .I To
|
---|
| 133 | is a directory and is not empty.
|
---|
| 134 | .SH "SEE ALSO"
|
---|
| 135 | .BR open (2)
|
---|