136da5199SPawel Jakub Dawidek /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35e53a4f9SPedro F. Giffuni * 436da5199SPawel Jakub Dawidek * Copyright (c) 2013 The FreeBSD Foundation 536da5199SPawel Jakub Dawidek * 636da5199SPawel Jakub Dawidek * This software was developed by Pawel Jakub Dawidek under sponsorship from 736da5199SPawel Jakub Dawidek * the FreeBSD Foundation. 836da5199SPawel Jakub Dawidek * 936da5199SPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 1036da5199SPawel Jakub Dawidek * modification, are permitted provided that the following conditions 1136da5199SPawel Jakub Dawidek * are met: 1236da5199SPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 1336da5199SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 1436da5199SPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 1536da5199SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 1636da5199SPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 1736da5199SPawel Jakub Dawidek * 1836da5199SPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1936da5199SPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2036da5199SPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2136da5199SPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 2236da5199SPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2336da5199SPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2436da5199SPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2536da5199SPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2636da5199SPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2736da5199SPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2836da5199SPawel Jakub Dawidek * SUCH DAMAGE. 2936da5199SPawel Jakub Dawidek */ 3036da5199SPawel Jakub Dawidek 3136da5199SPawel Jakub Dawidek #ifndef _COMMON_IMPL_H_ 3236da5199SPawel Jakub Dawidek #define _COMMON_IMPL_H_ 3336da5199SPawel Jakub Dawidek 34991666adSMark Johnston #include <errno.h> 35991666adSMark Johnston #include <fcntl.h> 36991666adSMark Johnston #include <stdbool.h> 37991666adSMark Johnston 38991666adSMark Johnston static inline bool 39991666adSMark Johnston fd_is_valid(int fd) 40991666adSMark Johnston { 41991666adSMark Johnston 42991666adSMark Johnston return (fcntl(fd, F_GETFD) != -1 || errno != EBADF); 43991666adSMark Johnston } 4436da5199SPawel Jakub Dawidek 4536da5199SPawel Jakub Dawidek #endif /* !_COMMON_IMPL_H_ */ 46