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