firasuke / cross / slibtool

Forked from cross/slibtool 3 months ago
Clone

Blame src/internal/slibtool_readlink_impl.h

e8159c
/*******************************************************************/
e8159c
/*  slibtool: a skinny libtool implementation, written in C        */
6803d8
/*  Copyright (C) 2016--2018  Z. Gilboa                            */
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