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