Skip to content

Commit

Permalink
Merge pull request zbackup#46 from frenkel/openbsd_support
Browse files Browse the repository at this point in the history
Add support for compiling on OpenBSD.
  • Loading branch information
am1go committed Jan 22, 2015
2 parents e186eab + c97c9aa commit c5b821d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Code contributions:
Igor Katson <[email protected]>
Eugene Agafonov <[email protected]>
Antonia Stevens <[email protected]>
Frank Groeneveld <[email protected]>

Feel free to add yourself to this list in your pull-request.
Please modify this file instead of source headers.
15 changes: 13 additions & 2 deletions file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions unbuffered_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "unbuffered_file.hh"


#ifdef __APPLE__
#if defined( __APPLE__ ) || defined( __OpenBSD__ )
#define lseek64 lseek
#endif

Expand All @@ -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 );
Expand Down

0 comments on commit c5b821d

Please sign in to comment.