1 /* Check for a sim bug, whereby an invalid seek (to a negative offset) 2 did not return an error. */ 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <errno.h> 7 #include <sys/types.h> 8 #include <sys/stat.h> 9 #include <fcntl.h> 10 #include <unistd.h> 11 12 int 13 main (void) 14 { 15 FILE *f; 16 const char fname[] = "sk1test.dat"; 17 const char tsttxt[] 18 = "A random line of text, used to test correct read, write and seek.\n"; 19 char buf[sizeof tsttxt] = ""; 20 int fd; 21 22 f = fopen (fname, "wb"); 23 if (f == NULL 24 || fwrite (tsttxt, 1, strlen (tsttxt), f) != strlen (tsttxt) 25 || fclose (f) != 0) 26 { 27 printf ("fail\n"); 28 exit (1); 29 } 30 31 fd = open (fname, O_RDONLY); 32 if (fd < 0 33 || lseek (fd, -1L, SEEK_CUR) != -1 34 || errno != EINVAL 35 || read (fd, buf, strlen (tsttxt)) != strlen (tsttxt) 36 || strcmp (buf, tsttxt) != 0) 37 { 38 printf ("fail\n"); 39 exit (1); 40 } 41 42 printf ("pass\n"); 43 exit (0); 44 } 45