Ticket #8857: 0003-Add-fdopendir-implementation-for-Darwin.patch

File 0003-Add-fdopendir-implementation-for-Darwin.patch, 1.7 KB (added by nielx, 7 years ago)
  • new file headers/build/host/darwin/dirent.h

    From 96a05c8385d735cd878cad09ae9307629476b890 Mon Sep 17 00:00:00 2001
    From: Niels Sascha Reedijk <niels.reedijk@gmail.com>
    Date: Wed, 8 Aug 2012 23:11:28 +0200
    Subject: [PATCH 3/3] Add fdopendir() implementation for Darwin.
    
    ---
     headers/build/host/darwin/dirent.h |   16 ++++++++++++++++
     src/build/libroot/fs_darwin.cpp    |   23 +++++++++++++++++++++++
     2 files changed, 39 insertions(+)
     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 0000000..ad805f0
    - +  
     1#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
     2#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
     3
     4#ifdef __cplusplus
     5extern "C" {
     6#endif
     7
     8#include_next <dirent.h>
     9
     10DIR *fdopendir(int fd);
     11   
     12#ifdef __cplusplus
     13}
     14#endif
     15
     16#endif  // _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
  • src/build/libroot/fs_darwin.cpp

    diff --git a/src/build/libroot/fs_darwin.cpp b/src/build/libroot/fs_darwin.cpp
    index 1c58577..e5fdd83 100644
    a b fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag) 
    211211}
    212212
    213213
     214DIR *
     215fdopendir(int fd)
     216{
     217    struct stat st;
     218    if (fstat (fd, &st))
     219        return NULL;
     220
     221    if (!S_ISDIR (st.st_mode))
     222    {
     223        errno = ENOTDIR;
     224        return NULL;
     225    }
     226
     227    char path[MAXPATHLEN];
     228    if (fcntl(fd, F_GETPATH, path) < 0) {
     229        // failed to get the path of fd, fcntl() sets errno
     230        return NULL;
     231    }
     232
     233    return opendir(path);
     234}
     235
     236
    214237int
    215238fstatat(int fd, const char *path, struct stat *st, int flag)
    216239{