From 538e4b2054e9802ebc860943e0a43baf2ee46741 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 31 Jan 2017 21:01:14 -0500 Subject: Don't trust st_size when reading symlinks Linux /proc, for example, reports a st_size of 0 for everything. It's nice to be able to use -lname on them anyway. --- util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'util.h') diff --git a/util.h b/util.h index 4fd5962..8fa775d 100644 --- a/util.h +++ b/util.h @@ -48,6 +48,19 @@ */ int xreaddir(DIR *dir, struct dirent **de); +/** + * readlinkat() wrapper that dynamically allocates the result. + * + * @param fd + * The base directory descriptor. + * @param path + * The path to the link, relative to fd. + * @param size + * An estimate for the size of the link name (pass 0 if unknown). + * @return The target of the link, allocated with malloc(), or NULL on failure. + */ +char *xreadlinkat(int fd, const char *path, size_t size); + /** * Check if a file descriptor is open. */ -- cgit v1.2.3