Merge pull request #46 from frenkel/openbsd_support

Add support for compiling on OpenBSD.
master
Vladimir Stackov 2015-01-23 00:05:43 +03:00
commit c5b821dba4
3 changed files with 16 additions and 4 deletions

View File

@ -14,6 +14,7 @@ Code contributions:
Igor Katson <igor.katson@gmail.com>
Eugene Agafonov <e.a.agafonov@gmail.com>
Antonia Stevens <a@antevens.com>
Frank Groeneveld <frank@frankgroeneveld.nl>
Feel free to add yourself to this list in your pull-request.
Please modify this file instead of source headers.

15
file.cc
View File

@ -6,7 +6,7 @@
#include <unistd.h>
#include <cerrno>
#include <cstring>
#ifdef __APPLE__
#if defined( __APPLE__ ) || defined( __OpenBSD__ )
#include <sys/socket.h>
#else
#include <sys/sendfile.h>
@ -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 );

View File

@ -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 );