diff --git a/src/libcglue/Makefile.am b/src/libcglue/Makefile.am index c8c2126a..8b8df2d7 100755 --- a/src/libcglue/Makefile.am +++ b/src/libcglue/Makefile.am @@ -29,7 +29,8 @@ GLUE_OBJS = __dummy_passwd.o __psp_heap_blockid.o __psp_free_heap.o _fork.o _wai _rename.o _getpid.o _kill.o _sbrk.o _gettimeofday.o _times.o ftime.o clock_getres.o clock_gettime.o clock_settime.o \ _isatty.o symlink.o truncate.o chmod.o fchmod.o pathconf.o readlink.o utime.o fchown.o _getentropy.o getpwuid.o \ fsync.o getpwnam.o getuid.o geteuid.o basename.o statvfs.o \ - openat.o renameat.o fchmodat.o fstatat.o mkdirat.o faccessat.o fchownat.o linkat.o readlinkat.o unlinkat.o + openat.o renameat.o fchmodat.o fstatat.o mkdirat.o faccessat.o fchownat.o linkat.o readlinkat.o unlinkat.o \ + realpath.o INIT_OBJS = __libpthreadglue_init.o __libcglue_init.o __libcglue_deinit.o _exit.o abort.o exit.o diff --git a/src/libcglue/glue.c b/src/libcglue/glue.c index 8554ce0f..a8fe5738 100755 --- a/src/libcglue/glue.c +++ b/src/libcglue/glue.c @@ -1179,3 +1179,38 @@ int unlinkat(int dirfd, const char *pathname, int flags) } } #endif /* F_unlinkat */ + +#ifdef F_realpath +char *realpath(const char *path, char *resolved_path) +{ + if (path == NULL) { + errno = EINVAL; + return NULL; + } + + if (strlen(path) > PATH_MAX) { + errno = ENAMETOOLONG; + return NULL; + } + + /* check if file or directory exist */ + struct stat st; + if (stat(path, &st) < 0) { + errno = ENOENT; + return NULL; + } + + // if resolved_path arg is NULL, use malloc instead + if (resolved_path == NULL) { + resolved_path = (char *)malloc(PATH_MAX * sizeof(char)); + if (resolved_path == NULL) { + errno = ENOMEM; + return NULL; + } + } + + __path_absolute(path, resolved_path, PATH_MAX); + + return resolved_path; +} +#endif /* F_realpath */ \ No newline at end of file