1 /* Check that the syscalls implementing fdopen work trivially. 2 #output: This is the first line of this test.\npass\n 3 */ 4 5 #include <stdio.h> 6 #include <string.h> 7 #include <stdlib.h> 8 #include <sys/stat.h> 9 #include <fcntl.h> 10 11 void perr(const char * s)12perr (const char *s) 13 { 14 perror (s); 15 exit (1); 16 } 17 18 int main(void)19main (void) 20 { 21 FILE *f; 22 int fd; 23 const char fname[] = "sk1test.dat"; 24 const char tsttxt1[] 25 = "This is the first line of this test.\n"; 26 char buf[sizeof (tsttxt1)] = ""; 27 28 /* Write a line to stdout. */ 29 f = fdopen (1, "w"); 30 if (f == NULL 31 || fwrite (tsttxt1, 1, strlen (tsttxt1), f) != strlen (tsttxt1)) 32 perr ("fdopen or fwrite"); 33 34 #if 0 35 /* Unfortunately we can't get < /dev/null to the simulator with 36 reasonable test-framework surgery. */ 37 38 /* Try to read from stdin. Expect EOF. */ 39 f = fdopen (0, "r"); 40 if (f == NULL 41 || fread (buf, 1, sizeof (buf), f) != 0 42 || feof (f) == 0 43 || ferror (f) != 0) 44 { 45 printf ("fail\n"); 46 exit (1); 47 } 48 #endif 49 50 printf ("pass\n"); 51 exit (0); 52 } 53