S390: Fix utf32 to utf8 handling of low surrogates (disable cu41).
[glibc.git] / libio / tst-atime.c
blob31ca59fec571bbff55e2d97c486517d5ad415cdb
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <sys/stat.h>
8 #include <sys/statvfs.h>
11 static int do_test (void);
12 #define TEST_FUNCTION do_test ()
13 #define TIMEOUT 5
14 #include <test-skeleton.c>
17 static int
18 do_test (void)
20 char *buf;
21 int fd;
22 FILE *fp;
23 int ch;
24 struct stat st1;
25 struct stat st2;
27 buf = (char *) malloc (strlen (test_dir) + sizeof "/tst-atime.XXXXXX");
28 if (buf == NULL)
30 printf ("cannot allocate memory: %m\n");
31 return 1;
33 stpcpy (stpcpy (buf, test_dir), "/tst-atime.XXXXXX");
35 fd = mkstemp (buf);
36 if (fd == -1)
38 printf ("cannot open temporary file: %m\n");
39 return 1;
42 #ifdef ST_NOATIME
43 /* Make sure the filesystem doesn't have the noatime option set. If
44 statvfs is not available just continue. */
45 struct statvfs sv;
46 int e = fstatvfs (fd, &sv);
47 if (e != ENOSYS)
49 if (e != 0)
51 printf ("cannot statvfs '%s': %m\n", buf);
52 return 1;
55 if ((sv.f_flag & ST_NOATIME) != 0)
57 puts ("Bah! The filesystem is mounted with noatime");
58 return 0;
61 #endif
63 /* Make sure it gets removed. */
64 add_temp_file (buf);
66 if (write (fd, "some string\n", 12) != 12)
68 printf ("cannot write temporary file: %m\n");
69 return 1;
72 if (lseek (fd, 0, SEEK_SET) == (off_t) -1)
74 printf ("cannot reposition temporary file: %m\n");
75 return 1;
78 fp = fdopen (fd, "r");
79 if (fp == NULL)
81 printf ("cannot create stream: %m\n");
82 return 1;
85 if (fstat (fd, &st1) == -1)
87 printf ("first stat failed: %m\n");
88 return 1;
91 sleep (2);
93 ch = fgetc (fp);
94 if (ch != 's')
96 printf ("did not read correct character: got '%c', expected 's'\n", ch);
97 return 1;
100 if (fstat (fd, &st2) == -1)
102 printf ("second stat failed: %m\n");
103 return 1;
106 if (st1.st_atime > st2.st_atime)
108 puts ("second atime smaller");
109 return 1;
111 else if (st1.st_atime == st2.st_atime)
113 puts ("atime has not changed");
114 return 1;
117 fclose (fp);
119 return 0;