gshadow: Matching sgetsgent, sgetsgent_r ERANGE handling (bug 30151)
[glibc.git] / misc / tst-mntent.c
blob493cef419eb7148edbe83099e9728de36da07287
1 #include <mntent.h>
2 #include <stdio.h>
3 #include <string.h>
6 static int
7 do_test (void)
9 int result = 0;
10 struct mntent mef;
11 struct mntent *mnt = &mef;
12 FILE *fp;
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;
21 if (hasmntopt (mnt, "defaults"))
22 printf ("Found!\n");
23 else
25 printf ("Didn't find it\n");
26 result = 1;
29 fp = tmpfile ();
30 if (fp == NULL)
32 printf ("Cannot open temporary file: %m\n");
33 result = 1;
35 else
37 char buf[1024];
39 /* Write the name entry. */
40 addmntent (fp, &mef);
42 /* Prepare for reading. */
43 rewind (fp);
45 /* First, read it raw. */
46 if (fgets (buf, sizeof (buf), fp) == NULL)
48 printf ("Cannot read temporary file: %m");
49 result = 1;
51 else
52 if (strcmp (buf, "/dev/hda1 /some\\040dir ext2 defaults 1 2\n") != 0)
54 puts ("Raw file data not correct");
55 result = 1;
58 /* Prepare for reading, part II. */
59 rewind (fp);
61 /* Now read it cooked. */
62 mnt = getmntent (fp);
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)
71 puts ("Error while reading written entry back in");
72 result = 1;
76 return result;
79 #define TEST_FUNCTION do_test ()
80 #include "../test-skeleton.c"