(banner): If TLS support available say so.
[glibc.git] / misc / tst-mntent.c
blobae967670f9cd2484b3dfda0e20a50a5f28a6c363
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>
8 int
9 main (int argc, char *argv[])
11 int result = 0;
12 struct mntent mef;
13 struct mntent *mnt = &mef;
14 char *name;
15 FILE *fp;
17 mef.mnt_fsname = strdupa ("/dev/hda1");
18 mef.mnt_dir = strdupa ("/some dir");
19 mef.mnt_type = strdupa ("ext2");
20 mef.mnt_opts = strdupa ("defaults");
21 mef.mnt_freq = 1;
22 mef.mnt_passno = 2;
24 if (hasmntopt (mnt, "defaults"))
25 printf ("Found!\n");
26 else
28 printf ("Didn't find it\n");
29 result = 1;
32 name = tmpnam (NULL);
33 fp = fopen (name, "w+");
34 if (fp == NULL)
36 printf ("Cannot open temporary file: %m\n");
37 result = 1;
39 else
41 char buf[1024];
43 /* Write the name entry. */
44 addmntent (fp, &mef);
46 /* Prepare for reading. */
47 rewind (fp);
49 /* First, read it raw. */
50 if (fgets (buf, sizeof (buf), fp) == NULL)
52 printf ("Cannot read temporary file: %m");
53 result = 1;
55 else
56 if (strcmp (buf, "/dev/hda1 /some\\040dir ext2 defaults 1 2\n") != 0)
58 puts ("Raw file data not correct");
59 result = 1;
62 /* Prepare for reading, part II. */
63 rewind (fp);
65 /* Now read it cooked. */
66 mnt = getmntent (fp);
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)
75 puts ("Error while reading written entry back in");
76 result = 1;
79 remove (name);
82 return result;