2009-11-07 18:55:16 +01:00
|
|
|
/*
|
2015-01-01 19:48:13 +01:00
|
|
|
* Copyright (C) 2003-2015 The Music Player Daemon Project
|
2009-11-07 18:55:16 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
2009-11-08 22:15:22 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2009-11-07 18:55:16 +01:00
|
|
|
*
|
2009-11-08 22:15:22 +01:00
|
|
|
* - Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2009-11-07 18:55:16 +01:00
|
|
|
*
|
2009-11-08 22:15:22 +01:00
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-11-07 18:55:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This library provides easy helper functions for working with file
|
|
|
|
* descriptors. It has wrappers for taking advantage of Linux 2.6
|
|
|
|
* specific features like O_CLOEXEC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FD_UTIL_H
|
|
|
|
#define FD_UTIL_H
|
|
|
|
|
2011-09-19 21:02:29 +02:00
|
|
|
#include "check.h"
|
|
|
|
|
2009-11-07 18:55:16 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2010-08-03 15:55:25 +02:00
|
|
|
#ifndef WIN32
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
2009-11-07 18:55:16 +01:00
|
|
|
struct sockaddr;
|
|
|
|
|
2012-08-22 13:30:09 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-03-15 14:54:02 +01:00
|
|
|
int
|
|
|
|
fd_set_cloexec(int fd, bool enable);
|
|
|
|
|
2009-11-08 21:38:52 +01:00
|
|
|
/**
|
2009-11-08 22:07:14 +01:00
|
|
|
* Wrapper for open(), which sets the CLOEXEC flag (atomically if
|
2009-11-08 21:38:52 +01:00
|
|
|
* supported by the OS).
|
|
|
|
*/
|
2009-11-07 18:55:16 +01:00
|
|
|
int
|
2009-11-10 16:53:24 +01:00
|
|
|
open_cloexec(const char *path_fs, int flags, int mode);
|
2009-11-07 18:55:16 +01:00
|
|
|
|
2009-11-08 21:38:52 +01:00
|
|
|
/**
|
2009-11-08 22:07:14 +01:00
|
|
|
* Wrapper for pipe(), which sets the CLOEXEC flag (atomically if
|
2009-11-08 21:38:52 +01:00
|
|
|
* supported by the OS).
|
2009-11-08 22:11:35 +01:00
|
|
|
*
|
|
|
|
* On systems that supports it (everybody except for Windows), it also
|
|
|
|
* sets the NONBLOCK flag.
|
2009-11-08 21:38:52 +01:00
|
|
|
*/
|
2009-11-07 18:55:16 +01:00
|
|
|
int
|
2009-11-08 22:11:35 +01:00
|
|
|
pipe_cloexec_nonblock(int fd[2]);
|
2009-11-07 18:55:16 +01:00
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_LIBMPDCLIENT
|
2013-11-18 11:35:22 +01:00
|
|
|
/* Avoid symbol conflict with statically linked libmpdclient */
|
|
|
|
#define socket_cloexec_nonblock socket_cloexec_nonblock_noconflict
|
|
|
|
#endif
|
|
|
|
|
2009-11-08 21:38:52 +01:00
|
|
|
/**
|
2009-11-08 22:11:35 +01:00
|
|
|
* Wrapper for socket(), which sets the CLOEXEC and the NONBLOCK flag
|
|
|
|
* (atomically if supported by the OS).
|
2009-11-08 21:38:52 +01:00
|
|
|
*/
|
2009-11-07 18:55:16 +01:00
|
|
|
int
|
2009-11-08 22:11:35 +01:00
|
|
|
socket_cloexec_nonblock(int domain, int type, int protocol);
|
2009-11-07 18:55:16 +01:00
|
|
|
|
2009-11-08 21:38:52 +01:00
|
|
|
/**
|
2009-11-08 22:11:35 +01:00
|
|
|
* Wrapper for accept(), which sets the CLOEXEC and the NONBLOCK flags
|
|
|
|
* (atomically if supported by the OS).
|
2009-11-08 21:38:52 +01:00
|
|
|
*/
|
2009-11-07 18:55:16 +01:00
|
|
|
int
|
2009-11-08 22:11:35 +01:00
|
|
|
accept_cloexec_nonblock(int fd, struct sockaddr *address,
|
|
|
|
size_t *address_length_r);
|
2009-11-07 18:55:16 +01:00
|
|
|
|
2011-09-19 21:04:19 +02:00
|
|
|
/**
|
|
|
|
* Portable wrapper for close(); use closesocket() on WIN32/WinSock.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
close_socket(int fd);
|
|
|
|
|
2012-08-22 13:30:09 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2011-09-19 21:03:08 +02:00
|
|
|
#endif
|