]>
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 | ||
c1f41083 AS |
8 | static int |
9 | do_test (void) | |
bf7997b6 | 10 | { |
444518fe | 11 | int result = 0; |
bf7997b6 UD |
12 | struct mntent mef; |
13 | struct mntent *mnt = &mef; | |
63f7cb44 | 14 | FILE *fp; |
bf7997b6 UD |
15 | |
16 | mef.mnt_fsname = strdupa ("/dev/hda1"); | |
63f7cb44 | 17 | mef.mnt_dir = strdupa ("/some dir"); |
bf7997b6 UD |
18 | mef.mnt_type = strdupa ("ext2"); |
19 | mef.mnt_opts = strdupa ("defaults"); | |
20 | mef.mnt_freq = 1; | |
63f7cb44 | 21 | mef.mnt_passno = 2; |
bf7997b6 UD |
22 | |
23 | if (hasmntopt (mnt, "defaults")) | |
24 | printf ("Found!\n"); | |
25 | else | |
444518fe | 26 | { |
bf7997b6 | 27 | printf ("Didn't find it\n"); |
444518fe UD |
28 | result = 1; |
29 | } | |
bf7997b6 | 30 | |
ba6088cf | 31 | fp = tmpfile (); |
63f7cb44 UD |
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 | } | |
fb87ee96 | 76 | } |
63f7cb44 | 77 | |
bf7997b6 UD |
78 | return result; |
79 | } | |
c1f41083 AS |
80 | |
81 | #define TEST_FUNCTION do_test () | |
82 | #include "../test-skeleton.c" |