diff --git a/headers/build/host/darwin/dirent.h b/headers/build/host/darwin/dirent.h index 8cae5fcd78..1762e46c84 100644 --- a/headers/build/host/darwin/dirent.h +++ b/headers/build/host/darwin/dirent.h @@ -1,8 +1,10 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT + #include_next + __BEGIN_DECLS DIR* fdopendir(int fd); diff --git a/headers/build/host/darwin/endian.h b/headers/build/host/darwin/endian.h index 2d77f391b2..7be35e8db3 100644 --- a/headers/build/host/darwin/endian.h +++ b/headers/build/host/darwin/endian.h @@ -1,8 +1,10 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN + #include + #define __LITTLE_ENDIAN LITTLE_ENDIAN #define __BIG_ENDIAN BIG_ENDIAN #define __PDP_ENDIAN PDP_ENDIAN diff --git a/headers/build/host/darwin/fcntl.h b/headers/build/host/darwin/fcntl.h index ff123d33e9..5e49d85a0f 100644 --- a/headers/build/host/darwin/fcntl.h +++ b/headers/build/host/darwin/fcntl.h @@ -1,9 +1,11 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL + #include_next #include + /* * Magic value that specify the use of the current working directory * to determine the target of relative file paths in the openat() and diff --git a/headers/build/host/darwin/regex.h b/headers/build/host/darwin/regex.h index e49b38dbfe..932527e5cf 100644 --- a/headers/build/host/darwin/regex.h +++ b/headers/build/host/darwin/regex.h @@ -1,12 +1,14 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX -// Include the darwin port of gnuregex __BEGIN_DECLS +// Include the darwin port of gnuregex + #include + __END_DECLS #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX diff --git a/headers/build/host/darwin/stdio.h b/headers/build/host/darwin/stdio.h index c33a09d457..30ec7eb0fc 100644 --- a/headers/build/host/darwin/stdio.h +++ b/headers/build/host/darwin/stdio.h @@ -1,8 +1,10 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO + #include_next + __BEGIN_DECLS int renameat(int oldFD, const char* oldPath, int newFD, const char* newPath); diff --git a/headers/build/host/darwin/sys/stat.h b/headers/build/host/darwin/sys/stat.h index 1f6ac496d4..4cb4f767fc 100644 --- a/headers/build/host/darwin/sys/stat.h +++ b/headers/build/host/darwin/sys/stat.h @@ -1,9 +1,11 @@ #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) diff --git a/headers/build/host/darwin/unistd.h b/headers/build/host/darwin/unistd.h index 1f4669f4d1..e2838e2b67 100644 --- a/headers/build/host/darwin/unistd.h +++ b/headers/build/host/darwin/unistd.h @@ -1,8 +1,10 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD + #include_next + __BEGIN_DECLS int faccessat(int fd, const char* path, int accessMode, int flag); diff --git a/headers/build/host/freebsd/endian.h b/headers/build/host/freebsd/endian.h index 5a6b5c66c6..2a7e4bdfe8 100644 --- a/headers/build/host/freebsd/endian.h +++ b/headers/build/host/freebsd/endian.h @@ -1,14 +1,16 @@ -#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN -#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN - -// There's no in FreeBSD, but . And the macro naming -// differs. - -#include - -#define __LITTLE_ENDIAN _LITTLE_ENDIAN -#define __BIG_ENDIAN _BIG_ENDIAN -#define __PDP_ENDIAN _PDP_ENDIAN -#define BYTE_ORDER _BYTE_ORDER - -#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN +#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN +#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN + + +// There's no in FreeBSD, but . And the macro naming +// differs. + +#include + + +#define __LITTLE_ENDIAN _LITTLE_ENDIAN +#define __BIG_ENDIAN _BIG_ENDIAN +#define __PDP_ENDIAN _PDP_ENDIAN +#define BYTE_ORDER _BYTE_ORDER + +#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN diff --git a/headers/build/host/freebsd/regex.h b/headers/build/host/freebsd/regex.h index 8d42abfbe0..de68e0a75e 100644 --- a/headers/build/host/freebsd/regex.h +++ b/headers/build/host/freebsd/regex.h @@ -1,8 +1,10 @@ -#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX -#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX - -// There's no in FreeBSD, but . - -#include - -#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX +#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX +#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX + + +// There's no in FreeBSD, but . + +#include + + +#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX diff --git a/headers/build/host/freebsd/sys/stat.h b/headers/build/host/freebsd/sys/stat.h index 5f06ac78ba..3bfd92528d 100644 --- a/headers/build/host/freebsd/sys/stat.h +++ b/headers/build/host/freebsd/sys/stat.h @@ -1,9 +1,11 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT #define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT + #include_next #include + #ifndef UTIME_NOW # define UTIME_NOW (-1) # define UTIME_OMIT (-2) diff --git a/src/build/libroot/Jamfile b/src/build/libroot/Jamfile index 13a53c0ba2..f8cb92d810 100644 --- a/src/build/libroot/Jamfile +++ b/src/build/libroot/Jamfile @@ -47,11 +47,11 @@ if $(HOST_PLATFORM) = cygwin || $(HOST_PLATFORM) = sunos { local hostPlatformSources ; if $(HOST_PLATFORM) = freebsd { - hostPlatformSources = fs_freebsd.c ; + hostPlatformSources = fs_freebsd.cpp ; } if $(HOST_PLATFORM) = darwin { - hostPlatformSources = fs_darwin.c ; + hostPlatformSources = fs_darwin.cpp ; } local librootSources = diff --git a/src/build/libroot/fs_darwin.c b/src/build/libroot/fs_darwin.cpp similarity index 98% rename from src/build/libroot/fs_darwin.c rename to src/build/libroot/fs_darwin.cpp index 57c9fad26f..f381bd0bdd 100644 --- a/src/build/libroot/fs_darwin.c +++ b/src/build/libroot/fs_darwin.cpp @@ -333,14 +333,14 @@ mknodat(int fd, const char *path, mode_t mode, dev_t dev) int renameat(int oldFD, const char* oldPath, int newFD, const char* newPath) { - int ignoreOldFD = 0; - int ignoreNewFD = 0; + bool ignoreOldFD = false; + bool ignoreNewFD = false; if (oldFD == AT_FDCWD || (oldPath != NULL && oldPath[0] == '/')) - ignoreOldFD = 1; + ignoreOldFD = true; if (newFD == AT_FDCWD || (newPath != NULL && newPath[0] == '/')) - ignoreNewFD = 1; + ignoreNewFD = true; if (ignoreOldFD && ignoreNewFD) { // call rename() ignoring the fd's @@ -464,14 +464,14 @@ linkat(int oldFD, const char *oldPath, int newFD, const char *newPath, return -1; } - int ignoreOldFD = 0; - int ignoreNewFD = 0; + bool ignoreOldFD = false; + bool ignoreNewFD = false; if (oldFD == AT_FDCWD || oldPath != NULL && oldPath[0] == '/') - ignoreOldFD = 1; + ignoreOldFD = true; if (newFD == AT_FDCWD || newPath != NULL && newPath[0] == '/') - ignoreNewFD = 1; + ignoreNewFD = true; if (ignoreOldFD && ignoreNewFD) { // call link() ignoring the fd's diff --git a/src/build/libroot/fs_freebsd.c b/src/build/libroot/fs_freebsd.cpp similarity index 95% rename from src/build/libroot/fs_freebsd.c rename to src/build/libroot/fs_freebsd.cpp index 9e4062ce5e..19acdcb704 100644 --- a/src/build/libroot/fs_freebsd.c +++ b/src/build/libroot/fs_freebsd.cpp @@ -4,6 +4,7 @@ * Distributed under the terms of the MIT License. */ + #include "fs_freebsd.h" #include @@ -52,9 +53,12 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) off_t sdCur = lseek(fd, -(cur % sectorSize), SEEK_CUR); if (sdCur == -1) perror("lseek oneblock"); + if (read(fd, tmpBlock, sectorSize) == -1) perror("read oneblock"); + memcpy((char*)buf, tmpBlock + cur % sectorSize, nbytes); + // repos at byte offset of latest wrote block if (lseek(fd, -sectorSize + (cur % sectorSize) + nbytes, SEEK_CUR) == -1) { @@ -68,20 +72,22 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) // Needs to write more than a block char* tmpBlock = (char*)malloc(sectorSize); - + // First block if seek isn't if (seekDiff > 0) { // read entire block at 0 pos if (lseek(fd, -(sectorSize - seekDiff), SEEK_CUR) == -1) perror("lseek seekDiff"); + off_t sdCur = lseek(fd,0,SEEK_CUR); if (sdCur == -1) perror("lseek2 seekDiff"); + if (read(fd, tmpBlock, sectorSize) == -1 ) perror("read seekDiff"); + // alter content memcpy(buf, tmpBlock + (sectorSize - seekDiff), seekDiff); - } // Blocks between @@ -91,15 +97,18 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) perror("read between"); } } - + // Last block if overflow if (nbytesDiff > 0 ) { off_t sdCur = lseek(fd, 0, SEEK_CUR); if (sdCur == -1) perror("lseek last"); + if (read(fd, tmpBlock, sectorSize) == -1) perror("read last"); + memcpy(((char*)buf) + nbytes - nbytesDiff, tmpBlock, nbytesDiff); + // repos at byte offset of latest wrote block if (lseek(fd, -(sectorSize - nbytesDiff), SEEK_CUR) == -1) perror("lseek2 last"); @@ -136,7 +145,6 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) if (seekDiff == 0 && nbytesDiff == 0) { // Not needed but this saves malloc and free operations return write(fd, buf, nbytes); - } else if (cur % sectorSize + nbytes <= sectorSize) { // Write complete in only a block char* tmpBlock = (char*)malloc(sectorSize); @@ -145,14 +153,19 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) off_t sdCur = lseek(fd, -(cur % sectorSize), SEEK_CUR); if (sdCur == -1) perror("lseek oneblock"); + if (pread(fd, tmpBlock, sectorSize, sdCur) == -1) perror("pread oneblock"); + memcpy(tmpBlock + cur % sectorSize, (char*)buf, nbytes); if (write(fd, tmpBlock, sectorSize) == -1) perror("write oneblock"); + // repos at byte offset of latest written block - if (lseek(fd, -sectorSize + (cur % sectorSize) + nbytes, SEEK_CUR) == -1) + if (lseek(fd, -sectorSize + (cur % sectorSize) + nbytes, SEEK_CUR) + == -1) { perror("lseek2 oneblock"); + } free(tmpBlock); @@ -161,27 +174,32 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) // Needs to write more than a block char* tmpBlock = (char*)malloc(sectorSize); - + // First block if seek isn't if (seekDiff > 0) { // read entire block at 0 pos if (lseek(fd, -(sectorSize - seekDiff), SEEK_CUR) == -1) perror("lseek seekDiff"); + off_t sdCur = lseek(fd, 0, SEEK_CUR); if (sdCur == -1) perror("lseek2 seekDiff"); - if (pread(fd, tmpBlock, sectorSize, sdCur) == -1 ) + + if (pread(fd, tmpBlock, sectorSize, sdCur) == -1) perror("pread seekDiff"); + // alter content memcpy(tmpBlock + (sectorSize - seekDiff), buf, seekDiff); - if (write(fd, tmpBlock, sectorSize)==-1) + if (write(fd, tmpBlock, sectorSize) == -1) perror("write seekDiff"); } // Blocks between if ((nbytes - seekDiff) >= sectorSize) { - if (write(fd, ((char*)buf) + seekDiff, nbytes - seekDiff - nbytesDiff) == -1) + if (write(fd, ((char*)buf) + seekDiff, nbytes - seekDiff + - nbytesDiff) == -1) { perror("write between"); + } } // Last block if overflow @@ -213,9 +231,8 @@ ssize_t haiku_freebsd_readv(int fd, const struct iovec *vecs, size_t count) { ssize_t bytesRead = 0; - size_t i = 0; - for (; i < count; i++) { + for (size_t i = 0; i < count; i++) { ssize_t currentRead = haiku_freebsd_read(fd, vecs[i].iov_base, vecs[i].iov_len); @@ -236,9 +253,8 @@ ssize_t haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count) { ssize_t bytesWritten = 0; - size_t i = 0; - for (; i < count; i++) { + for (size_t i = 0; i < count; i++) { ssize_t written = haiku_freebsd_write(fd, vecs[i].iov_base, vecs[i].iov_len);