diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b088c49..5618ed7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -14,6 +14,7 @@ Code contributions: Igor Katson Eugene Agafonov Antonia Stevens + Frank Groeneveld Feel free to add yourself to this list in your pull-request. Please modify this file instead of source headers. diff --git a/file.cc b/file.cc index 5d4d141..972215f 100644 --- a/file.cc +++ b/file.cc @@ -6,7 +6,7 @@ #include #include #include -#ifdef __APPLE__ +#if defined( __APPLE__ ) || defined( __OpenBSD__ ) #include #else #include @@ -65,9 +65,20 @@ void File::rename( std::string const & from, source file. */ write_fd = ::open( to.c_str(), O_WRONLY | O_CREAT, stat_buf.st_mode ); /* Blast the bytes from one file to the other. */ - #ifdef __APPLE__ + #if defined( __APPLE__ ) if ( -1 == sendfile(write_fd, read_fd, offset, &stat_buf.st_size, NULL, 0) ) throw exCantRename( from + " to " + to ); + #elif defined( __OpenBSD__ ) + + size_t BUFSIZE = 4096, size; + char buf[BUFSIZE]; + + while ( ( size = ::read( read_fd, buf, BUFSIZE ) ) != -1 && size != 0 ) + ::write( write_fd, buf, size ); + + if ( size == -1 ) + throw exCantRename( from + " to " + to ); + #else if ( -1 == sendfile(write_fd, read_fd, &offset, stat_buf.st_size) ) throw exCantRename( from + " to " + to ); diff --git a/unbuffered_file.cc b/unbuffered_file.cc index 0816e4a..1339480 100644 --- a/unbuffered_file.cc +++ b/unbuffered_file.cc @@ -13,7 +13,7 @@ #include "unbuffered_file.hh" -#ifdef __APPLE__ +#if defined( __APPLE__ ) || defined( __OpenBSD__ ) #define lseek64 lseek #endif @@ -24,7 +24,7 @@ UnbufferedFile::UnbufferedFile( char const * fileName, Mode mode ) int flags = ( mode == WriteOnly ? ( O_WRONLY | O_CREAT | O_TRUNC ) : O_RDONLY ); -#ifndef __APPLE__ +#if !defined( __APPLE__ ) && !defined( __OpenBSD__ ) flags |= O_LARGEFILE; #endif fd = open( fileName, flags, 0666 );