Back to index

glibc  2.9
tst-put-error.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <error.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <unistd.h>
00006 
00007 
00008 static int
00009 do_test (void)
00010 {
00011   char tmpl[] = "/tmp/tst-put-error.XXXXXX";
00012   int fd = mkstemp (tmpl);
00013   if (fd == -1)
00014     error (EXIT_FAILURE, errno, "cannot create temporary file");
00015   FILE *fp = fdopen (fd, "w");
00016   if (fp == NULL)
00017     error (EXIT_FAILURE, errno, "fdopen");
00018   setlinebuf (fp);
00019   close (fd);
00020   unlink (tmpl);
00021   int n = fprintf (fp, "hello world\n");
00022   printf ("fprintf = %d\n", n);
00023   if (n >= 0)
00024     error (EXIT_FAILURE, 0, "first fprintf succeeded");
00025   n = fprintf (fp, "hello world\n");
00026   printf ("fprintf = %d\n", n);
00027   if (n >= 0)
00028     error (EXIT_FAILURE, 0, "second fprintf succeeded");
00029   return 0;
00030 }
00031 
00032 #define TEST_FUNCTION do_test ()
00033 #include "../test-skeleton.c"