@@ -1386,6 +1386,62 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {
13861386 return syscall3 (.madvise , @ptrToInt (address ), len , advice );
13871387}
13881388
1389+ pub fn fadvise (fd : fd_t , offset : u64 , len : u64 , advice : usize ) usize {
1390+ if (comptime std .Target .current .cpu .arch .isMIPS ()) {
1391+ // MIPS requires a 7 argument syscall
1392+
1393+ const offset_halves = splitValue64 (@bitCast (u64 , offset ));
1394+ const length_halves = splitValue64 (@bitCast (u64 , len ));
1395+
1396+ return syscall7 (
1397+ .fadvise64 ,
1398+ @bitCast (usize , @as (isize , fd )),
1399+ 0 ,
1400+ offset_halves [0 ],
1401+ offset_halves [1 ],
1402+ length_halves [0 ],
1403+ length_halves [1 ],
1404+ advice ,
1405+ );
1406+ } else if (comptime std .Target .current .cpu .arch .isARM ()) {
1407+ // ARM reorders the arguments
1408+
1409+ const offset_halves = splitValue64 (@bitCast (u64 , offset ));
1410+ const length_halves = splitValue64 (@bitCast (u64 , len ));
1411+
1412+ return syscall6 (
1413+ .fadvise64_64 ,
1414+ @bitCast (usize , @as (isize , fd )),
1415+ advice ,
1416+ offset_halves [0 ],
1417+ offset_halves [1 ],
1418+ length_halves [0 ],
1419+ length_halves [1 ],
1420+ );
1421+ } else if (@hasField (SYS , "fadvise64_64" )) {
1422+ const offset_halves = splitValue64 (@bitCast (u64 , offset ));
1423+ const length_halves = splitValue64 (@bitCast (u64 , len ));
1424+
1425+ return syscall6 (
1426+ .fadvise64_64 ,
1427+ @bitCast (usize , @as (isize , fd )),
1428+ offset_halves [0 ],
1429+ offset_halves [1 ],
1430+ length_halves [0 ],
1431+ length_halves [1 ],
1432+ advice ,
1433+ );
1434+ } else {
1435+ return syscall4 (
1436+ .fadvise64 ,
1437+ @bitCast (usize , @as (isize , fd )),
1438+ @bitCast (usize , offset ),
1439+ @bitCast (usize , len ),
1440+ advice ,
1441+ );
1442+ }
1443+ }
1444+
13891445test {
13901446 if (builtin .os .tag == .linux ) {
13911447 _ = @import ("linux/test.zig" );
0 commit comments