diff options
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -15,8 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this library. If not, see <http://www.gnu.org/licenses/>. */ -#include <stdlib.h> -#include <string.h> +#include <stddef.h> @@ -28,12 +27,16 @@ * @return The duplicate of the memory segment, * `NULL` on error */ -static inline void* memdup(const void* src, size_t n) -{ - void* dest = malloc(n); - if (dest == NULL) - return NULL; - memcpy(dest, src, n); - return dest; -} +void* memdup(const void* src, size_t n); + + +/** + * Read an entire file + * + * @param fd The file descriptor + * @param n Output for the size of the file + * @return The read content, plus a NUL byte at + * the end (not counted in `*n`) + */ +void* nread(int fd, size_t* n); |