Add fopendir() to fs_darwin.cpp and fix symlinkat().
This completes 2/3 of #8857 and is courtesy of nielx.
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
|
||||||
|
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include_next <dirent.h>
|
||||||
|
|
||||||
|
DIR* fdopendir(int fd);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
|
||||||
@@ -6,6 +6,6 @@
|
|||||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||||
#define __BIG_ENDIAN BIG_ENDIAN
|
#define __BIG_ENDIAN BIG_ENDIAN
|
||||||
#define __PDP_ENDIAN PDP_ENDIAN
|
#define __PDP_ENDIAN PDP_ENDIAN
|
||||||
#define __BYTE_ORDER BYTE_ORDER
|
#define __BYTE_ORDER BYTE_ORDER
|
||||||
|
|
||||||
#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN
|
#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
/* assume that futimens() and utimensat() aren't available */
|
/* 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 utimensat(int fd, const char* path, const struct timespec times[2],
|
||||||
int flag);
|
int flag);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
int
|
||||||
fstatat(int fd, const char *path, struct stat *st, int flag)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char oldFullPath[MAXPATHLEN];
|
// newPath is relative to the fd
|
||||||
if (get_path(fd, oldPath, oldFullPath) < 0)
|
char newFullPath[MAXPATHLEN];
|
||||||
|
if (get_path(fd, newPath, newFullPath) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return symlink(oldFullPath, newPath);
|
return symlink(oldPath, newFullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user