Blame src/internal/tpax_readlink_impl.h

88751e
/******************************************************/
88751e
/*  tpax: a topological pax implementation            */
88751e
/*  Copyright (C) 2020  Z. Gilboa                     */
88751e
/*  Released under GPLv2 and GPLv3; see COPYING.TPAX. */
88751e
/******************************************************/
88751e
88751e
#ifndef TPAX_READLINK_IMPL_H
88751e
#define TPAX_READLINK_IMPL_H
88751e
88751e
#include <unistd.h>
88751e
#include <errno.h>
88751e
88751e
static inline int tpax_readlink(
88751e
	const char *	restrict path,
88751e
	char *		restrict buf,
88751e
	ssize_t		bufsize)
88751e
{
88751e
	ssize_t ret;
88751e
88751e
	if ((ret = readlink(path,buf,bufsize)) <= 0) {
88751e
		return -1;
88751e
	} else if (ret == bufsize) {
88751e
		errno = ENOBUFS;
88751e
		return -1;
88751e
	} else {
88751e
		buf[ret] = 0;
88751e
		return 0;
88751e
	}
88751e
}
88751e
88751e
#endif