(root)/
findutils-4.9.0/
gnulib-tests/
test-closein.c
       1  /* Test of closein module.
       2     Copyright (C) 2007-2022 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, or (at your option)
       7     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 Eric Blake.  */
      18  
      19  #include <config.h>
      20  
      21  #include "closein.h"
      22  
      23  #include <stdio.h>
      24  #include <stdlib.h>
      25  #include <unistd.h>
      26  
      27  #include "binary-io.h"
      28  #include "ignore-value.h"
      29  
      30  /* With no arguments, do nothing.  With arguments, attempt to consume
      31     first 6 bytes of stdin.  In either case, let exit() take care of
      32     closing std streams and changing exit status if ferror(stdin).  */
      33  int
      34  main (int argc, char **argv)
      35  {
      36    char buf[7];
      37    atexit (close_stdin);
      38  
      39    /* close_stdin currently relies on ftell, but mingw ftell is
      40       unreliable on text mode input.  */
      41    set_binary_mode (0, O_BINARY);
      42  
      43    if (argc > 2)
      44      close (0);
      45  
      46    if (argc > 1)
      47      ignore_value (fread (buf, 1, 6, stdin));
      48    return 0;
      49  }