summaryrefslogtreecommitdiffhomepage
path: root/src/util
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-02-19 03:31:04 +0000
committermidipix <writeonce@midipix.org>2024-02-19 03:43:05 +0000
commitd4b2a5603d628ed00a764cb526df02e3a382a0c1 (patch)
tree6a0ef37030e7a96c2ed5fcb691f165ad3b7d2505 /src/util
parent81e06363fd5be411ff34013f1024664f68f66a12 (diff)
downloadslibtool-d4b2a5603d628ed00a764cb526df02e3a382a0c1.tar.bz2
slibtool-d4b2a5603d628ed00a764cb526df02e3a382a0c1.tar.xz
slbt_util_real_path(): rewrite as a wrapper around an internal slbt_realpath().
Diffstat (limited to 'src/util')
-rw-r--r--src/util/slbt_realpath.c88
1 files changed, 2 insertions, 86 deletions
diff --git a/src/util/slbt_realpath.c b/src/util/slbt_realpath.c
index 9e97427..a21a986 100644
--- a/src/util/slbt_realpath.c
+++ b/src/util/slbt_realpath.c
@@ -4,31 +4,7 @@
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
/*******************************************************************/
-#include <fcntl.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <slibtool/slibtool.h>
-
-#include "slibtool_driver_impl.h"
-#include "slibtool_readlink_impl.h"
-
-#ifdef HAVE_SYS_SYSCALL_H
-#include <sys/syscall.h>
-#endif
-
-#ifdef _MIDIPIX_ABI
-#include <sys/fs.h>
-#endif
-
-#ifndef ENOTSUP
-#define ENOTSUP EOPNOTSUPP
-#endif
-
-#ifdef SYS___realpathat
-extern long syscall(int, ...);
-#endif
+#include "slibtool_realpath_impl.h"
int slbt_util_real_path(
int fdat,
@@ -37,65 +13,5 @@ int slbt_util_real_path(
char * buf,
size_t buflen)
{
- int ret;
- int fd;
- int fdproc;
- struct stat st;
- struct stat stproc;
- char procfspath[36];
-
- /* common validation */
- if (!buf || (options & O_CREAT)) {
- errno = EINVAL;
- return -1;
- }
-
- /* framework-based wrapper */
-#ifdef _MIDIPIX_ABI
- return __fs_rpath(fdat,path,options,buf,buflen);
-#endif
-
-#ifdef SYS___realpathat
- return syscall(SYS___realpathat,fdat,path,buf,buflen,0);
-#endif
-
- /* buflen */
- if (buflen < PATH_MAX) {
- errno = ENOBUFS;
- return -1;
- }
-
- /* AT_FDCWD */
- if (fdat == AT_FDCWD) {
- return realpath(path,buf) ? 0 : -1;
- }
-
- /* /proc/self/fd */
- if ((fd = openat(fdat,path,options,0)) < 0)
- return -1;
-
- sprintf(procfspath,"/proc/self/fd/%d",fd);
-
- if (slbt_readlinkat(fdat,procfspath,buf,buflen)) {
- close(fd);
- return -1;
- }
-
- if ((fdproc = openat(AT_FDCWD,buf,options|O_NOFOLLOW,0)) < 0) {
- close(fd);
- errno = ELOOP;
- return -1;
- }
-
- ret = fstat(fd,&st) || fstat(fdproc,&stproc);
-
- close(fd);
- close(fdproc);
-
- if (ret || (st.st_dev != stproc.st_dev) || (st.st_ino != stproc.st_ino)) {
- errno = ENOTSUP;
- return -1;
- }
-
- return 0;
+ return slbt_realpath(fdat,path,options,buf,buflen);
}