io: Re-flow and sort multiline Makefile definitions
[glibc.git] / misc / tst-mntent-escape.c
blob843f290d020aec04f9f372829a2ebdf4da13c502
1 /* Test mntent interface with escaped sequences.
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <mntent.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <support/check.h>
25 struct const_mntent
27 const char *mnt_fsname;
28 const char *mnt_dir;
29 const char *mnt_type;
30 const char *mnt_opts;
31 int mnt_freq;
32 int mnt_passno;
33 const char *expected;
36 struct const_mntent tests[] =
38 {"/dev/hda1", "/some dir", "ext2", "defaults", 1, 2,
39 "/dev/hda1 /some\\040dir ext2 defaults 1 2\n"},
40 {"device name", "/some dir", "tmpfs", "defaults", 1, 2,
41 "device\\040name /some\\040dir tmpfs defaults 1 2\n"},
42 {" ", "/some dir", "tmpfs", "defaults", 1, 2,
43 "\\040 /some\\040dir tmpfs defaults 1 2\n"},
44 {"\t", "/some dir", "tmpfs", "defaults", 1, 2,
45 "\\011 /some\\040dir tmpfs defaults 1 2\n"},
46 {"\\", "/some dir", "tmpfs", "defaults", 1, 2,
47 "\\134 /some\\040dir tmpfs defaults 1 2\n"},
50 static int
51 do_test (void)
53 for (int i = 0; i < sizeof (tests) / sizeof (struct const_mntent); i++)
55 char buf[128];
56 struct mntent *ret, curtest;
57 FILE *fp = fmemopen (buf, sizeof (buf), "w+");
59 if (fp == NULL)
61 printf ("Failed to open file\n");
62 return 1;
65 curtest.mnt_fsname = strdupa (tests[i].mnt_fsname);
66 curtest.mnt_dir = strdupa (tests[i].mnt_dir);
67 curtest.mnt_type = strdupa (tests[i].mnt_type);
68 curtest.mnt_opts = strdupa (tests[i].mnt_opts);
69 curtest.mnt_freq = tests[i].mnt_freq;
70 curtest.mnt_passno = tests[i].mnt_passno;
72 if (addmntent (fp, &curtest) != 0)
74 support_record_failure ();
75 continue;
78 TEST_COMPARE_STRING (buf, tests[i].expected);
80 rewind (fp);
81 ret = getmntent (fp);
82 if (ret == NULL)
84 support_record_failure ();
85 continue;
88 TEST_COMPARE_STRING(tests[i].mnt_fsname, ret->mnt_fsname);
89 TEST_COMPARE_STRING(tests[i].mnt_dir, ret->mnt_dir);
90 TEST_COMPARE_STRING(tests[i].mnt_type, ret->mnt_type);
91 TEST_COMPARE_STRING(tests[i].mnt_opts, ret->mnt_opts);
92 TEST_COMPARE(tests[i].mnt_freq, ret->mnt_freq);
93 TEST_COMPARE(tests[i].mnt_passno, ret->mnt_passno);
95 fclose (fp);
98 return 0;
101 #include <support/test-driver.c>