MPD 0.17~git
|
00001 /* 00002 * Copyright (C) 2003-2011 The Music Player Daemon Project 00003 * http://www.musicpd.org 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 00012 * - Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 00020 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00021 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00022 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00023 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00029 /* 00030 * This library provides easy helper functions for working with file 00031 * descriptors. It has wrappers for taking advantage of Linux 2.6 00032 * specific features like O_CLOEXEC. 00033 * 00034 */ 00035 00036 #ifndef FD_UTIL_H 00037 #define FD_UTIL_H 00038 00039 #include "check.h" 00040 00041 #include <stdbool.h> 00042 #include <stddef.h> 00043 00044 #ifndef WIN32 00045 #if !defined(_GNU_SOURCE) && (defined(HAVE_PIPE2) || defined(HAVE_ACCEPT4)) 00046 #define _GNU_SOURCE 00047 #endif 00048 00049 #include <sys/types.h> 00050 #endif 00051 00052 struct sockaddr; 00053 00058 int 00059 dup_cloexec(int oldfd); 00060 00065 int 00066 open_cloexec(const char *path_fs, int flags, int mode); 00067 00072 int 00073 pipe_cloexec(int fd[2]); 00074 00082 int 00083 pipe_cloexec_nonblock(int fd[2]); 00084 00085 #ifndef WIN32 00086 00091 int 00092 socketpair_cloexec(int domain, int type, int protocol, int sv[2]); 00093 00098 int 00099 socketpair_cloexec_nonblock(int domain, int type, int protocol, int sv[2]); 00100 00101 #endif 00102 00107 int 00108 socket_cloexec_nonblock(int domain, int type, int protocol); 00109 00114 int 00115 accept_cloexec_nonblock(int fd, struct sockaddr *address, 00116 size_t *address_length_r); 00117 00118 00119 #ifndef WIN32 00120 00121 struct msghdr; 00122 00127 ssize_t 00128 recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags); 00129 00130 #endif 00131 00132 #ifdef HAVE_INOTIFY_INIT 00133 00138 int 00139 inotify_init_cloexec(void); 00140 00141 #endif 00142 00146 int 00147 close_socket(int fd); 00148 00149 #endif