155714Skris/*- 2280304Sjkim * SPDX-License-Identifier: BSD-2-Clause 3280304Sjkim * 4280304Sjkim * Copyright (c) 2013 The FreeBSD Foundation 555714Skris * All rights reserved. 655714Skris * 755714Skris * This software was developed by Pawel Jakub Dawidek under sponsorship from 855714Skris * the FreeBSD Foundation. 955714Skris * 1055714Skris * Redistribution and use in source and binary forms, with or without 1155714Skris * modification, are permitted provided that the following conditions 1255714Skris * are met: 1355714Skris * 1. Redistributions of source code must retain the above copyright 14280304Sjkim * notice, this list of conditions and the following disclaimer. 1555714Skris * 2. Redistributions in binary form must reproduce the above copyright 1655714Skris * notice, this list of conditions and the following disclaimer in the 1755714Skris * documentation and/or other materials provided with the distribution. 1855714Skris * 1955714Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 2055714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2155714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2255714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 2355714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2455714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2555714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2655714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2755714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2855714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2955714Skris * SUCH DAMAGE. 3055714Skris */ 3155714Skris 3255714Skris#ifndef _COMMON_IMPL_H_ 3355714Skris#define _COMMON_IMPL_H_ 3455714Skris 3555714Skris#include <errno.h> 3655714Skris#include <fcntl.h> 3755714Skris#include <stdbool.h> 3855714Skris 3955714Skrisstatic inline bool 4055714Skrisfd_is_valid(int fd) 4155714Skris{ 4255714Skris 4355714Skris return (fcntl(fd, F_GETFD) != -1 || errno != EBADF); 4455714Skris} 4555714Skris 4655714Skris#endif /* !_COMMON_IMPL_H_ */ 4755714Skris