diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-13 02:34:50 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-13 02:34:50 +0000 |
commit | b36c91b6b51fbfc213e627975881dd8ce6fdbdf0 (patch) | |
tree | 2f82952c03a37c744fc4275ec26bac8c431055fa /io.c | |
parent | e1dc8e0c2262169400bc9dd2d2d389e2ff7e93cb (diff) |
* io.c (simple_sendfile): added for BSD version of sendfile(2).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -8198,25 +8198,45 @@ nogvl_copy_stream_wait_write(struct copy_stream_struct *stp) #ifdef HAVE_SENDFILE -#ifdef __linux__ -#define USE_SENDFILE +# ifdef __linux__ +# define USE_SENDFILE -#ifdef HAVE_SYS_SENDFILE_H -#include <sys/sendfile.h> -#endif +# ifdef HAVE_SYS_SENDFILE_H +# include <sys/sendfile.h> +# endif static ssize_t simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count) { -#if SIZEOF_OFF_T > SIZEOF_SIZE_T +# if SIZEOF_OFF_T > SIZEOF_SIZE_T /* we are limited by the 32-bit ssize_t return value on 32-bit */ if (count > (off_t)SSIZE_MAX) count = SSIZE_MAX; -#endif +# endif return sendfile(out_fd, in_fd, offset, (size_t)count); } -#endif +# elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) +# ifdef HAVE_SYS_UIO_H +# include <sys/uio.h> +# endif + +static ssize_t +simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count) +{ + int r; + size_t sbytes; +# if SIZEOF_OFF_T > SIZEOF_SIZE_T + /* we are limited by the 32-bit ssize_t return value on 32-bit */ + if (count > (off_t)SSIZE_MAX) + count = SSIZE_MAX; +# endif + r = sendfile(in_fd, out_fd, *offset, (size_t)count, NULL, &sbytes, 0); + if (r != 0) return -1; + return (ssize_t)sbytes; +} + +# endif #endif |