Commit 41e7ac51 by Basile Starynkevitch Committed by Rafael Espindola

gengtype.c (is_file_equal): New function.

2009-09-22  Basile Starynkevitch  <basile@starynkevitch.net>
            Rafael Avila de Espindola  <espindola@google.com>

	* gengtype.c (is_file_equal): New function.
	(close_output_files): Use is_file_equal. Free of->buf.


Co-Authored-By: Rafael Avila de Espindola <espindola@google.com>

From-SVN: r152049
parent 0182d016
2009-09-22 Basile Starynkevitch <basile@starynkevitch.net>
Rafael Avila de Espindola <espindola@google.com>
* gengtype.c (is_file_equal): New function.
(close_output_files): Use is_file_equal. Free of->buf.
2009-09-22 Basile Starynkevitch <basile@starynkevitch.net>
Rafael Avila de Espindola <espindola@google.com>
* gengtype.c (write_types, write_local): Add the output_header
argument. Update all callers.
......
......@@ -1794,39 +1794,46 @@ get_output_file_name (const char *input_file)
return NULL;
}
/* Copy the output to its final destination,
but don't unnecessarily change modification times. */
/* Check if existing file is equal to the in memory buffer. */
static void
close_output_files (void)
static bool
is_file_equal (outf_p of)
{
outf_p of;
for (of = output_files; of; of = of->next)
{
FILE * newfile;
newfile = fopen (of->name, "r");
if (newfile != NULL )
{
int no_write_p;
FILE *newfile = fopen (of->name, "r");
size_t i;
bool equal;
if (newfile == NULL)
return false;
equal = true;
for (i = 0; i < of->bufused; i++)
{
int ch;
ch = fgetc (newfile);
if (ch == EOF || ch != (unsigned char) of->buf[i])
{
equal = false;
break;
}
no_write_p = i == of->bufused && fgetc (newfile) == EOF;
}
fclose (newfile);
return equal;
}
if (no_write_p)
continue;
}
/* Copy the output to its final destination,
but don't unnecessarily change modification times. */
newfile = fopen (of->name, "w");
static void
close_output_files (void)
{
outf_p of;
for (of = output_files; of; of = of->next)
{
if (!is_file_equal(of))
{
FILE *newfile = fopen (of->name, "w");
if (newfile == NULL)
fatal ("opening output file %s: %s", of->name, strerror (errno));
if (fwrite (of->buf, 1, of->bufused, newfile) != of->bufused)
......@@ -1834,6 +1841,10 @@ close_output_files (void)
if (fclose (newfile) != 0)
fatal ("closing output file %s: %s", of->name, strerror (errno));
}
free(of->buf);
of->buf = NULL;
of->bufused = of->buflength = 0;
}
}
struct flist {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment