(root)/
coreutils-9.4/
lib/
fadvise.c
       1  /* Declare an access pattern hint for files.
       2     Copyright (C) 2010-2023 Free Software Foundation, Inc.
       3  
       4     This program is free software: you can redistribute it and/or modify
       5     it under the terms of the GNU General Public License as published by
       6     the Free Software Foundation, either version 3 of the License, or
       7     (at your option) any later version.
       8  
       9     This program is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12     GNU General Public License for more details.
      13  
      14     You should have received a copy of the GNU General Public License
      15     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      16  
      17  /* Without this pragma, gcc suggests that (given !HAVE_POSIX_FADVISE)
      18     the fdadvise function might be a candidate for attribute 'const'.  */
      19  #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
      20  # pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
      21  #endif
      22  
      23  #include <config.h>
      24  #include "fadvise.h"
      25  
      26  #include <stdio.h>
      27  #include <fcntl.h>
      28  #include "ignore-value.h"
      29  
      30  void
      31  fdadvise (int fd, off_t offset, off_t len, fadvice_t advice)
      32  {
      33  #if HAVE_POSIX_FADVISE
      34    ignore_value (posix_fadvise (fd, offset, len, advice));
      35  #endif
      36  }
      37  
      38  void
      39  fadvise (FILE *fp, fadvice_t advice)
      40  {
      41    if (fp)
      42      fdadvise (fileno (fp), 0, 0, advice);
      43  }