input_buffer.cc (a3906ca572a6be18d39883a1ce431f147918385a) input_buffer.cc (21d5d37ba4c0131d6c141695366e266e32cc3bc1)
1/*-
2 * Copyright (c) 2013 David Chisnall
3 * All rights reserved.
4 *
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
8 *

--- 88 unchanged lines hidden (view full) ---

97 */
98 std::vector<char> b;
99 /**
100 * Constructs a new buffer from the standard input.
101 */
102 stream_input_buffer();
103};
104
1/*-
2 * Copyright (c) 2013 David Chisnall
3 * All rights reserved.
4 *
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
8 *

--- 88 unchanged lines hidden (view full) ---

97 */
98 std::vector<char> b;
99 /**
100 * Constructs a new buffer from the standard input.
101 */
102 stream_input_buffer();
103};
104
105mmap_input_buffer::mmap_input_buffer(int fd, std::string &&filename)
105mmap_input_buffer::mmap_input_buffer(int fd, string &&filename)
106 : input_buffer(0, 0), fn(filename)
107{
108 struct stat sb;
109 if (fstat(fd, &sb))
110 {
111 perror("Failed to stat file");
112 }
113 size = sb.st_size;

--- 97 unchanged lines hidden (view full) ---

211 consume('/');
212 }
213 next_token();
214 if (!consume('"'))
215 {
216 parse_error("Expected quoted filename");
217 return;
218 }
106 : input_buffer(0, 0), fn(filename)
107{
108 struct stat sb;
109 if (fstat(fd, &sb))
110 {
111 perror("Failed to stat file");
112 }
113 size = sb.st_size;

--- 97 unchanged lines hidden (view full) ---

211 consume('/');
212 }
213 next_token();
214 if (!consume('"'))
215 {
216 parse_error("Expected quoted filename");
217 return;
218 }
219 auto loc = location();
219 string file = parse_to('"');
220 consume('"');
221 if (!reallyInclude)
222 {
223 return;
224 }
225 string include_file = dir + '/' + file;
226 auto include_buffer = input_buffer::buffer_for_file(include_file, false);

--- 11 unchanged lines hidden (view full) ---

238 }
239 if (depfile)
240 {
241 putc(' ', depfile);
242 fputs(include_file.c_str(), depfile);
243 }
244 if (!include_buffer)
245 {
220 string file = parse_to('"');
221 consume('"');
222 if (!reallyInclude)
223 {
224 return;
225 }
226 string include_file = dir + '/' + file;
227 auto include_buffer = input_buffer::buffer_for_file(include_file, false);

--- 11 unchanged lines hidden (view full) ---

239 }
240 if (depfile)
241 {
242 putc(' ', depfile);
243 fputs(include_file.c_str(), depfile);
244 }
245 if (!include_buffer)
246 {
246 parse_error("Unable to locate input file");
247 loc.report_error("Unable to locate input file");
247 return;
248 }
249 input_stack.push(std::move(include_buffer));
250}
251
252input_buffer
253input_buffer::buffer_from_offset(int offset, int s)
254{

--- 954 unchanged lines hidden (view full) ---

1209 {
1210 if (warn)
1211 {
1212 fprintf(stderr, "File %s is a directory\n", path.c_str());
1213 }
1214 close(source);
1215 return 0;
1216 }
248 return;
249 }
250 input_stack.push(std::move(include_buffer));
251}
252
253input_buffer
254input_buffer::buffer_from_offset(int offset, int s)
255{

--- 954 unchanged lines hidden (view full) ---

1210 {
1211 if (warn)
1212 {
1213 fprintf(stderr, "File %s is a directory\n", path.c_str());
1214 }
1215 close(source);
1216 return 0;
1217 }
1217 std::unique_ptr<input_buffer> b(new mmap_input_buffer(source, std::string(path)));
1218 std::unique_ptr<input_buffer> b(new mmap_input_buffer(source, string(path)));
1218 close(source);
1219 return b;
1220}
1221
1222} // namespace dtc
1223
1219 close(source);
1220 return b;
1221}
1222
1223} // namespace dtc
1224