summaryrefslogtreecommitdiffstats
path: root/util.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-01-31 21:01:14 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-01-31 21:01:14 -0500
commit538e4b2054e9802ebc860943e0a43baf2ee46741 (patch)
tree70993ee6abf4d7cc0642bf55a5ea1d7edda4ce05 /util.h
parentab64ca5d29147385b099edb8874d6e101b48c1e0 (diff)
downloadbfs-538e4b2054e9802ebc860943e0a43baf2ee46741.tar.xz
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.
Diffstat (limited to 'util.h')
-rw-r--r--util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/util.h b/util.h
index 4fd5962..8fa775d 100644
--- a/util.h
+++ b/util.h
@@ -49,6 +49,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.
*/
bool isopen(int fd);