/usr/include/dnscore/fdtools.h is in libyadifa-dev 2.1.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /*------------------------------------------------------------------------------
*
* Copyright (c) 2011-2016, EURid. All rights reserved.
* The YADIFA TM software product is provided under the BSD 3-clause license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of EURid nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* 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 COPYRIGHT HOLDER 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.
*
*------------------------------------------------------------------------------
*
*/
/** @defgroup dnscoretools Generic Tools
* @ingroup dnscore
* @brief
*
* @{
*/
#ifndef _FDTOOLS_H
#define _FDTOOLS_H
#include <dirent.h>
#include <dnscore/sys_types.h>
#ifndef _DIRENT_HAVE_D_TYPE
#ifndef DT_UNKNOWN
#define DT_UNKNOWN 0
#endif
#ifndef DT_REG
#define DT_REG 8
#endif
#ifndef DT_DIR
#define DT_DIR 10
#endif
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#define US_RATE(x) (0.000001 * (x))
/**
* Writes fully the buffer to the fd
* It will only return a short count for system errors.
* ie: fs full, non-block would block, fd invalid/closed, ...
*/
ssize_t writefully(int fd, const void *buf, size_t count);
/**
* Reads fully the buffer from the fd
* It will only return a short count for system errors.
* ie: fs full, non-block would block, fd invalid/closed, ...
*/
ssize_t readfully(int fd, void *buf, size_t count);
ssize_t writefully_limited(int fd, const void *buf, size_t count, double minimum_rate);
ssize_t readfully_limited(int fd, void *buf, size_t count, double minimum_rate);
/**
* Reads an ASCII text line from fd, stops at EOF or '\n'
*/
ssize_t readtextline(int fd, char *buf, size_t count);
/**
* Deletes a file (see man 2 unlink).
* Handles EINTR and other retry errors.
*
* @param fd
* @return
*/
int unlink_ex(const char *folder, const char *filename);
/**
* Opens a file. (see man 2 open)
* Handles EINTR and other retry errors.
*
* @param fd
* @return
*/
ya_result open_ex(const char *pathname, int flags);
/**
* Opens a file, create if it does not exist. (see man 2 open with O_CREAT)
* Handles EINTR and other retry errors.
*
* @param fd
* @return
*/
ya_result open_create_ex(const char *pathname, int flags, mode_t mode);
/**
* Opens a file, create if it does not exist. (see man 2 open with O_CREAT)
* Handles EINTR and other retry errors.
* This version of open_create_ex does NOT log anything, which is very important sometimes in the logger thread
*
* @param fd
* @return
*/
ya_result open_create_ex_nolog(const char *pathname, int flags, mode_t mode);
/**
* Closes a file descriptor (see man 2 close)
* Handles EINTR and other retry errors.
* At return the file will be closed or not closable.
*
* @param fd
* @return
*/
ya_result close_ex(int fd);
/**
* Returns the size of a file
*
* @param name
* @return
*/
s64 filesize(const char *name);
/**
*
* 0 : not a link
* 1 : a link
* < 0 : error
*/
ya_result file_is_link(const char *name);
/**
*
* @param pathname
* @param mode
* @return
*/
#define MKDIR_EX_PATH_TO_FILE 1 // ie: pathname points to a file, so skip the file part
int mkdir_ex(const char *pathname, mode_t mode, u32 flags);
/**
* Fixes an issue with the dirent not always set as expected.
*
* The type can be set to DT_UNKNOWN instead of file or directory.
* In that case the function will call stats to get the type.
*/
u8 dirent_get_file_type(const char* folder, struct dirent *entry);
#define READDIR_CALLBACK_CONTINUE 0
#define READDIR_CALLBACK_ENTER 1
#define READDIR_CALLBACK_EXIT 2
typedef ya_result readdir_callback(const char *basedir, const char* file, u8 filetype, void *args);
ya_result readdir_forall(const char *basedir, readdir_callback *func, void *args);
#ifdef __cplusplus
}
#endif
#endif /* _FDTOOLS_H */
/** @} */
|