]> git.ipfire.org Git - thirdparty/glibc.git/blob - misc/tst-mntent.c
__glibc_unsafe_len: Fix comment
[thirdparty/glibc.git] / misc / tst-mntent.c
1 #include <mntent.h>
2 #include <stdio.h>
3 #include <string.h>
4
5
6 static int
7 do_test (void)
8 {
9 int result = 0;
10 struct mntent mef;
11 struct mntent *mnt = &mef;
12 FILE *fp;
13
14 mef.mnt_fsname = strdupa ("/dev/hda1");
15 mef.mnt_dir = strdupa ("/some dir");
16 mef.mnt_type = strdupa ("ext2");
17 mef.mnt_opts = strdupa ("defaults");
18 mef.mnt_freq = 1;
19 mef.mnt_passno = 2;
20
21 if (hasmntopt (mnt, "defaults"))
22 printf ("Found!\n");
23 else
24 {
25 printf ("Didn't find it\n");
26 result = 1;
27 }
28
29 fp = tmpfile ();
30 if (fp == NULL)
31 {
32 printf ("Cannot open temporary file: %m\n");
33 result = 1;
34 }
35 else
36 {
37 char buf[1024];
38
39 /* Write the name entry. */
40 addmntent (fp, &mef);
41
42 /* Prepare for reading. */
43 rewind (fp);
44
45 /* First, read it raw. */
46 if (fgets (buf, sizeof (buf), fp) == NULL)
47 {
48 printf ("Cannot read temporary file: %m");
49 result = 1;
50 }
51 else
52 if (strcmp (buf, "/dev/hda1 /some\\040dir ext2 defaults 1 2\n") != 0)
53 {
54 puts ("Raw file data not correct");
55 result = 1;
56 }
57
58 /* Prepare for reading, part II. */
59 rewind (fp);
60
61 /* Now read it cooked. */
62 mnt = getmntent (fp);
63
64 if (strcmp (mnt->mnt_fsname, "/dev/hda1") != 0
65 || strcmp (mnt->mnt_dir, "/some dir") != 0
66 || strcmp (mnt->mnt_type, "ext2") != 0
67 || strcmp (mnt->mnt_opts, "defaults") != 0
68 || mnt->mnt_freq != 1
69 || mnt->mnt_passno != 2)
70 {
71 puts ("Error while reading written entry back in");
72 result = 1;
73 }
74 }
75
76 return result;
77 }
78
79 #define TEST_FUNCTION do_test ()
80 #include "../test-skeleton.c"