sendfile-util.c revision 32c40bcc868782a9e34ff8bcfd969b89a09de89d
/* Copyright (c) 2002-2003 Timo Sirainen */
/* kludge a bit to remove _FILE_OFFSET_BITS definition from config.h.
It's required to be able to include sys/sendfile.h with Linux. */
#include "config.h"
#ifdef HAVE_LINUX_SENDFILE
#endif
#include "lib.h"
#include "sendfile-util.h"
#ifdef HAVE_LINUX_SENDFILE
#include <sys/sendfile.h>
{
/* REMEBER: uoff_t and off_t may not be of same size. */
if (count == 0)
return 0;
/* make sure given offset fits into off_t */
/* 32bit off_t */
if (*offset >= 2147483647L) {
return -1;
}
} else {
/* they're most likely the same size. if not, fix this
code later */
return -1;
}
}
if (ret == 0) {
ret = -1;
}
return ret;
}
#elif defined(HAVE_FREEBSD_SENDFILE)
{
int ret;
if (count == 0) {
/* if count=0 is passed to sendfile(), it sends everything
from in_fd until EOF. We don't want that. */
return 0;
}
else {
/* out_fd wasn't a socket. behave as if sendfile()
wasn't supported at all. */
}
return -1;
}
}
#elif defined (HAVE_SOLARIS_SENDFILE)
#include <sys/sendfile.h>
#include "network.h"
{
if (count == 0)
return 0;
/* NOTE: if outfd is not a socket, some Solaris versions will
kernel panic */
if (ret < 0) {
if (errno == EAFNOSUPPORT) {
/* not supported, return Linux-like EINVAL so caller
sees only consistent errnos. */
/* some data was sent, return it */
}
}
return ret;
}
#else
{
return -1;
}
#endif