diff --git a/headers/build/host/darwin/sys/stat.h b/headers/build/host/darwin/sys/stat.h new file mode 100644 index 0000000000..35538445cb --- /dev/null +++ b/headers/build/host/darwin/sys/stat.h @@ -0,0 +1,34 @@ +#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT +#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT + +#include_next + +#include + + +#ifndef UTIME_NOW +# define UTIME_NOW (-1) +# define UTIME_OMIT (-2) + + __BEGIN_DECLS + + /* assume that futimens() and utimensat() aren't available */ + int futimens(int fd, const struct timespec times[2]); + int utimensat(int fd, const char* path, const struct timespec times[2], + int flag); + + __END_DECLS + +# ifndef _HAIKU_BUILD_NO_FUTIMENS +# define _HAIKU_BUILD_NO_FUTIMENS 1 +# endif +# ifndef _HAIKU_BUILD_NO_FUTIMESAT +# define _HAIKU_BUILD_NO_FUTIMESAT 1 +# endif +# ifndef _HAIKU_BUILD_NO_UTIMENSAT +# define _HAIKU_BUILD_NO_UTIMENSAT 1 +# endif +#endif + + +#endif /* _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT */ \ No newline at end of file diff --git a/src/build/libroot/Jamfile b/src/build/libroot/Jamfile index 0104f25cf3..f8cb92d810 100644 --- a/src/build/libroot/Jamfile +++ b/src/build/libroot/Jamfile @@ -50,6 +50,10 @@ if $(HOST_PLATFORM) = freebsd { hostPlatformSources = fs_freebsd.cpp ; } +if $(HOST_PLATFORM) = darwin { + hostPlatformSources = fs_darwin.cpp ; +} + local librootSources = atomic.cpp byteorder.cpp diff --git a/src/build/libroot/fs.cpp b/src/build/libroot/fs.cpp index 5de5bfa0ab..0db65d45f3 100644 --- a/src/build/libroot/fs.cpp +++ b/src/build/libroot/fs.cpp @@ -31,6 +31,8 @@ #if defined(HAIKU_HOST_PLATFORM_FREEBSD) # include "fs_freebsd.h" +#elif defined(HAIKU_HOST_PLATFORM_DARWIN) +# include "fs_darwin.h" #endif @@ -45,6 +47,13 @@ using namespace BPrivate; # define haiku_host_platform_writev haiku_freebsd_writev # define HAIKU_HOST_STAT_ATIM(x) ((x).st_atimespec) # define HAIKU_HOST_STAT_MTIM(x) ((x).st_mtimespec) +#elif defined(HAIKU_HOST_PLATFORM_DARWIN) +# define haiku_host_platform_read read +# define haiku_host_platform_write write +# define haiku_host_platform_readv readv +# define haiku_host_platform_writev writev +# define HAIKU_HOST_STAT_ATIM(x) ((x).st_atimespec) +# define HAIKU_HOST_STAT_MTIM(x) ((x).st_mtimespec) #else # define haiku_host_platform_read read # define haiku_host_platform_write write @@ -65,6 +74,139 @@ using namespace BPrivate; } while (0) +#if defined(_HAIKU_BUILD_NO_FUTIMENS) || defined(_HAIKU_BUILD_NO_FUTIMENS) + +template +static int +utimes_helper(File& file, const struct timespec times[2]) +{ + if (times == NULL) + return file.SetTimes(NULL); + + timeval timeBuffer[2]; + timeBuffer[0].tv_sec = times[0].tv_sec; + timeBuffer[0].tv_usec = times[0].tv_nsec / 1000; + timeBuffer[1].tv_sec = times[1].tv_sec; + timeBuffer[1].tv_usec = times[1].tv_nsec / 1000; + + if (times[0].tv_nsec == UTIME_OMIT || times[1].tv_nsec == UTIME_OMIT) { + struct stat st; + if (file.GetStat(st) != 0) + return -1; + + if (times[0].tv_nsec == UTIME_OMIT && times[1].tv_nsec == UTIME_OMIT) + return 0; + + if (times[0].tv_nsec == UTIME_OMIT) { + timeBuffer[0].tv_sec = st.st_atimespec.tv_sec; + timeBuffer[0].tv_usec = st.st_atimespec.tv_nsec / 1000; + } + + if (times[1].tv_nsec == UTIME_OMIT) { + timeBuffer[1].tv_sec = st.st_mtimespec.tv_sec; + timeBuffer[1].tv_usec = st.st_mtimespec.tv_nsec / 1000; + } + } + + if (times[0].tv_nsec == UTIME_NOW || times[1].tv_nsec == UTIME_NOW) { + timeval now; + gettimeofday(&now, NULL); + + if (times[0].tv_nsec == UTIME_NOW) + timeBuffer[0] = now; + + if (times[1].tv_nsec == UTIME_NOW) + timeBuffer[1] = now; + } + + return file.SetTimes(timeBuffer); +} + +#endif // _HAIKU_BUILD_NO_FUTIMENS || _HAIKU_BUILD_NO_FUTIMENS + + +#ifdef _HAIKU_BUILD_NO_FUTIMENS + +struct FDFile { + FDFile(int fd) + : + fFD(fd) + { + } + + int GetStat(struct stat& _st) + { + return fstat(fFD, &_st); + } + + int SetTimes(const timeval times[2]) + { + return futimes(fFD, times); + } + +private: + int fFD; +}; + + +int +futimens(int fd, const struct timespec times[2]) +{ + FDFile file(fd); + return utimes_helper(file, times); +} + +#endif // _HAIKU_BUILD_NO_FUTIMENS + +#ifdef _HAIKU_BUILD_NO_FUTIMESAT + +int +futimesat(int fd, const char *path, const struct timeval times[2]) { + FDFile file(fd); + return futimes(fd, times); +} + +#endif // _HAIKU_BUILD_NO_FUTIMESAT + +#ifdef _HAIKU_BUILD_NO_UTIMENSAT + +struct FDPathFile { + FDPathFile(int fd, const char* path, int flag) + : + fFD(fd), + fPath(path), + fFlag(flag) + { + } + + int GetStat(struct stat& _st) + { + return fstatat(fFD, fPath, &_st, fFlag); + } + + int SetTimes(const timeval times[2]) + { + // TODO: fFlag (AT_SYMLINK_NOFOLLOW) is not supported here! + return futimesat(fFD, fPath, times); + } + +private: + int fFD; + const char* fPath; + int fFlag; +}; + + +int +utimensat(int fd, const char* path, const struct timespec times[2], int flag) +{ + FDPathFile file(fd, path, flag); + return utimes_helper(file, times); +} + +#endif // _HAIKU_BUILD_NO_UTIMENSAT + + static status_t get_path(dev_t device, ino_t node, const char *name, string &path); diff --git a/src/build/libroot/fs_darwin.cpp b/src/build/libroot/fs_darwin.cpp new file mode 100644 index 0000000000..c6c054010e --- /dev/null +++ b/src/build/libroot/fs_darwin.cpp @@ -0,0 +1,99 @@ +/* + * Copyright 2011, John Scipione, jscipione@gmail.com. + * Distributed under the terms of the MIT License. + */ + +#include "fs_darwin.h" + +#include +#include +#include +#include +#include +#include +#include +#include + + +int +faccessat(int fd, const char* path, int accessMode, int flag) +{ + return 0; +} + + +int +fchmodat(int fd, const char* path, mode_t mode, int flag) +{ + return 0; +} + + +int +fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag) +{ + return 0; +} + + +int +fstatat(int fd, const char *path, struct stat *st, int flag) +{ + return 0; +} + + +int +mkdirat(int fd, const char *path, mode_t mode) +{ + return 0; +} + + +int +mkfifoat(int fd, const char *path, mode_t mode) +{ + return 0; +} + + +int +mknodat(int fd, const char *name, mode_t mode, dev_t dev) +{ + return 0; +} + + +int +renameat(int fromFD, const char* from, int toFD, const char* to) +{ + return 0; +} + + +ssize_t +readlinkat(int fd, const char *path, char *buffer, size_t bufferSize) +{ + return 0; +} + + +int +symlinkat(const char *toPath, int fd, const char *symlinkPath) +{ + return 0; +} + + +int +unlinkat(int fd, const char *path, int flag) +{ + return 0; +} + + +int +linkat(int toFD, const char *toPath, int linkFD, const char *linkPath, int flag) +{ + return 0; +} diff --git a/src/build/libroot/fs_darwin.h b/src/build/libroot/fs_darwin.h new file mode 100644 index 0000000000..0d9dbf950c --- /dev/null +++ b/src/build/libroot/fs_darwin.h @@ -0,0 +1,31 @@ +/* + * Copyright 2011, John Scipione, jscipione@gmail.com. + * Distributed under the terms of the MIT License. + */ +#ifndef FS_DARWIN_H +#define FS_DARWIN_H + +/* flags for the *at() functions */ +#define AT_FDCWD (-1) /* CWD FD for the *at() functions */ + +#define AT_SYMLINK_NOFOLLOW 0x01 /* fstatat(), fchmodat(), fchownat(), + utimensat() */ +#define AT_SYMLINK_FOLLOW 0x02 /* linkat() */ +#define AT_REMOVEDIR 0x04 /* unlinkat() */ +#define AT_EACCESS 0x08 /* faccessat() */ + +int faccessat(int fd, const char* path, int accessMode, int flag); +int fchmodat(int fd, const char* path, mode_t mode, int flag); +int fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag); +int fstatat(int fd, const char *path, struct stat *st, int flag); +int mkdirat(int fd, const char *path, mode_t mode); +int mkfifoat(int fd, const char *path, mode_t mode); +int mknodat(int fd, const char *name, mode_t mode, dev_t dev); +int renameat(int fromFD, const char* from, int toFD, const char* to); + +ssize_t readlinkat(int fd, const char *path, char *buffer, size_t bufferSize); +int symlinkat(const char *toPath, int fd, const char *symlinkPath); +int unlinkat(int fd, const char *path, int flag); +int linkat(int toFD, const char *toPath, int linkFD, const char *linkPath, int flag); + +#endif // FS_DARWIN_H diff --git a/src/build/libroot/fs_freebsd.cpp b/src/build/libroot/fs_freebsd.cpp index 339d8a5dc9..648650ef32 100644 --- a/src/build/libroot/fs_freebsd.cpp +++ b/src/build/libroot/fs_freebsd.cpp @@ -254,127 +254,3 @@ haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count) return bytesWritten; } - - -#if defined(_HAIKU_BUILD_NO_FUTIMENS) || defined(_HAIKU_BUILD_NO_FUTIMENS) - -template -static int -utimes_helper(File& file, const struct timespec times[2]) -{ - if (times == NULL) - return file.SetTimes(NULL); - - timeval timeBuffer[2]; - timeBuffer[0].tv_sec = times[0].tv_sec; - timeBuffer[0].tv_usec = times[0].tv_nsec / 1000; - timeBuffer[1].tv_sec = times[1].tv_sec; - timeBuffer[1].tv_usec = times[1].tv_nsec / 1000; - - if (times[0].tv_nsec == UTIME_OMIT || times[1].tv_nsec == UTIME_OMIT) { - struct stat st; - if (file.GetStat(st) != 0) - return -1; - - if (times[0].tv_nsec == UTIME_OMIT && times[1].tv_nsec == UTIME_OMIT) - return 0; - - if (times[0].tv_nsec == UTIME_OMIT) { - timeBuffer[0].tv_sec = st.st_atimespec.tv_sec; - timeBuffer[0].tv_usec = st.st_atimespec.tv_nsec / 1000; - } - - if (times[1].tv_nsec == UTIME_OMIT) { - timeBuffer[1].tv_sec = st.st_mtimespec.tv_sec; - timeBuffer[1].tv_usec = st.st_mtimespec.tv_nsec / 1000; - } - } - - if (times[0].tv_nsec == UTIME_NOW || times[1].tv_nsec == UTIME_NOW) { - timeval now; - gettimeofday(&now, NULL); - - if (times[0].tv_nsec == UTIME_NOW) - timeBuffer[0] = now; - - if (times[1].tv_nsec == UTIME_NOW) - timeBuffer[1] = now; - } - - return file.SetTimes(timeBuffer); -} - -#endif // _HAIKU_BUILD_NO_FUTIMENS || _HAIKU_BUILD_NO_FUTIMENS - - -#ifdef _HAIKU_BUILD_NO_FUTIMENS - -struct FDFile { - FDFile(int fd) - : - fFD(fd) - { - } - - int GetStat(struct stat& _st) - { - return fstat(fFD, &_st); - } - - int SetTimes(const timeval times[2]) - { - return futimes(fFD, times); - } - -private: - int fFD; -}; - - -int -futimens(int fd, const struct timespec times[2]) -{ - FDFile file(fd); - return utimes_helper(file, times); -} - -#endif // _HAIKU_BUILD_NO_FUTIMENS - - -#ifdef _HAIKU_BUILD_NO_UTIMENSAT - -struct FDPathFile { - FDPathFile(int fd, const char* path, int flag) - : - fFD(fd), - fPath(path), - fFlag(flag) - { - } - - int GetStat(struct stat& _st) - { - return fstatat(fFD, fPath, &_st, fFlag); - } - - int SetTimes(const timeval times[2]) - { - // TODO: fFlag (AT_SYMLINK_NOFOLLOW) is not supported here! - return futimesat(fFD, fPath, times); - } - -private: - int fFD; - const char* fPath; - int fFlag; -}; - - -int -utimensat(int fd, const char* path, const struct timespec times[2], int flag) -{ - FDPathFile file(fd, path, flag); - return utimes_helper(file, times); -} - -#endif // _HAIKU_BUILD_NO_UTIMENSAT diff --git a/src/system/libroot/os/driver_settings.cpp b/src/system/libroot/os/driver_settings.cpp index b62bea0422..8abe187ed3 100644 --- a/src/system/libroot/os/driver_settings.cpp +++ b/src/system/libroot/os/driver_settings.cpp @@ -977,5 +977,5 @@ get_driver_settings(void *handle) // this creates an alias of the above function // unload_driver_settings() is the same as delete_driver_settings() extern "C" __typeof(unload_driver_settings) delete_driver_settings - __attribute__((alias ("unload_driver_settings"))); + __attribute__((weak, alias ("unload_driver_settings")));