mirror of https://github.com/vitalif/zbackup
commit
c5b821dba4
|
@ -14,6 +14,7 @@ Code contributions:
|
||||||
Igor Katson <igor.katson@gmail.com>
|
Igor Katson <igor.katson@gmail.com>
|
||||||
Eugene Agafonov <e.a.agafonov@gmail.com>
|
Eugene Agafonov <e.a.agafonov@gmail.com>
|
||||||
Antonia Stevens <a@antevens.com>
|
Antonia Stevens <a@antevens.com>
|
||||||
|
Frank Groeneveld <frank@frankgroeneveld.nl>
|
||||||
|
|
||||||
Feel free to add yourself to this list in your pull-request.
|
Feel free to add yourself to this list in your pull-request.
|
||||||
Please modify this file instead of source headers.
|
Please modify this file instead of source headers.
|
||||||
|
|
15
file.cc
15
file.cc
|
@ -6,7 +6,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#ifdef __APPLE__
|
#if defined( __APPLE__ ) || defined( __OpenBSD__ )
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
|
@ -65,9 +65,20 @@ void File::rename( std::string const & from,
|
||||||
source file. */
|
source file. */
|
||||||
write_fd = ::open( to.c_str(), O_WRONLY | O_CREAT, stat_buf.st_mode );
|
write_fd = ::open( to.c_str(), O_WRONLY | O_CREAT, stat_buf.st_mode );
|
||||||
/* Blast the bytes from one file to the other. */
|
/* 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) )
|
if ( -1 == sendfile(write_fd, read_fd, offset, &stat_buf.st_size, NULL, 0) )
|
||||||
throw exCantRename( from + " to " + to );
|
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
|
#else
|
||||||
if ( -1 == sendfile(write_fd, read_fd, &offset, stat_buf.st_size) )
|
if ( -1 == sendfile(write_fd, read_fd, &offset, stat_buf.st_size) )
|
||||||
throw exCantRename( from + " to " + to );
|
throw exCantRename( from + " to " + to );
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "unbuffered_file.hh"
|
#include "unbuffered_file.hh"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#if defined( __APPLE__ ) || defined( __OpenBSD__ )
|
||||||
#define lseek64 lseek
|
#define lseek64 lseek
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ UnbufferedFile::UnbufferedFile( char const * fileName, Mode mode )
|
||||||
|
|
||||||
int flags = ( mode == WriteOnly ? ( O_WRONLY | O_CREAT | O_TRUNC ) :
|
int flags = ( mode == WriteOnly ? ( O_WRONLY | O_CREAT | O_TRUNC ) :
|
||||||
O_RDONLY );
|
O_RDONLY );
|
||||||
#ifndef __APPLE__
|
#if !defined( __APPLE__ ) && !defined( __OpenBSD__ )
|
||||||
flags |= O_LARGEFILE;
|
flags |= O_LARGEFILE;
|
||||||
#endif
|
#endif
|
||||||
fd = open( fileName, flags, 0666 );
|
fd = open( fileName, flags, 0666 );
|
||||||
|
|
Loading…
Reference in New Issue