Ejemplo n.º 1
0
int
main ()
{
  static int sizes[] =
    {
       511,  512,  513,
      1023, 1024, 1025,
      2047, 2048, 2049,
      4095, 4096, 4097,
      8191, 8192, 8193
    };
  static char dummy[8193];
  unsigned int i, j;

  for (i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++)
    {
      size_t size = sizes[i];

      for (j = 0; j < 2; j++)
        {
          /* Run a test depending on i and j:
             Write size bytes and then calls fflush if j==1.  */
          FILE *stream = fopen (UNWRITABLE_FILE, "w");

          if (stream == NULL)
            {
              fprintf (stderr, "Test %u:%u: could not open file\n", i, j);
              continue;
            }

          fwrite (dummy, 347, 1, stream);
          fwrite (dummy, size - 347, 1, stream);
          if (j)
            fflush (stream);

          if (fwriteerror (stream) == -1)
            {
              if (errno != ENOSPC)
                fprintf (stderr, "Test %u:%u: fwriteerror ok, errno = %d\n",
                         i, j, errno);
            }
          else
            fprintf (stderr, "Test %u:%u: fwriteerror found no error!\n",
                     i, j);
        }
    }

  return 0;
}
Ejemplo n.º 2
0
int
msgdomain_write_xml_bulk (msgfmt_operand_list_ty *operands,
                          const char *template_file_name,
                          its_rule_list_ty *its_rules,
                          const char *file_name)
{
  its_merge_context_ty *context;
  size_t i;
  FILE *fp;

  if (strcmp (file_name, "-") == 0)
    fp = stdout;
  else
    {
      fp = fopen (file_name, "wb");
      if (fp == NULL)
        {
          error (0, errno, _("cannot create output file \"%s\""),
                 file_name);
          return 1;
        }
    }

  context = its_merge_context_alloc (its_rules, template_file_name);
  for (i = 0; i < operands->nitems; i++)
    its_merge_context_merge (context,
                             operands->items[i].language,
                             operands->items[i].mlp);
  its_merge_context_write (context, fp);
  its_merge_context_free (context);

  /* Make sure nothing went wrong.  */
  if (fwriteerror (fp))
    {
      error (0, errno, _("error while writing \"%s\" file"),
             file_name);
      return 1;
    }

  return 0;
}