]>
git.ipfire.org Git - thirdparty/glibc.git/blob - stdio-common/tst-sprintf-errno.c
1 /* Test the %m, %#m printf specifiers via asprintf.
2 Copyright (C) 2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
20 #include <libc-diag.h>
22 #include <support/check.h>
23 #include <support/support.h>
25 /* GCC does not yet know about the %#m specifier. */
26 DIAG_PUSH_NEEDS_COMMENT
;
27 DIAG_IGNORE_NEEDS_COMMENT (11, "-Wformat=");
35 TEST_COMPARE (sprintf (buf
, "%m"), 16);
36 TEST_COMPARE_STRING (buf
, "Invalid argument");
39 TEST_COMPARE (sprintf (buf
, "%#m"), 6);
40 TEST_COMPARE_STRING (buf
, "EINVAL");
43 TEST_COMPARE (sprintf (buf
, "%m"), 7);
44 TEST_COMPARE_STRING (buf
, "Success");
47 TEST_COMPARE (sprintf (buf
, "%#m"), 1);
48 TEST_COMPARE_STRING (buf
, "0");
51 TEST_COMPARE (sprintf (buf
, "%m"), 16);
52 TEST_COMPARE_STRING (buf
, "Unknown error -1");
55 TEST_COMPARE (sprintf (buf
, "%#m"), 2);
56 TEST_COMPARE_STRING (buf
, "-1");
59 TEST_COMPARE (sprintf (buf
, "%m"), 21);
60 TEST_COMPARE_STRING (buf
, "Unknown error 1002003");
63 TEST_COMPARE (sprintf (buf
, "%#m"), 7);
64 TEST_COMPARE_STRING (buf
, "1002003");
67 TEST_COMPARE (sprintf (buf
, "%20m"), 20);
68 TEST_COMPARE_STRING (buf
, " Invalid argument");
71 TEST_COMPARE (sprintf (buf
, "%#20m"), 20);
72 TEST_COMPARE_STRING (buf
, " EINVAL");
75 TEST_COMPARE (sprintf (buf
, "%-20m"), 20);
76 TEST_COMPARE_STRING (buf
, "Invalid argument ");
79 TEST_COMPARE (sprintf (buf
, "%-#20m"), 20);
80 TEST_COMPARE_STRING (buf
, "EINVAL ");
83 TEST_COMPARE (sprintf (buf
, "%-20m"), 20);
84 TEST_COMPARE_STRING (buf
, "Success ");
87 TEST_COMPARE (sprintf (buf
, "%-#20m"), 20);
88 TEST_COMPARE_STRING (buf
, "0 ");
93 #include <support/test-driver.c>