hrev44524 adds 2 changesets to branch 'master' old head: 7ad72ef6eae1ad8a2ec03043055ca0e649b11f80 new head: efeef5fad7c8a92b0595540a6004113b8df8da12 ---------------------------------------------------------------------------- e4e6891: Cleanup darwin build system some more. * Convert fs_darwin.cpp and fs_freebsd.cpp to C. * Convert extern C calls to __BEGIN_DECLS and __END_DECLS macros * Link rm_attrs with dynamic libroot efeef5f: FreeBSD build fixes cpp => c [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 11 files changed, 65 insertions(+), 83 deletions(-) headers/build/host/darwin/dirent.h | 10 ++-- headers/build/host/darwin/fcntl.h | 10 ++-- headers/build/host/darwin/regex.h | 8 +-- headers/build/host/darwin/stdio.h | 10 ++-- headers/build/host/darwin/sys/stat.h | 4 ++ headers/build/host/darwin/unistd.h | 10 ++-- src/build/libroot/Jamfile | 4 +- src/build/libroot/{fs_darwin.cpp => fs_darwin.c} | 43 ++++++++-------- src/build/libroot/{fs_freebsd.cpp => fs_freebsd.c} | 39 +++++++------- src/build/libroot/fs_freebsd.h | 7 ++- src/tools/Jamfile | 3 -- ############################################################################ Commit: e4e68917c3993aa63a726021dce8e05c80901d09 URL: http://cgit.haiku-os.org/haiku/commit/?id=e4e6891 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Aug 12 15:29:21 2012 UTC Cleanup darwin build system some more. * Convert fs_darwin.cpp and fs_freebsd.cpp to C. * Convert extern C calls to __BEGIN_DECLS and __END_DECLS macros * Link rm_attrs with dynamic libroot ---------------------------------------------------------------------------- diff --git a/headers/build/host/darwin/dirent.h b/headers/build/host/darwin/dirent.h index 296b56c..8cae5fc 100644 --- a/headers/build/host/darwin/dirent.h +++ b/headers/build/host/darwin/dirent.h @@ -1,16 +1,12 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT -#ifdef __cplusplus -extern "C" { -#endif - #include_next <dirent.h> +__BEGIN_DECLS + DIR* fdopendir(int fd); -#ifdef __cplusplus -} -#endif +__END_DECLS #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT diff --git a/headers/build/host/darwin/fcntl.h b/headers/build/host/darwin/fcntl.h index 36810e3..ff123d3 100644 --- a/headers/build/host/darwin/fcntl.h +++ b/headers/build/host/darwin/fcntl.h @@ -1,10 +1,6 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL -#ifdef __cplusplus -extern "C" { -#endif - #include_next <fcntl.h> #include <sys/time.h> @@ -24,11 +20,11 @@ extern "C" { #define AT_SYMLINK_FOLLOW 0x400 /* linkat() */ #define AT_REMOVEDIR 0x800 /* unlinkat() */ +__BEGIN_DECLS + int unlinkat(int fd, const char *path, int flag); int futimesat(int fd, const char *path, const struct timeval times[2]); -#ifdef __cplusplus -} -#endif +__END_DECLS #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL diff --git a/headers/build/host/darwin/regex.h b/headers/build/host/darwin/regex.h index b8c1cef..e49b38d 100644 --- a/headers/build/host/darwin/regex.h +++ b/headers/build/host/darwin/regex.h @@ -3,14 +3,10 @@ // Include the darwin port of gnuregex -#ifdef __cplusplus -extern "C" { -#endif +__BEGIN_DECLS #include </opt/local/include/gnuregex.h> -#ifdef __cplusplus -} -#endif +__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 0843207..c33a09d 100644 --- a/headers/build/host/darwin/stdio.h +++ b/headers/build/host/darwin/stdio.h @@ -1,17 +1,13 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO -#ifdef __cplusplus -extern "C" { -#endif - #include_next <stdio.h> +__BEGIN_DECLS + int renameat(int oldFD, const char* oldPath, int newFD, const char* newPath); int symlinkat(const char *oldPath, int fd, const char *newPath); -#ifdef __cplusplus -} -#endif +__END_DECLS #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO diff --git a/headers/build/host/darwin/sys/stat.h b/headers/build/host/darwin/sys/stat.h index cd742a9..1f6ac49 100644 --- a/headers/build/host/darwin/sys/stat.h +++ b/headers/build/host/darwin/sys/stat.h @@ -25,10 +25,14 @@ # endif #endif +__BEGIN_DECLS + int fchmodat(int fd, const char* path, mode_t mode, 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); +__END_DECLS + #endif /* _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT */ diff --git a/headers/build/host/darwin/unistd.h b/headers/build/host/darwin/unistd.h index c451674..1f4669f 100644 --- a/headers/build/host/darwin/unistd.h +++ b/headers/build/host/darwin/unistd.h @@ -1,20 +1,16 @@ #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD -#ifdef __cplusplus -extern "C" { -#endif - #include_next <unistd.h> +__BEGIN_DECLS + int faccessat(int fd, const char* path, int accessMode, int flag); int fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag); ssize_t readlinkat(int fd, const char *path, char *buffer, size_t bufferSize); int linkat(int oldFD, const char *oldPath, int newFD, const char *newPath, int flag); -#ifdef __cplusplus -} -#endif +__END_DECLS #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD diff --git a/src/build/libroot/Jamfile b/src/build/libroot/Jamfile index f8cb92d..13a53c0 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.cpp ; + hostPlatformSources = fs_freebsd.c ; } if $(HOST_PLATFORM) = darwin { - hostPlatformSources = fs_darwin.cpp ; + hostPlatformSources = fs_darwin.c ; } local librootSources = diff --git a/src/build/libroot/fs_darwin.cpp b/src/build/libroot/fs_darwin.c similarity index 90% rename from src/build/libroot/fs_darwin.cpp rename to src/build/libroot/fs_darwin.c index 3bd669f..57c9fad 100644 --- a/src/build/libroot/fs_darwin.cpp +++ b/src/build/libroot/fs_darwin.c @@ -4,7 +4,6 @@ * Distributed under the terms of the MIT License. */ - #include <dirent.h> #include <errno.h> #include <fcntl.h> @@ -116,7 +115,7 @@ faccessat(int fd, const char* path, int accessMode, int flag) return -1; } - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call access() ignoring fd return (flag & AT_EACCESS) != 0 ? eaccess(path, accessMode) : access(path, accessMode); @@ -146,7 +145,7 @@ fchmodat(int fd, const char* path, mode_t mode, int flag) return -1; } - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call chmod() ignoring fd if ((flag & AT_SYMLINK_NOFOLLOW) != 0) { // fake lchmod() with open() and fchmod() @@ -190,7 +189,7 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag) return -1; } - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call chown() ignoring fd return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lchown(path, owner, group) : chown(path, owner, group); @@ -244,7 +243,7 @@ fstatat(int fd, const char *path, struct stat *st, int flag) return -1; } - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call stat() or lstat() ignoring fd return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lstat(path, st) : stat(path, st); @@ -268,7 +267,7 @@ fstatat(int fd, const char *path, struct stat *st, int flag) int mkdirat(int fd, const char *path, mode_t mode) { - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call mkdir() ignoring fd return mkdir(path, mode); } @@ -290,7 +289,7 @@ mkdirat(int fd, const char *path, mode_t mode) int mkfifoat(int fd, const char *path, mode_t mode) { - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call mkfifo() ignoring fd return mkfifo(path, mode); } @@ -312,7 +311,7 @@ mkfifoat(int fd, const char *path, mode_t mode) int mknodat(int fd, const char *path, mode_t mode, dev_t dev) { - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call mknod() ignoring fd return mknod(path, mode, dev); } @@ -334,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) { - bool ignoreOldFD = false; - bool ignoreNewFD = false; + int ignoreOldFD = 0; + int ignoreNewFD = 0; - if (oldFD == AT_FDCWD || oldPath != NULL && oldPath[0] == '/') - ignoreOldFD = true; + if (oldFD == AT_FDCWD || (oldPath != NULL && oldPath[0] == '/')) + ignoreOldFD = 1; - if (newFD == AT_FDCWD || newPath != NULL && newPath[0] == '/') - ignoreNewFD = true; + if (newFD == AT_FDCWD || (newPath != NULL && newPath[0] == '/')) + ignoreNewFD = 1; if (ignoreOldFD && ignoreNewFD) { // call rename() ignoring the fd's @@ -380,7 +379,7 @@ renameat(int oldFD, const char* oldPath, int newFD, const char* newPath) ssize_t readlinkat(int fd, const char *path, char *buffer, size_t bufferSize) { - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call readlink() ignoring fd return readlink(path, buffer, bufferSize); } @@ -402,7 +401,7 @@ readlinkat(int fd, const char *path, char *buffer, size_t bufferSize) int symlinkat(const char *oldPath, int fd, const char *newPath) { - if (fd == AT_FDCWD || newPath != NULL && newPath[0] == '/') { + if (fd == AT_FDCWD || (newPath != NULL && newPath[0] == '/')) { // call symlink() ignoring fd return symlink(oldPath, newPath); } @@ -431,7 +430,7 @@ unlinkat(int fd, const char *path, int flag) return -1; } - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call rmdir() or unlink() ignoring fd return (flag & AT_REMOVEDIR) != 0 ? rmdir(path) : unlink(path); } @@ -465,14 +464,14 @@ linkat(int oldFD, const char *oldPath, int newFD, const char *newPath, return -1; } - bool ignoreOldFD = false; - bool ignoreNewFD = false; + int ignoreOldFD = 0; + int ignoreNewFD = 0; if (oldFD == AT_FDCWD || oldPath != NULL && oldPath[0] == '/') - ignoreOldFD = true; + ignoreOldFD = 1; if (newFD == AT_FDCWD || newPath != NULL && newPath[0] == '/') - ignoreNewFD = true; + ignoreNewFD = 1; if (ignoreOldFD && ignoreNewFD) { // call link() ignoring the fd's @@ -511,7 +510,7 @@ linkat(int oldFD, const char *oldPath, int newFD, const char *newPath, int futimesat(int fd, const char *path, const struct timeval times[2]) { - if (fd == AT_FDCWD || path != NULL && path[0] == '/') { + if (fd == AT_FDCWD || (path != NULL && path[0] == '/')) { // call utimes() ignoring fd return utimes(path, times); } diff --git a/src/build/libroot/fs_freebsd.cpp b/src/build/libroot/fs_freebsd.c similarity index 98% rename from src/build/libroot/fs_freebsd.cpp rename to src/build/libroot/fs_freebsd.c index 648650e..1fa1c7a 100644 --- a/src/build/libroot/fs_freebsd.cpp +++ b/src/build/libroot/fs_freebsd.c @@ -40,11 +40,10 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) off_t seekDiff = (sectorSize - (cur % sectorSize)) % sectorSize; off_t nbytesDiff = (nbytes - seekDiff) % sectorSize; - + if (seekDiff == 0 && nbytesDiff == 0) { // Not needed but this saves malloc and free operations return read(fd, buf, nbytes); - } else if (cur % sectorSize + nbytes <= sectorSize) { // Read complete in only a block char* tmpBlock = (char*)malloc(sectorSize); @@ -63,9 +62,8 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) } free(tmpBlock); - - return nbytes; + return nbytes; } else { // Needs to write more than a block @@ -88,13 +86,14 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) // Blocks between if ((nbytes - seekDiff) >= sectorSize) { - if (read(fd, ((char*)buf) + seekDiff, nbytes - seekDiff - nbytesDiff) == -1) + if (read(fd, ((char*)buf) + seekDiff, nbytes - seekDiff + - nbytesDiff) == -1) { perror("read between"); + } } // Last block if overflow if (nbytesDiff > 0 ) { - off_t sdCur = lseek(fd, 0, SEEK_CUR); if (sdCur == -1) perror("lseek last"); @@ -107,10 +106,9 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) } free(tmpBlock); - + return nbytes; } - } @@ -157,9 +155,8 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) perror("lseek2 oneblock"); free(tmpBlock); - - return nbytes; + return nbytes; } else { // Needs to write more than a block @@ -179,7 +176,6 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) memcpy(tmpBlock + (sectorSize - seekDiff), buf, seekDiff); if (write(fd, tmpBlock, sectorSize)==-1) perror("write seekDiff"); - } // Blocks between @@ -187,28 +183,29 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) if (write(fd, ((char*)buf) + seekDiff, nbytes - seekDiff - nbytesDiff) == -1) perror("write between"); } - + // Last block if overflow if (nbytesDiff > 0) { - off_t sdCur = lseek(fd, 0, SEEK_CUR); if (sdCur == -1) perror("lseek last"); + if (pread(fd, tmpBlock, sectorSize, sdCur) == -1) perror("pread last"); + memcpy(tmpBlock, ((char*)buf) + nbytes - nbytesDiff, nbytesDiff); if (write(fd, tmpBlock, sectorSize) == -1) perror("write last"); + // repos at byte offset of latest wrote block if (lseek(fd, -(sectorSize - nbytesDiff), SEEK_CUR) == -1) perror("lseek2 last"); } free(tmpBlock); - + return nbytes; } - } diff --git a/src/build/libroot/fs_freebsd.h b/src/build/libroot/fs_freebsd.h index dd94cff..6db2712 100644 --- a/src/build/libroot/fs_freebsd.h +++ b/src/build/libroot/fs_freebsd.h @@ -5,6 +5,7 @@ #ifndef FS_FREEBSD_H #define FS_FREEBSD_H + #include <sys/uio.h> @@ -13,5 +14,4 @@ ssize_t haiku_freebsd_write(int fd, const void *buf, size_t nbytes); ssize_t haiku_freebsd_readv(int fd, const iovec *vecs, size_t count); ssize_t haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count); - -#endif // FS_FREEBSD_H +#endif /* FS_FREEBSD_H */ diff --git a/src/tools/Jamfile b/src/tools/Jamfile index dbb92b2..6c7fe4a 100644 --- a/src/tools/Jamfile +++ b/src/tools/Jamfile @@ -86,8 +86,6 @@ if $(HOST_PLATFORM_BEOS_COMPATIBLE) { BuildPlatformMain <build>mkindex : mkindex.cpp : $(HOST_LIBBE) ; -# We want rm_attrs to be self-contained, so we link against the static libroot. -HOST_LIBROOT on <build>rm_attrs_tmp = $(HOST_STATIC_LIBROOT) ; BuildPlatformMain <build>rm_attrs_tmp : rm_attrs.cpp : $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) ; MakeLocateDebug <build>rm_attrs ; @@ -146,4 +144,3 @@ SubInclude HAIKU_TOP src tools unzip ; SubInclude HAIKU_TOP src tools vmdkimage ; SubInclude HAIKU_TOP src tools unflatten ; SubInclude HAIKU_TOP src tools zip ; - ############################################################################ Revision: hrev44524 Commit: efeef5fad7c8a92b0595540a6004113b8df8da12 URL: http://cgit.haiku-os.org/haiku/commit/?id=efeef5f Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Aug 12 23:32:18 2012 UTC FreeBSD build fixes cpp => c ---------------------------------------------------------------------------- diff --git a/src/build/libroot/fs_freebsd.c b/src/build/libroot/fs_freebsd.c index 1fa1c7a..9e4062c 100644 --- a/src/build/libroot/fs_freebsd.c +++ b/src/build/libroot/fs_freebsd.c @@ -30,7 +30,7 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes) if (S_ISREG(st.st_mode)) return read(fd, buf, nbytes); // Is a file! Good :) - int sectorSize; + uint sectorSize; if (ioctl(fd, DIOCGSECTORSIZE, §orSize) == -1) sectorSize = 512; // If fail, hardcode to 512 for now @@ -122,7 +122,7 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) if (S_ISREG(st.st_mode)) return write(fd, buf, nbytes); // Is a file! Good :) - int sectorSize; + uint sectorSize; if (ioctl(fd, DIOCGSECTORSIZE, §orSize) == -1) sectorSize = 512; // If fail, hardcode do 512 for now @@ -210,11 +210,12 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes) ssize_t -haiku_freebsd_readv(int fd, const iovec *vecs, size_t count) +haiku_freebsd_readv(int fd, const struct iovec *vecs, size_t count) { ssize_t bytesRead = 0; + size_t i = 0; - for (size_t i = 0; i < count; i++) { + for (; i < count; i++) { ssize_t currentRead = haiku_freebsd_read(fd, vecs[i].iov_base, vecs[i].iov_len); @@ -235,8 +236,9 @@ ssize_t haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count) { ssize_t bytesWritten = 0; + size_t i = 0; - for (size_t i = 0; i < count; i++) { + for (; i < count; i++) { ssize_t written = haiku_freebsd_write(fd, vecs[i].iov_base, vecs[i].iov_len); diff --git a/src/build/libroot/fs_freebsd.h b/src/build/libroot/fs_freebsd.h index 6db2712..404edb8 100644 --- a/src/build/libroot/fs_freebsd.h +++ b/src/build/libroot/fs_freebsd.h @@ -5,13 +5,16 @@ #ifndef FS_FREEBSD_H #define FS_FREEBSD_H - #include <sys/uio.h> +__BEGIN_DECLS + ssize_t haiku_freebsd_read(int fd, void *buf, size_t nbytes); ssize_t haiku_freebsd_write(int fd, const void *buf, size_t nbytes); -ssize_t haiku_freebsd_readv(int fd, const iovec *vecs, size_t count); +ssize_t haiku_freebsd_readv(int fd, const struct iovec *vecs, size_t count); ssize_t haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count); +__END_DECLS + #endif /* FS_FREEBSD_H */