xref: /openbsd/lib/libc/sys/rmdir.2 (revision f6aab3d8)
1.\"	$OpenBSD: rmdir.2,v 1.16 2022/02/18 00:15:53 jsg Exp $
2.\"	$NetBSD: rmdir.2,v 1.7 1995/02/27 12:36:30 cgd Exp $
3.\"
4.\" Copyright (c) 1983, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)rmdir.2	8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: February 18 2022 $
34.Dt RMDIR 2
35.Os
36.Sh NAME
37.Nm rmdir
38.Nd remove a directory file
39.Sh SYNOPSIS
40.In unistd.h
41.Ft int
42.Fn rmdir "const char *path"
43.Sh DESCRIPTION
44.Fn rmdir
45removes a directory file
46whose name is given by
47.Fa path .
48The directory must not have any entries other
49than
50.Ql \&.
51and
52.Ql \&.. .
53.Pp
54There is no
55.Fn rmdirat
56function;
57to remove a directory with a path relative to the directory associated
58with a file descriptor use the
59.Xr unlinkat 2
60function with the
61.Dv AT_REMOVEDIR
62flag.
63.Sh RETURN VALUES
64.Rv -std
65.Sh ERRORS
66The named file is removed unless:
67.Bl -tag -width Er
68.It Bq Er ENOTDIR
69A component of the path is not a directory.
70.It Bq Er ENAMETOOLONG
71A component of a pathname exceeded
72.Dv NAME_MAX
73characters, or an entire pathname (including the terminating NUL)
74exceeded
75.Dv PATH_MAX
76bytes.
77.It Bq Er ENOENT
78The named directory does not exist.
79.It Bq Er ELOOP
80Too many symbolic links were encountered in translating the pathname.
81.It Bq Er ENOTEMPTY
82The named directory contains files other than
83.Ql \&.
84and
85.Ql \&..
86in it.
87.It Bq Er EACCES
88Search permission is denied for a component of the path prefix.
89.It Bq Er EACCES
90Write permission is denied on the directory containing the directory
91to be removed.
92.It Bq Er EPERM
93The directory containing the directory to be removed is marked sticky,
94and neither the containing directory nor the directory to be removed
95are owned by the effective user ID.
96.It Bq Er EPERM
97The directory to be removed or the directory containing it has its
98immutable or append-only flag set (see
99.Xr chflags 2 ) .
100.It Bq Er EBUSY
101The directory to be removed is the mount point
102for a mounted file system.
103.It Bq Er EINVAL
104The last path element of the directory to be removed consists of
105.Ql \&. .
106.It Bq Er EIO
107An I/O error occurred while deleting the directory entry
108or deallocating the inode.
109.It Bq Er EROFS
110The directory entry to be removed resides on a read-only file system.
111.It Bq Er EFAULT
112.Fa path
113points outside the process's allocated address space.
114.El
115.Sh SEE ALSO
116.Xr rmdir 1 ,
117.Xr chflags 2 ,
118.Xr mkdir 2 ,
119.Xr unlink 2
120.Sh STANDARDS
121The
122.Fn rmdir
123function conforms to
124.St -p1003.1-2008 .
125.Sh HISTORY
126The
127.Fn rmdir
128function call appeared in
129.Bx 4.1c .
130