xref: /openbsd/lib/libpthread/man/sem_open.3 (revision 4bdff4be)
1.\" $OpenBSD: sem_open.3,v 1.12 2023/02/11 21:13:56 jmc Exp $
2.\"
3.\" Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: February 11 2023 $
18.Dt SEM_OPEN 3
19.Os
20.Sh NAME
21.Nm sem_open ,
22.Nm sem_close ,
23.Nm sem_unlink
24.Nd open and close named semaphores
25.Sh SYNOPSIS
26.In semaphore.h
27.Ft sem_t *
28.Fn sem_open "const char *name" "int oflag" "..."
29.Ft int
30.Fn sem_close "sem_t *sem"
31.Ft int
32.Fn sem_unlink "const char *name"
33.Sh DESCRIPTION
34The
35.Fn sem_open
36function opens and returns a named semaphore.
37The
38.Fn sem_close
39function closes a previously opened named semaphore without removing it.
40The
41.Fn sem_unlink
42function removes the named semaphore from the system without closing it.
43.Sh RETURN VALUES
44On success,
45.Fn sem_open
46returns a pointer to a semaphore.
47.Fn sem_close
48and
49.Fn sem_unlink
50return 0 on success.
51.Fn sem_open
52returns SEM_FAILED and sets
53.Va errno
54to indicate an error.
55.Fn sem_close
56and
57.Fn sem_unlink
58return -1 and set
59.Va errno
60to indicate an error.
61.Sh ERRORS
62It is an error to call
63.Fn sem_close
64with an unnamed semaphore or to call
65.Xr sem_destroy 3
66with a named semaphore.
67.Pp
68.Fn sem_open
69may fail if:
70.Bl -tag -width Er
71.It Bq Er ENOSPC
72Insufficient memory is available.
73.It Bq Er EPERM
74An attempt was made to open a shared semaphore owned by another user.
75.El
76.Pp
77.Fn sem_unlink
78may fail for any of the reasons listed in
79.Xr unlink 2 .
80.Sh SEE ALSO
81.Xr sem_destroy 3 ,
82.Xr sem_getvalue 3 ,
83.Xr sem_init 3 ,
84.Xr sem_post 3 ,
85.Xr sem_wait 3
86.Sh STANDARDS
87.Fn sem_open ,
88.Fn sem_close ,
89and
90.Fn sem_unlink
91appear in
92.St -p1003.1-96 .
93This implementation deviates from the standard by permitting less sharing.
94