(root)/
gettext-0.22.4/
gettext-tools/
gnulib-tests/
test-stdio.c
       1  /* Test of <stdio.h> substitute.
       2     Copyright (C) 2007, 2009-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 Bruno Haible <bruno@clisp.org>, 2007.  */
      18  
      19  #include <config.h>
      20  
      21  #include <stdio.h>
      22  
      23  /* Check that the various SEEK_* macros are defined.  */
      24  int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
      25  
      26  /* Check that the _PRINTF_NAN_LEN_MAX macro is defined.  */
      27  int pnlm[] = { _PRINTF_NAN_LEN_MAX };
      28  
      29  /* Check that NULL can be passed through varargs as a pointer type,
      30     per POSIX 2008.  */
      31  static_assert (sizeof NULL == sizeof (void *));
      32  
      33  /* Check that the types are all defined.  */
      34  fpos_t t1;
      35  off_t t2;
      36  size_t t3;
      37  ssize_t t4;
      38  va_list t5;
      39  
      40  #include <string.h>
      41  
      42  #include "signed-nan.h"
      43  #include "signed-snan.h"
      44  #include "macros.h"
      45  
      46  int
      47  main (void)
      48  {
      49    {
      50      double value1;
      51      char buf[64];
      52  
      53      value1 = positive_NaNd();
      54      sprintf (buf, "%g", value1);
      55      ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
      56  
      57      value1 = negative_NaNd();
      58      sprintf (buf, "%g", value1);
      59      ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
      60    }
      61  #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
      62    /* Check the value of _PRINTF_NAN_LEN_MAX.  */
      63    {
      64      double value1;
      65      memory_double value2;
      66      char buf[64];
      67  
      68      value1 = positive_SNaNd();
      69      sprintf (buf, "%g", value1);
      70      ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
      71  
      72      value1 = negative_SNaNd();
      73      sprintf (buf, "%g", value1);
      74      ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
      75  
      76      value2.value = positive_NaNd ();
      77      #if DBL_EXPBIT0_BIT == 20
      78      value2.word[DBL_EXPBIT0_WORD] ^= 0x54321;
      79      #endif
      80      sprintf (buf, "%g", value2.value);
      81      ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
      82  
      83      value2.value = negative_NaNd ();
      84      #if DBL_EXPBIT0_BIT == 20
      85      value2.word[DBL_EXPBIT0_WORD] ^= 0x54321;
      86      #endif
      87      sprintf (buf, "%g", value2.value);
      88      ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
      89    }
      90  #endif
      91  
      92    return 0;
      93  }