(root)/
glibc-2.38/
elf/
tst-dl-printf-static.c
       1  /* Check _dl_debug_vdprintf.
       2     Copyright The GNU Toolchain Authors.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <ldsodefs.h>
      20  #include <limits.h>
      21  #include <stdarg.h>
      22  #include <stdio.h>
      23  #include <support/check.h>
      24  #include <support/xunistd.h>
      25  
      26  #define BUFSZ 64
      27  
      28  #define TEST(fmt, ...)                                                        \
      29    do                                                                          \
      30      {                                                                         \
      31        char str1[BUFSZ], str2[BUFSZ];                                          \
      32        int len1 = snprintf (str1, BUFSZ, fmt, __VA_ARGS__);                    \
      33        TEST_VERIFY_EXIT (len1 >= 0);                                           \
      34        TEST_VERIFY_EXIT (len1 < BUFSZ);                                        \
      35        _dl_dprintf (fds[1], fmt, __VA_ARGS__);                                 \
      36        ssize_t len2 = read (fds[0], str2, BUFSZ);                              \
      37        TEST_VERIFY_EXIT (len2 >= 0);                                           \
      38        TEST_VERIFY_EXIT (len2 < BUFSZ);                                        \
      39        str2[len2] = '\0';                                                      \
      40        TEST_COMPARE_STRING (str1, str2);                                       \
      41      }                                                                         \
      42    while (0)
      43  
      44  static int
      45  do_test (void)
      46  {
      47    int fds[2];
      48    xpipe (fds);
      49    TEST ("%d", 0);
      50    TEST ("%d", 1);
      51    TEST ("%d", INT_MAX);
      52    TEST ("%d", -1);
      53    TEST ("%d", INT_MIN + 1);
      54    TEST ("%d", INT_MIN);
      55    TEST ("%u", 0U);
      56    TEST ("%u", 1U);
      57    TEST ("%u", UINT_MAX);
      58    TEST ("%x", 0);
      59    TEST ("%x", 1);
      60    TEST ("%x", UINT_MAX);
      61    TEST ("%ld", 0L);
      62    TEST ("%ld", 1L);
      63    TEST ("%ld", LONG_MAX);
      64    TEST ("%ld", -1L);
      65    TEST ("%ld", LONG_MIN + 1);
      66    TEST ("%ld", LONG_MIN);
      67    TEST ("%lu", 0UL);
      68    TEST ("%lu", 1UL);
      69    TEST ("%lu", ULONG_MAX);
      70    TEST ("%lx", 0UL);
      71    TEST ("%lx", 1UL);
      72    TEST ("%lx", ULONG_MAX);
      73    xclose (fds[0]);
      74    xclose (fds[1]);
      75    return 0;
      76  }
      77  
      78  #include <support/test-driver.c>