Blame src/internal/tpax_readlink_impl.h

5874a9
/**************************************************************/
5874a9
/*  tpax: a topological pax implementation                    */
5874a9
/*  Copyright (C) 2020--2021  SysDeer Technologies, LLC       */
5874a9
/*  Released under GPLv2 and GPLv3; see COPYING.TPAX.         */
5874a9
/**************************************************************/
88751e
88751e
#ifndef TPAX_READLINK_IMPL_H
88751e
#define TPAX_READLINK_IMPL_H
88751e
88751e
#include <unistd.h>
88751e
#include <errno.h>
88751e
25a377
static inline int tpax_readlinkat(
25a377
	int		fdat,
88751e
	const char *	restrict path,
88751e
	char *		restrict buf,
88751e
	ssize_t		bufsize)
88751e
{
88751e
	ssize_t ret;
88751e
25a377
	if ((ret = readlinkat(fdat,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