firasuke / cross / slibtool

Forked from cross/slibtool 3 months ago
Clone

Blame src/internal/slibtool_readlink_impl.h

e8159c
/*******************************************************************/
eac61a
/*  slibtool: a strong libtool implementation, written in C        */
49181b
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
e8159c
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
e8159c
/*******************************************************************/
e8159c
089c8b
#ifndef SLIBTOOL_READLINK_IMPL_H
089c8b
#define SLIBTOOL_READLINK_IMPL_H
089c8b
e8159c
#include <unistd.h>
0ee958
#include <errno.h>
e8159c
c81d16
static inline int slbt_readlinkat(
c81d16
	int		fdcwd,
e8159c
	const char *	restrict path,
e8159c
	char *		restrict buf,
e8159c
	ssize_t		bufsize)
e8159c
{
e8159c
	ssize_t ret;
e8159c
c81d16
	if ((ret = readlinkat(fdcwd,path,buf,bufsize)) <= 0) {
e8159c
		return -1;
0ee958
	} else if (ret == bufsize) {
0ee958
		errno = ENOBUFS;
e8159c
		return -1;
0ee958
	} else {
869ddd
		buf[ret] = 0;
e8159c
		return 0;
e8159c
	}
e8159c
}
089c8b
089c8b
#endif