Convert fs_host files from c back to cpp and style changes.

* fs_darwin.c => fs_darwin.cpp
* fs_freebsd.c => fs_freebsd.cpp
* use bool instead of int again in fs_darwin.cpp (C => C++)
* declare loop varibles inline again in fs_freebsd.cpp (C => C++)
* 2 newlines between top header gaurd and first #include
* 2 newlines after last #include
* freebsd/endian.h and freebsd/regex.h convert \r\n to just \n
* remove some leading tabs in fs_freebsd.cpp
* add newlines after single line if statement in fs_freebsd.cpp
* 80-char limit fixes in fs_freebsd.cpp
This commit is contained in:
John Scipione
2012-08-13 18:51:59 -04:00
parent 2c2e65ef16
commit 19a18af35e
13 changed files with 82 additions and 46 deletions
+2
View File
@@ -1,8 +1,10 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
#include_next <dirent.h> #include_next <dirent.h>
__BEGIN_DECLS __BEGIN_DECLS
DIR* fdopendir(int fd); DIR* fdopendir(int fd);
+2
View File
@@ -1,8 +1,10 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN
#include <machine/endian.h> #include <machine/endian.h>
#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
+2
View File
@@ -1,9 +1,11 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL
#include_next <fcntl.h> #include_next <fcntl.h>
#include <sys/time.h> #include <sys/time.h>
/* /*
* Magic value that specify the use of the current working directory * Magic value that specify the use of the current working directory
* to determine the target of relative file paths in the openat() and * to determine the target of relative file paths in the openat() and
+3 -1
View File
@@ -1,12 +1,14 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX
// Include the darwin port of gnuregex
__BEGIN_DECLS __BEGIN_DECLS
// Include the darwin port of gnuregex
#include </opt/local/include/gnuregex.h> #include </opt/local/include/gnuregex.h>
__END_DECLS __END_DECLS
#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX #endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX
+2
View File
@@ -1,8 +1,10 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO
#include_next <stdio.h> #include_next <stdio.h>
__BEGIN_DECLS __BEGIN_DECLS
int renameat(int oldFD, const char* oldPath, int newFD, const char* newPath); int renameat(int oldFD, const char* oldPath, int newFD, const char* newPath);
+2
View File
@@ -1,9 +1,11 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT
#include_next <sys/stat.h> #include_next <sys/stat.h>
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef UTIME_NOW #ifndef UTIME_NOW
# define UTIME_NOW (-1) # define UTIME_NOW (-1)
# define UTIME_OMIT (-2) # define UTIME_OMIT (-2)
+2
View File
@@ -1,8 +1,10 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD #ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD #define _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD
#include_next <unistd.h> #include_next <unistd.h>
__BEGIN_DECLS __BEGIN_DECLS
int faccessat(int fd, const char* path, int accessMode, int flag); int faccessat(int fd, const char* path, int accessMode, int flag);
+16 -14
View File
@@ -1,14 +1,16 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN #ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN
#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN #define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN
// There's no <endian.h> in FreeBSD, but <sys/endian.h>. And the macro naming
// differs. // There's no <endian.h> in FreeBSD, but <sys/endian.h>. And the macro naming
// differs.
#include <sys/endian.h>
#include <sys/endian.h>
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
#define __BIG_ENDIAN _BIG_ENDIAN
#define __PDP_ENDIAN _PDP_ENDIAN #define __LITTLE_ENDIAN _LITTLE_ENDIAN
#define BYTE_ORDER _BYTE_ORDER #define __BIG_ENDIAN _BIG_ENDIAN
#define __PDP_ENDIAN _PDP_ENDIAN
#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN #define BYTE_ORDER _BYTE_ORDER
#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_ENDIAN
+10 -8
View File
@@ -1,8 +1,10 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX #ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX #define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
// There's no <regex.h> in FreeBSD, but <gnu/regex.h>.
// There's no <regex.h> in FreeBSD, but <gnu/regex.h>.
#include <gnu/regex.h>
#include <gnu/regex.h>
#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
+2
View File
@@ -1,9 +1,11 @@
#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT #ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT
#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT #define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT
#include_next <sys/stat.h> #include_next <sys/stat.h>
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef UTIME_NOW #ifndef UTIME_NOW
# define UTIME_NOW (-1) # define UTIME_NOW (-1)
# define UTIME_OMIT (-2) # define UTIME_OMIT (-2)
+2 -2
View File
@@ -47,11 +47,11 @@ if $(HOST_PLATFORM) = cygwin || $(HOST_PLATFORM) = sunos {
local hostPlatformSources ; local hostPlatformSources ;
if $(HOST_PLATFORM) = freebsd { if $(HOST_PLATFORM) = freebsd {
hostPlatformSources = fs_freebsd.c ; hostPlatformSources = fs_freebsd.cpp ;
} }
if $(HOST_PLATFORM) = darwin { if $(HOST_PLATFORM) = darwin {
hostPlatformSources = fs_darwin.c ; hostPlatformSources = fs_darwin.cpp ;
} }
local librootSources = local librootSources =
@@ -333,14 +333,14 @@ mknodat(int fd, const char *path, mode_t mode, dev_t dev)
int int
renameat(int oldFD, const char* oldPath, int newFD, const char* newPath) renameat(int oldFD, const char* oldPath, int newFD, const char* newPath)
{ {
int ignoreOldFD = 0; bool ignoreOldFD = false;
int ignoreNewFD = 0; bool ignoreNewFD = false;
if (oldFD == AT_FDCWD || (oldPath != NULL && oldPath[0] == '/')) if (oldFD == AT_FDCWD || (oldPath != NULL && oldPath[0] == '/'))
ignoreOldFD = 1; ignoreOldFD = true;
if (newFD == AT_FDCWD || (newPath != NULL && newPath[0] == '/')) if (newFD == AT_FDCWD || (newPath != NULL && newPath[0] == '/'))
ignoreNewFD = 1; ignoreNewFD = true;
if (ignoreOldFD && ignoreNewFD) { if (ignoreOldFD && ignoreNewFD) {
// call rename() ignoring the fd's // call rename() ignoring the fd's
@@ -464,14 +464,14 @@ linkat(int oldFD, const char *oldPath, int newFD, const char *newPath,
return -1; return -1;
} }
int ignoreOldFD = 0; bool ignoreOldFD = false;
int ignoreNewFD = 0; bool ignoreNewFD = false;
if (oldFD == AT_FDCWD || oldPath != NULL && oldPath[0] == '/') if (oldFD == AT_FDCWD || oldPath != NULL && oldPath[0] == '/')
ignoreOldFD = 1; ignoreOldFD = true;
if (newFD == AT_FDCWD || newPath != NULL && newPath[0] == '/') if (newFD == AT_FDCWD || newPath != NULL && newPath[0] == '/')
ignoreNewFD = 1; ignoreNewFD = true;
if (ignoreOldFD && ignoreNewFD) { if (ignoreOldFD && ignoreNewFD) {
// call link() ignoring the fd's // call link() ignoring the fd's
@@ -4,6 +4,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "fs_freebsd.h" #include "fs_freebsd.h"
#include <errno.h> #include <errno.h>
@@ -52,9 +53,12 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes)
off_t sdCur = lseek(fd, -(cur % sectorSize), SEEK_CUR); off_t sdCur = lseek(fd, -(cur % sectorSize), SEEK_CUR);
if (sdCur == -1) if (sdCur == -1)
perror("lseek oneblock"); perror("lseek oneblock");
if (read(fd, tmpBlock, sectorSize) == -1) if (read(fd, tmpBlock, sectorSize) == -1)
perror("read oneblock"); perror("read oneblock");
memcpy((char*)buf, tmpBlock + cur % sectorSize, nbytes); memcpy((char*)buf, tmpBlock + cur % sectorSize, nbytes);
// repos at byte offset of latest wrote block // repos at byte offset of latest wrote block
if (lseek(fd, -sectorSize + (cur % sectorSize) + nbytes, SEEK_CUR) if (lseek(fd, -sectorSize + (cur % sectorSize) + nbytes, SEEK_CUR)
== -1) { == -1) {
@@ -68,20 +72,22 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes)
// Needs to write more than a block // Needs to write more than a block
char* tmpBlock = (char*)malloc(sectorSize); char* tmpBlock = (char*)malloc(sectorSize);
// First block if seek isn't // First block if seek isn't
if (seekDiff > 0) { if (seekDiff > 0) {
// read entire block at 0 pos // read entire block at 0 pos
if (lseek(fd, -(sectorSize - seekDiff), SEEK_CUR) == -1) if (lseek(fd, -(sectorSize - seekDiff), SEEK_CUR) == -1)
perror("lseek seekDiff"); perror("lseek seekDiff");
off_t sdCur = lseek(fd,0,SEEK_CUR); off_t sdCur = lseek(fd,0,SEEK_CUR);
if (sdCur == -1) if (sdCur == -1)
perror("lseek2 seekDiff"); perror("lseek2 seekDiff");
if (read(fd, tmpBlock, sectorSize) == -1 ) if (read(fd, tmpBlock, sectorSize) == -1 )
perror("read seekDiff"); perror("read seekDiff");
// alter content // alter content
memcpy(buf, tmpBlock + (sectorSize - seekDiff), seekDiff); memcpy(buf, tmpBlock + (sectorSize - seekDiff), seekDiff);
} }
// Blocks between // Blocks between
@@ -91,15 +97,18 @@ haiku_freebsd_read(int fd, void *buf, size_t nbytes)
perror("read between"); perror("read between");
} }
} }
// Last block if overflow // Last block if overflow
if (nbytesDiff > 0 ) { if (nbytesDiff > 0 ) {
off_t sdCur = lseek(fd, 0, SEEK_CUR); off_t sdCur = lseek(fd, 0, SEEK_CUR);
if (sdCur == -1) if (sdCur == -1)
perror("lseek last"); perror("lseek last");
if (read(fd, tmpBlock, sectorSize) == -1) if (read(fd, tmpBlock, sectorSize) == -1)
perror("read last"); perror("read last");
memcpy(((char*)buf) + nbytes - nbytesDiff, tmpBlock, nbytesDiff); memcpy(((char*)buf) + nbytes - nbytesDiff, tmpBlock, nbytesDiff);
// repos at byte offset of latest wrote block // repos at byte offset of latest wrote block
if (lseek(fd, -(sectorSize - nbytesDiff), SEEK_CUR) == -1) if (lseek(fd, -(sectorSize - nbytesDiff), SEEK_CUR) == -1)
perror("lseek2 last"); perror("lseek2 last");
@@ -136,7 +145,6 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes)
if (seekDiff == 0 && nbytesDiff == 0) { if (seekDiff == 0 && nbytesDiff == 0) {
// Not needed but this saves malloc and free operations // Not needed but this saves malloc and free operations
return write(fd, buf, nbytes); return write(fd, buf, nbytes);
} else if (cur % sectorSize + nbytes <= sectorSize) { } else if (cur % sectorSize + nbytes <= sectorSize) {
// Write complete in only a block // Write complete in only a block
char* tmpBlock = (char*)malloc(sectorSize); 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); off_t sdCur = lseek(fd, -(cur % sectorSize), SEEK_CUR);
if (sdCur == -1) if (sdCur == -1)
perror("lseek oneblock"); perror("lseek oneblock");
if (pread(fd, tmpBlock, sectorSize, sdCur) == -1) if (pread(fd, tmpBlock, sectorSize, sdCur) == -1)
perror("pread oneblock"); perror("pread oneblock");
memcpy(tmpBlock + cur % sectorSize, (char*)buf, nbytes); memcpy(tmpBlock + cur % sectorSize, (char*)buf, nbytes);
if (write(fd, tmpBlock, sectorSize) == -1) if (write(fd, tmpBlock, sectorSize) == -1)
perror("write oneblock"); perror("write oneblock");
// repos at byte offset of latest written block // 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"); perror("lseek2 oneblock");
}
free(tmpBlock); free(tmpBlock);
@@ -161,27 +174,32 @@ haiku_freebsd_write(int fd, const void *buf, size_t nbytes)
// Needs to write more than a block // Needs to write more than a block
char* tmpBlock = (char*)malloc(sectorSize); char* tmpBlock = (char*)malloc(sectorSize);
// First block if seek isn't // First block if seek isn't
if (seekDiff > 0) { if (seekDiff > 0) {
// read entire block at 0 pos // read entire block at 0 pos
if (lseek(fd, -(sectorSize - seekDiff), SEEK_CUR) == -1) if (lseek(fd, -(sectorSize - seekDiff), SEEK_CUR) == -1)
perror("lseek seekDiff"); perror("lseek seekDiff");
off_t sdCur = lseek(fd, 0, SEEK_CUR); off_t sdCur = lseek(fd, 0, SEEK_CUR);
if (sdCur == -1) if (sdCur == -1)
perror("lseek2 seekDiff"); perror("lseek2 seekDiff");
if (pread(fd, tmpBlock, sectorSize, sdCur) == -1 )
if (pread(fd, tmpBlock, sectorSize, sdCur) == -1)
perror("pread seekDiff"); perror("pread seekDiff");
// alter content // alter content
memcpy(tmpBlock + (sectorSize - seekDiff), buf, seekDiff); memcpy(tmpBlock + (sectorSize - seekDiff), buf, seekDiff);
if (write(fd, tmpBlock, sectorSize)==-1) if (write(fd, tmpBlock, sectorSize) == -1)
perror("write seekDiff"); perror("write seekDiff");
} }
// Blocks between // Blocks between
if ((nbytes - seekDiff) >= sectorSize) { 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"); perror("write between");
}
} }
// Last block if overflow // Last block if overflow
@@ -213,9 +231,8 @@ ssize_t
haiku_freebsd_readv(int fd, const struct iovec *vecs, size_t count) haiku_freebsd_readv(int fd, const struct iovec *vecs, size_t count)
{ {
ssize_t bytesRead = 0; 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, ssize_t currentRead = haiku_freebsd_read(fd, vecs[i].iov_base,
vecs[i].iov_len); vecs[i].iov_len);
@@ -236,9 +253,8 @@ ssize_t
haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count) haiku_freebsd_writev(int fd, const struct iovec *vecs, size_t count)
{ {
ssize_t bytesWritten = 0; 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, ssize_t written = haiku_freebsd_write(fd, vecs[i].iov_base,
vecs[i].iov_len); vecs[i].iov_len);