From 236f43bec5d539cc55b7dc8ba92854a22b454495 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 10 Oct 2015 18:04:09 +0200 Subject: add abspath and relpath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/stdlib.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'include/stdlib.h') diff --git a/include/stdlib.h b/include/stdlib.h index 89712f9..eca92b2 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -93,6 +93,46 @@ lldiv_t lldiv(long long, long long) __GCC_ONLY(__attribute__((const))); +#if !defined(__PORTABLE) +/** + * Get the absolute path of a file. + * It will remove all redundant slashes, all "./":s, + * and all "../":s, but not resolve symbolic links. + * + * This is a slibc extension. + * + * @param file The file. + * @param ref The directory the file's specified path is + * relative, `NULL` for the current working directory. + * @return The file's absolute pathname. Will end with a slash + * if `file` does. (Or if `ref` does but file is empty.) + * + * @throws ENOMEM The process cannot allocate more memory. + */ +char* abspath(const char*, const char*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull(1), malloc))); + +/** + * Get the relative path of a file. + * + * This is a slibc extension. + * + * @param file The file. + * @param ref The file the result shall be relative to, + * `NULL` for the current working directory. + * If and only if this path ends with a slash, + * (or if it is `NULL`,) it will be treated as + * a directory in which a symbolic link, with + * the result as it target, can be located to + * point to `file`. + * + * @throws ENOMEM The process cannot allocate more memory. + */ +char* relpath(const char*, const char*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull(1), malloc))); +#endif + + /* TODO implement rand-functions */ #define RAND_MAX 1 -- cgit v1.2.3-70-g09d2