/* Part of CPP library. File handling.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
+Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+along with this program; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
/* The contents of NAME after calling read_file(). */
const uchar *buffer;
+ /* Pointer to the real start of BUFFER. read_file() might increment
+ BUFFER; when freeing, this this pointer must be used instead. */
+ const uchar *buffer_start;
+
/* The macro, if any, preventing re-inclusion. */
const cpp_hashnode *cmacro;
/* If BUFFER above contains the true contents of the file. */
bool buffer_valid;
-
- /* File is a PCH (on return from find_include_file). */
- bool pch;
};
/* A singly-linked list for all searches for a given file name, with
}
closedir (pchdir);
}
- if (valid)
- file->pch = true;
- else
+ if (!valid)
*invalid_pch = true;
}
type. Use INTTYPE_MAXIMUM unconditionally to ensure this
does not bite us. */
#ifndef __BORLANDC__
- if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t))
+ if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t))
{
cpp_error (pfile, CPP_DL_ERROR, "%s is too large", file->path);
return false;
"%s is shorter than expected", file->path);
#endif
- file->buffer = _cpp_convert_input (pfile, CPP_OPTION (pfile, input_charset),
- buf, size, total, &file->st.st_size);
+ file->buffer = _cpp_convert_input (pfile,
+ CPP_OPTION (pfile, input_charset),
+ buf, size, total,
+ &file->buffer_start,
+ &file->st.st_size);
file->buffer_valid = true;
return true;
return false;
/* Handle PCH files immediately; don't stack them. */
- if (file->pch)
+ if (file->pchname)
{
pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path);
- close (file->fd);
file->fd = -1;
+ free ((void *) file->pchname);
+ file->pchname = NULL;
return false;
}
complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we
found a PCH file (in which case linemap_add is not called) or we
were included from the command-line. */
- if (! file->pch && file->err_no == 0 && type != IT_CMDLINE)
+ if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE)
pfile->line_table->highest_location--;
- return _cpp_stack_file (pfile, file, type == IT_IMPORT);
+ return _cpp_stack_file (pfile, file, (bool)(type == IT_IMPORT));
}
/* Could not open FILE. The complication is dependency output. */
static void
destroy_cpp_file (_cpp_file *file)
{
- if (file->buffer)
- free ((void *) file->buffer);
+ if (file->buffer_start)
+ free ((void *) file->buffer_start);
free ((void *) file->name);
free (file);
}
/* Invalidate control macros in the #including file. */
pfile->mi_valid = false;
- if (file->buffer)
+ if (file->buffer_start)
{
- free ((void *) file->buffer);
+ free ((void *) file->buffer_start);
+ file->buffer_start = NULL;
file->buffer = NULL;
file->buffer_valid = false;
}