100008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes/* 200008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * Copyright (C) 2014 The Android Open Source Project 300008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * All rights reserved. 400008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * 500008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * Redistribution and use in source and binary forms, with or without 600008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * modification, are permitted provided that the following conditions 700008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * are met: 800008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * * Redistributions of source code must retain the above copyright 900008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * notice, this list of conditions and the following disclaimer. 1000008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * * Redistributions in binary form must reproduce the above copyright 1100008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * notice, this list of conditions and the following disclaimer in 1200008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * the documentation and/or other materials provided with the 1300008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * distribution. 1400008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * 1500008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1600008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1700008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1800008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1900008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2000008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2100008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2200008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2300008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2400008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2500008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2600008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes * SUCH DAMAGE. 2700008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes */ 2800008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes 2900008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes#include <fcntl.h> 3000008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes 3100008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes#include "private/ErrnoRestorer.h" 3200008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes 3300008263782e484020420c606f7d145fe7d0a4d8Elliott Hughesextern "C" int __arm_fadvise64_64(int, int, off64_t, off64_t); 3400008263782e484020420c606f7d145fe7d0a4d8Elliott Hughesextern "C" int __fadvise64(int, off64_t, off64_t, int); 3500008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes 3600008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes// No architecture actually has the 32-bit off_t system call. 3700008263782e484020420c606f7d145fe7d0a4d8Elliott Hughesint posix_fadvise(int fd, off_t offset, off_t length, int advice) { 3800008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes return posix_fadvise64(fd, offset, length, advice); 3900008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes} 4000008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes 4100008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes#if defined(__arm__) 4200008263782e484020420c606f7d145fe7d0a4d8Elliott Hughesint posix_fadvise64(int fd, off64_t offset, off64_t length, int advice) { 4300008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes ErrnoRestorer errno_restorer; 4400008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes return (__arm_fadvise64_64(fd, advice, offset, length) == 0) ? 0 : errno; 4500008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes} 4600008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes#else 4700008263782e484020420c606f7d145fe7d0a4d8Elliott Hughesint posix_fadvise64(int fd, off64_t offset, off64_t length, int advice) { 4800008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes ErrnoRestorer errno_restorer; 4900008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes return (__fadvise64(fd, offset, length, advice) == 0) ? 0 : errno; 5000008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes} 5100008263782e484020420c606f7d145fe7d0a4d8Elliott Hughes#endif 52