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:
parent
2c2e65ef16
commit
19a18af35e
@ -1,8 +1,10 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_DIRENT
|
||||
|
||||
|
||||
#include_next <dirent.h>
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
DIR* fdopendir(int fd);
|
||||
|
@ -1,8 +1,10 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN
|
||||
|
||||
|
||||
#include <machine/endian.h>
|
||||
|
||||
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
@ -1,9 +1,11 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_FCNTL
|
||||
|
||||
|
||||
#include_next <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
/*
|
||||
* Magic value that specify the use of the current working directory
|
||||
* to determine the target of relative file paths in the openat() and
|
||||
|
@ -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 </opt/local/include/gnuregex.h>
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX
|
||||
|
@ -1,8 +1,10 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_STDIO
|
||||
|
||||
|
||||
#include_next <stdio.h>
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int renameat(int oldFD, const char* oldPath, int newFD, const char* newPath);
|
||||
|
@ -1,9 +1,11 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_SYS_STAT
|
||||
|
||||
|
||||
#include_next <sys/stat.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
|
||||
#ifndef UTIME_NOW
|
||||
# define UTIME_NOW (-1)
|
||||
# define UTIME_OMIT (-2)
|
||||
|
@ -1,8 +1,10 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_UNISTD
|
||||
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int faccessat(int fd, const char* path, int accessMode, int flag);
|
||||
|
@ -1,14 +1,16 @@
|
||||
#ifndef _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.
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
#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 <endian.h> in FreeBSD, but <sys/endian.h>. And the macro naming
|
||||
// differs.
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
|
||||
#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
|
||||
|
@ -1,8 +1,10 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
|
||||
|
||||
// There's no <regex.h> in FreeBSD, but <gnu/regex.h>.
|
||||
|
||||
#include <gnu/regex.h>
|
||||
|
||||
#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
|
||||
|
||||
|
||||
// There's no <regex.h> in FreeBSD, but <gnu/regex.h>.
|
||||
|
||||
#include <gnu/regex.h>
|
||||
|
||||
|
||||
#endif // _HAIKU_BUILD_COMPATIBILITY_FREEBSD_REGEX
|
||||
|
@ -1,9 +1,11 @@
|
||||
#ifndef _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT
|
||||
#define _HAIKU_BUILD_COMPATIBILITY_FREEBSD_SYS_STAT
|
||||
|
||||
|
||||
#include_next <sys/stat.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
|
||||
#ifndef UTIME_NOW
|
||||
# define UTIME_NOW (-1)
|
||||
# define UTIME_OMIT (-2)
|
||||
|
@ -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 =
|
||||
|
@ -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
|
@ -4,6 +4,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "fs_freebsd.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);
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user