Add MacOSX compatability

master
Jarl Stefansson 2014-11-17 12:26:58 -05:00
parent 3e7ae35a7c
commit 5aa754654b
1 changed files with 11 additions and 3 deletions

14
file.cc
View File

@ -6,8 +6,11 @@
#include <unistd.h>
#include <cerrno>
#include <cstring>
#include <sys/sendfile.h>
#ifdef __APPLE__
#include <sys/socket.h>
#else
#include <sys/sendfile.h>
#endif
#include <sys/types.h>
#include <fcntl.h>
@ -61,8 +64,13 @@ 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 ( -1 == sendfile(write_fd, read_fd, offset, &stat_buf.st_size, NULL, 0) )
throw exCantRename( from + " to " + to );
#else
if ( -1 == sendfile(write_fd, read_fd, &offset, stat_buf.st_size) )
throw exCantRename( from + " to " + to );
throw exCantRename( from + " to " + to );
#endif
/* Close up. */
::close( read_fd );