(root)/
coreutils-9.4/
gnulib-tests/
test-fadvise.c
       1  /* Test that fadvise works as advertised.
       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  /* Written by Pádraig Brady.  */
      18  
      19  #include <config.h>
      20  #include <stdio.h>
      21  
      22  #include "fadvise.h"
      23  
      24  /* We ignore any errors as these hints are only advisory.
      25   * There is the chance one can pass invalid ADVICE, which will
      26   * not be indicated, but given the simplicity of the interface
      27   * this is unlikely.  Also not returning errors allows the
      28   * unconditional passing of descriptors to non standard files,
      29   * which will just be ignored if unsupported.  */
      30  
      31  int
      32  main (void)
      33  {
      34    /* Valid.  */
      35    fadvise (stdin, FADVISE_SEQUENTIAL);
      36    fdadvise (fileno (stdin), 0, 0, FADVISE_RANDOM);
      37  
      38    /* Ignored.  */
      39    fadvise (nullptr, FADVISE_RANDOM);
      40  
      41    /* Invalid.  */
      42    fdadvise (42, 0, 0, FADVISE_RANDOM);
      43    /* Unfortunately C enums are not types.
      44       One could hack type safety by wrapping in a struct,
      45       but it's probably not worth the complexity in this case.  */
      46    fadvise (stdin, FADVISE_SEQUENTIAL + FADVISE_RANDOM);
      47    fadvise (stdin, 4242);
      48  
      49    return 0;
      50  }