Commit | Line | Data |
---|---|---|
931b8415 CL |
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
3e847271 | 3 | .\" |
931b8415 | 4 | .\" %sccs.include.redist.man% |
3e847271 | 5 | .\" |
931b8415 CL |
6 | .\" @(#)unlink.2 6.3 (Berkeley) %G% |
7 | .\" | |
8 | .Dd | |
9 | .Dt UNLINK 2 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm unlink | |
13 | .Nd remove directory entry | |
14 | .Sh SYNOPSIS | |
15 | .Fd #include <unistd.h> | |
16 | .Ft int | |
17 | .Fn unlink "const char *path" | |
18 | .Sh DESCRIPTION | |
19 | The | |
20 | .Fn unlink | |
21 | function | |
22 | removes the link named by | |
23 | .Fa path | |
24 | from its directory and decrements the link count of the | |
25 | file which was referenced by the link. | |
26 | If that decrement reduces the link count of the file | |
27 | to zero, | |
4c6f63c8 KM |
28 | and no process has the file open, then |
29 | all resources associated with the file are reclaimed. | |
931b8415 CL |
30 | If one or more process have the file open when the last link is removed, |
31 | the link is removed, but the removal of the file is delayed until | |
32 | all references to it have been closed. | |
33 | .Sh RETURN VALUES | |
4c6f63c8 | 34 | Upon successful completion, a value of 0 is returned. |
931b8415 CL |
35 | Otherwise, a value of -1 is returned and |
36 | .Va errno | |
4c6f63c8 | 37 | is set to indicate the error. |
931b8415 CL |
38 | .Sh ERRORS |
39 | The | |
40 | .Fn unlink | |
41 | succeeds unless: | |
42 | .Bl -tag -width ENAMETOOLONGAA | |
43 | .It Bq Er ENOTDIR | |
4c6f63c8 | 44 | A component of the path prefix is not a directory. |
931b8415 | 45 | .It Bq Er EINVAL |
b5984ffe | 46 | The pathname contains a character with the high-order bit set. |
931b8415 | 47 | .It Bq Er ENAMETOOLONG |
b5984ffe KM |
48 | A component of a pathname exceeded 255 characters, |
49 | or an entire path name exceeded 1023 characters. | |
931b8415 | 50 | .It Bq Er ENOENT |
4c6f63c8 | 51 | The named file does not exist. |
931b8415 | 52 | .It Bq Er EACCES |
4c6f63c8 | 53 | Search permission is denied for a component of the path prefix. |
931b8415 | 54 | .It Bq Er EACCES |
4c6f63c8 KM |
55 | Write permission is denied on the directory containing the link |
56 | to be removed. | |
931b8415 | 57 | .It Bq Er ELOOP |
b5984ffe | 58 | Too many symbolic links were encountered in translating the pathname. |
931b8415 | 59 | .It Bq Er EPERM |
4c6f63c8 KM |
60 | The named file is a directory and the effective user ID |
61 | of the process is not the super-user. | |
931b8415 | 62 | .It Bq Er EPERM |
b5984ffe KM |
63 | The directory containing the file is marked sticky, |
64 | and neither the containing directory nor the file to be removed | |
65 | are owned by the effective user ID. | |
931b8415 | 66 | .It Bq Er EBUSY |
4c6f63c8 KM |
67 | The entry to be unlinked is the mount point for a |
68 | mounted file system. | |
931b8415 | 69 | .It Bq Er EIO |
b5984ffe KM |
70 | An I/O error occurred while deleting the directory entry |
71 | or deallocating the inode. | |
931b8415 | 72 | .It Bq Er EROFS |
4c6f63c8 | 73 | The named file resides on a read-only file system. |
931b8415 CL |
74 | .It Bq Er EFAULT |
75 | .Fa Path | |
4c6f63c8 | 76 | points outside the process's allocated address space. |
931b8415 CL |
77 | .El |
78 | .Sh SEE ALSO | |
79 | .Xr close 2 , | |
80 | .Xr link 2 , | |
81 | .Xr rmdir 2 | |
82 | .Sh HISTORY | |
83 | An | |
84 | .Nm | |
85 | function call appeared in Version 6 AT&T UNIX. |