Back to index

glibc  2.9
tst-memstream1.c
Go to the documentation of this file.
00001 #include <mcheck.h>
00002 #include <stdio.h>
00003 
00004 
00005 #ifndef CHAR_T
00006 # define CHAR_T char
00007 # define W(o) o
00008 # define OPEN_MEMSTREAM open_memstream
00009 #endif
00010 
00011 #define S(s) S1 (s)
00012 #define S1(s) #s
00013 
00014 
00015 static void
00016 mcheck_abort (enum mcheck_status ev)
00017 {
00018   printf ("mecheck failed with status %d\n", (int) ev);
00019   exit (1);
00020 }
00021 
00022 
00023 static int
00024 do_test (void)
00025 {
00026   mcheck_pedantic (mcheck_abort);
00027 
00028   CHAR_T *buf = (CHAR_T *) 1l;
00029   size_t len = 12345;
00030   FILE *fp = OPEN_MEMSTREAM (&buf, &len);
00031   if (fp == NULL)
00032     {
00033       printf ("%s failed\n", S(OPEN_MEMSTREAM));
00034       return 1;
00035     }
00036 
00037   if (fflush (fp) != 0)
00038     {
00039       puts ("fflush failed");
00040       return 1;
00041     }
00042 
00043   if (len != 0)
00044     {
00045       puts ("string after no write not empty");
00046       return 1;
00047     }
00048   if (buf == (CHAR_T *) 1l)
00049     {
00050       puts ("buf not updated");
00051       return 1;
00052     }
00053   if (buf[0] != W('\0'))
00054     {
00055       puts ("buf[0] != 0");
00056       return 1;
00057     }
00058 
00059   buf = (CHAR_T *) 1l;
00060   len = 12345;
00061   if (fclose (fp) != 0)
00062     {
00063       puts ("fclose failed");
00064       return 1;
00065     }
00066 
00067   if (len != 0)
00068     {
00069       puts ("string after close with no write not empty");
00070       return 1;
00071     }
00072   if (buf == (CHAR_T *) 1l)
00073     {
00074       puts ("buf not updated");
00075       return 1;
00076     }
00077   if (buf[0] != W('\0'))
00078     {
00079       puts ("buf[0] != 0");
00080       return 1;
00081     }
00082 
00083   free (buf);
00084 
00085   return 0;
00086 }
00087 
00088 #define TEST_FUNCTION do_test ()
00089 #include "../test-skeleton.c"