From ef7e9d6b9bd4959ef8e6f5b324d4a0fbc2870b81 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 11 Aug 2012 17:56:22 -0400 Subject: [PATCH] Add fopendir() to fs_darwin.cpp and fix symlinkat(). This completes 2/3 of #8857 and is courtesy of nielx. --- headers/build/host/darwin/dirent.h | 16 ++++++++++++++ headers/build/host/darwin/endian.h | 2 +- headers/build/host/darwin/sys/stat.h | 2 +- src/build/libroot/fs_darwin.cpp | 31 +++++++++++++++++++++++++--- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 headers/build/host/darwin/dirent.h diff --git a/headers/build/host/darwin/dirent.h b/headers/build/host/darwin/dirent.h new file mode 100644 index 0000000000..9b72874385 --- /dev/null +++ b/headers/build/host/darwin/dirent.h @@ -0,0 +1,16 @@ +#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT +#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT + +#ifdef __cplusplus +extern "C" { +#endif + +#include_next + +DIR* fdopendir(int fd); + +#ifdef __cplusplus +} +#endif + +#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT diff --git a/headers/build/host/darwin/endian.h b/headers/build/host/darwin/endian.h index 7c4f332b16..2d77f391b2 100644 --- a/headers/build/host/darwin/endian.h +++ b/headers/build/host/darwin/endian.h @@ -6,6 +6,6 @@ #define __LITTLE_ENDIAN LITTLE_ENDIAN #define __BIG_ENDIAN BIG_ENDIAN #define __PDP_ENDIAN PDP_ENDIAN -#define __BYTE_ORDER BYTE_ORDER +#define __BYTE_ORDER BYTE_ORDER #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN diff --git a/headers/build/host/darwin/sys/stat.h b/headers/build/host/darwin/sys/stat.h index 04ca945f85..0742c975ca 100644 --- a/headers/build/host/darwin/sys/stat.h +++ b/headers/build/host/darwin/sys/stat.h @@ -14,7 +14,7 @@ __BEGIN_DECLS /* assume that futimens() and utimensat() aren't available */ - int futimens(int fd, const struct timespec times[2]); + int futimens(int fd, const struct timespec times[2]); int utimensat(int fd, const char* path, const struct timespec times[2], int flag); diff --git a/src/build/libroot/fs_darwin.cpp b/src/build/libroot/fs_darwin.cpp index 89eb24471b..115c72dd6e 100644 --- a/src/build/libroot/fs_darwin.cpp +++ b/src/build/libroot/fs_darwin.cpp @@ -213,6 +213,30 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag) } +DIR* +fdopendir(int fd) +{ + struct stat st; + if (fstat(fd, &st)) { + // failed to get the stat info for fd, fstat() sets errno + return NULL; + } + + if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; + return NULL; + } + + char path[MAXPATHLEN]; + if (fcntl(fd, F_GETPATH, path) < 0) { + // failed to get the path of fd, fcntl() sets errno + return NULL; + } + + return opendir(path); +} + + int fstatat(int fd, const char *path, struct stat *st, int flag) { @@ -391,11 +415,12 @@ symlinkat(const char *oldPath, int fd, const char *newPath) return -1; } - char oldFullPath[MAXPATHLEN]; - if (get_path(fd, oldPath, oldFullPath) < 0) + // newPath is relative to the fd + char newFullPath[MAXPATHLEN]; + if (get_path(fd, newPath, newFullPath) < 0) return -1; - return symlink(oldFullPath, newPath); + return symlink(oldPath, newFullPath); }