Skip to content

Commit 37c866a

Browse files
committed
Merge pull request rust-lang#170 from kamalmarhubi/sendfile
unix: Add sendfile to platforms that support it
2 parents cb688da + 143358b commit 37c866a

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fn main() {
145145
cfg.header("sys/epoll.h");
146146
cfg.header("sys/eventfd.h");
147147
cfg.header("sys/prctl.h");
148+
cfg.header("sys/sendfile.h");
148149
cfg.header("sys/vfs.h");
149150
cfg.header("sys/syscall.h");
150151
if !musl {

src/unix/bsd/apple/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ s! {
250250
pub l_type: ::c_short,
251251
pub l_whence: ::c_short,
252252
}
253+
254+
pub struct sf_hdtr {
255+
pub headers: *mut ::iovec,
256+
pub hdr_cnt: ::c_int,
257+
pub trailers: *mut ::iovec,
258+
pub trl_cnt: ::c_int,
259+
}
253260
}
254261

255262
pub const EXIT_FAILURE: ::c_int = 1;
@@ -914,6 +921,12 @@ extern {
914921
id: ::c_int,
915922
data: *mut ::c_char) -> ::c_int;
916923
pub fn sethostname(name: *const ::c_char, len: ::c_int) -> ::c_int;
924+
pub fn sendfile(fd: ::c_int,
925+
s: ::c_int,
926+
offset: ::off_t,
927+
len: *mut ::off_t,
928+
hdtr: *mut ::sf_hdtr,
929+
flags: ::c_int) -> ::c_int;
917930
}
918931

919932
cfg_if! {

src/unix/bsd/freebsdlike/freebsd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pub type fsfilcnt_t = ::uint64_t;
44
pub const PTHREAD_STACK_MIN: ::size_t = 2048;
55
pub const KERN_PROC_PATHNAME: ::c_int = 12;
66
pub const SIGSTKSZ: ::size_t = 34816;
7+
pub const SF_NODISKIO: ::c_int = 0x00000001;
8+
pub const SF_MNOWAIT: ::c_int = 0x00000002;
9+
pub const SF_SYNC: ::c_int = 0x00000004;
710

811
extern {
912
pub fn __error() -> *mut ::c_int;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ s! {
139139
pub l_whence: ::c_short,
140140
pub l_sysid: ::c_int,
141141
}
142+
143+
pub struct sf_hdtr {
144+
pub headers: *mut ::iovec,
145+
pub hdr_cnt: ::c_int,
146+
pub trailers: *mut ::iovec,
147+
pub trl_cnt: ::c_int,
148+
}
142149
}
143150

144151
pub const EXIT_FAILURE: ::c_int = 1;
@@ -616,6 +623,13 @@ extern {
616623
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
617624
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
618625
pub fn memrchr(cx: *const ::c_void, c: ::c_int, n: ::size_t) -> *mut ::c_void;
626+
pub fn sendfile(fd: ::c_int,
627+
s: ::c_int,
628+
offset: ::off_t,
629+
nbytes: ::size_t,
630+
hdtr: *mut ::sf_hdtr,
631+
sbytes: *mut ::off_t,
632+
flags: ::c_int) -> ::c_int;
619633
}
620634

621635
cfg_if! {

src/unix/notbsd/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ extern {
624624
pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int;
625625
pub fn memrchr(cx: *const ::c_void, c: ::c_int, n: ::size_t) -> *mut ::c_void;
626626
pub fn syscall(num: ::c_long, ...) -> ::c_long;
627+
pub fn sendfile(out_fd: ::c_int,
628+
in_fd: ::c_int,
629+
offset: *mut off_t,
630+
count: ::size_t) -> ::ssize_t;
627631
pub fn splice(fd_in: ::c_int,
628632
off_in: *mut ::loff_t,
629633
fd_out: ::c_int,
@@ -638,7 +642,6 @@ extern {
638642
iov: *const ::iovec,
639643
nr_segs: ::size_t,
640644
flags: ::c_uint) -> ::ssize_t;
641-
642645
}
643646

644647
cfg_if! {

0 commit comments

Comments
 (0)