7 static char fname[] = "/tmp/rndseek.XXXXXX";
8 static char tempdata[65 * 1024];
11 static int do_test (void);
12 #define TEST_FUNCTION do_test ()
15 #include "../test-skeleton.c"
19 fp_test (const char *name, FILE *fp)
26 int idx = random () % (sizeof (tempdata) - 2);
30 if (fseek (fp, idx, SEEK_SET) != 0)
32 printf ("%s: %d: fseek failed: %m\n", name, rounds);
37 ch1 = fgetc_unlocked (fp);
41 printf ("%s: %d: character at index %d not what is expected ('%c' vs '%c')\n",
42 name, rounds, idx, ch1, ch2);
48 ch2 = tempdata[idx + 1];
51 printf ("%s: %d: character at index %d not what is expected ('%c' vs '%c')\n",
52 name, rounds, idx + 1, ch1, ch2);
76 printf ("cannot open temporary file: %m\n");
79 /* Make sure the file gets removed. */
80 add_temp_file (fname);
82 /* Repeatability demands this. */
85 /* First create some temporary data. */
86 for (i = 0; i < sizeof (tempdata); ++i)
87 tempdata[i] = 'a' + random () % 26;
89 /* Write this data to a file. */
90 if (TEMP_FAILURE_RETRY (write (fd, tempdata, sizeof (tempdata)))
93 printf ("cannot wrote data to temporary file: %m\n");
97 /* Now try reading the data. */
98 fp = fdopen (dup (fd), "r");
101 printf ("cannot duplicate temporary file descriptor: %m\n");
106 for (i = 0; i < sizeof (tempdata); ++i)
108 int ch0 = fgetc (fp);
110 char ch2 = tempdata[i];
114 puts ("premature end of file while reading data");
120 printf ("%zd: '%c' vs '%c'\n", i, ch1, ch2);
125 result = fp_test ("fdopen(\"r\")", fp);
127 fp = fopen (fname, "r");
128 result |= fp_test ("fopen(\"r\")", fp);
130 fp = fopen64 (fname, "r");
131 result |= fp_test ("fopen64(\"r\")", fp);
133 /* The "rw" mode will prevent the mmap-using code from being used. */
134 fp = fdopen (fd, "rw");
135 result = fp_test ("fdopen(\"rw\")", fp);
137 fp = fopen (fname, "rw");
138 result |= fp_test ("fopen(\"rw\")", fp);
140 fp = fopen64 (fname, "rw");
141 result |= fp_test ("fopen64(\"rw\")", fp);