MPD: system/fd_util.h Source File

MPD 0.20.15

fd_util.h
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*
30 * This library provides easy helper functions for working with file
31 * descriptors. It has wrappers for taking advantage of Linux 2.6
32 * specific features like O_CLOEXEC.
33 *
34 */
35
36 #ifndef FD_UTIL_H
37 #define FD_UTIL_H
38
39 #include "check.h"
40
41 #include <stdbool.h>
42 #include <stddef.h>
43
44 #ifndef _WIN32
45 #include <sys/types.h>
46 #endif
47
48 struct sockaddr;
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 int
55 fd_set_cloexec(int fd, bool enable);
56
61 int
62 open_cloexec(const char *path_fs, int flags, int mode);
63
71 int
72 pipe_cloexec_nonblock(int fd[2]);
73
74 #ifdef ENABLE_LIBMPDCLIENT
75 /* Avoid symbol conflict with statically linked libmpdclient */
76 #define socket_cloexec_nonblock socket_cloexec_nonblock_noconflict
77 #endif
78
83 int
84 socket_cloexec_nonblock(int domain, int type, int protocol);
85
90 int
91 accept_cloexec_nonblock(int fd, struct sockaddr *address,
92 size_t *address_length_r);
93
97 int
98 close_socket(int fd);
99
100 #ifdef __cplusplus
101 } /* extern "C" */
102 #endif
103
104 #endif
open_cloexec
int open_cloexec(const char *path_fs, int flags, int mode)
Wrapper for open(), which sets the CLOEXEC flag (atomically if supported by the OS).
check.h
fd_set_cloexec
int fd_set_cloexec(int fd, bool enable)
socket_cloexec_nonblock
int socket_cloexec_nonblock(int domain, int type, int protocol)
Wrapper for socket(), which sets the CLOEXEC and the NONBLOCK flag (atomically if supported by the OS...
pipe_cloexec_nonblock
int pipe_cloexec_nonblock(int fd[2])
Wrapper for pipe(), which sets the CLOEXEC flag (atomically if supported by the OS).
accept_cloexec_nonblock
int accept_cloexec_nonblock(int fd, struct sockaddr *address, size_t *address_length_r)
Wrapper for accept(), which sets the CLOEXEC and the NONBLOCK flags (atomically if supported by the O...
close_socket
int close_socket(int fd)
Portable wrapper for close(); use closesocket() on WIN32/WinSock.