files.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979
  1. /* Part of CPP library. File handling.
  2. Copyright (C) 1986-2015 Free Software Foundation, Inc.
  3. Written by Per Bothner, 1994.
  4. Based on CCCP program by Paul Rubin, June 1986
  5. Adapted to ANSI C, Richard Stallman, Jan 1987
  6. Split out of cpplib.c, Zack Weinberg, Oct 1998
  7. Reimplemented, Neil Booth, Jul 2003
  8. This program is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 3, or (at your option) any
  11. later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; see the file COPYING3. If not see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "cpplib.h"
  22. #include "internal.h"
  23. #include "mkdeps.h"
  24. #include "obstack.h"
  25. #include "hashtab.h"
  26. #include "md5.h"
  27. #include <dirent.h>
  28. /* Variable length record files on VMS will have a stat size that includes
  29. record control characters that won't be included in the read size. */
  30. #ifdef VMS
  31. # define FAB_C_VAR 2 /* variable length records (see Starlet fabdef.h) */
  32. # define STAT_SIZE_RELIABLE(ST) ((ST).st_fab_rfm != FAB_C_VAR)
  33. #else
  34. # define STAT_SIZE_RELIABLE(ST) true
  35. #endif
  36. #ifdef __DJGPP__
  37. #include <io.h>
  38. /* For DJGPP redirected input is opened in text mode. */
  39. # define set_stdin_to_binary_mode() \
  40. if (! isatty (0)) setmode (0, O_BINARY)
  41. #else
  42. # define set_stdin_to_binary_mode() /* Nothing */
  43. #endif
  44. /* This structure represents a file searched for by CPP, whether it
  45. exists or not. An instance may be pointed to by more than one
  46. cpp_file_hash_entry; at present no reference count is kept. */
  47. struct _cpp_file
  48. {
  49. /* Filename as given to #include or command line switch. */
  50. const char *name;
  51. /* The full path used to find the file. */
  52. const char *path;
  53. /* The full path of the pch file. */
  54. const char *pchname;
  55. /* The file's path with the basename stripped. NULL if it hasn't
  56. been calculated yet. */
  57. const char *dir_name;
  58. /* Chain through all files. */
  59. struct _cpp_file *next_file;
  60. /* The contents of NAME after calling read_file(). */
  61. const uchar *buffer;
  62. /* Pointer to the real start of BUFFER. read_file() might increment
  63. BUFFER; when freeing, this this pointer must be used instead. */
  64. const uchar *buffer_start;
  65. /* The macro, if any, preventing re-inclusion. */
  66. const cpp_hashnode *cmacro;
  67. /* The directory in the search path where FILE was found. Used for
  68. #include_next and determining whether a header is a system
  69. header. */
  70. cpp_dir *dir;
  71. /* As filled in by stat(2) for the file. */
  72. struct stat st;
  73. /* File descriptor. Invalid if -1, otherwise open. */
  74. int fd;
  75. /* Zero if this file was successfully opened and stat()-ed,
  76. otherwise errno obtained from failure. */
  77. int err_no;
  78. /* Number of times the file has been stacked for preprocessing. */
  79. unsigned short stack_count;
  80. /* If opened with #import or contains #pragma once. */
  81. bool once_only;
  82. /* If read() failed before. */
  83. bool dont_read;
  84. /* If this file is the main file. */
  85. bool main_file;
  86. /* If BUFFER above contains the true contents of the file. */
  87. bool buffer_valid;
  88. /* If this file is implicitly preincluded. */
  89. bool implicit_preinclude;
  90. };
  91. /* A singly-linked list for all searches for a given file name, with
  92. its head pointed to by a slot in FILE_HASH. The file name is what
  93. appeared between the quotes in a #include directive; it can be
  94. determined implicitly from the hash table location or explicitly
  95. from FILE->name.
  96. FILE is a structure containing details about the file that was
  97. found with that search, or details of how the search failed.
  98. START_DIR is the starting location of the search in the include
  99. chain. The current directories for "" includes are also hashed in
  100. the hash table and therefore unique. Files that are looked up
  101. without using a search path, such as absolute filenames and file
  102. names from the command line share a special starting directory so
  103. they don't cause cache hits with normal include-chain lookups.
  104. If START_DIR is NULL then the entry is for a directory, not a file,
  105. and the directory is in DIR. Since the starting point in a file
  106. lookup chain is never NULL, this means that simple pointer
  107. comparisons against START_DIR can be made to determine cache hits
  108. in file lookups.
  109. If a cache lookup fails because of e.g. an extra "./" in the path,
  110. then nothing will break. It is just less efficient as CPP will
  111. have to do more work re-preprocessing the file, and/or comparing
  112. its contents against earlier once-only files.
  113. */
  114. struct cpp_file_hash_entry
  115. {
  116. struct cpp_file_hash_entry *next;
  117. cpp_dir *start_dir;
  118. source_location location;
  119. union
  120. {
  121. _cpp_file *file;
  122. cpp_dir *dir;
  123. } u;
  124. };
  125. /* Number of entries to put in a cpp_file_hash_entry pool. */
  126. #define FILE_HASH_POOL_SIZE 127
  127. /* A file hash entry pool. We allocate cpp_file_hash_entry object from
  128. one of these. */
  129. struct file_hash_entry_pool
  130. {
  131. /* Number of entries used from this pool. */
  132. unsigned int file_hash_entries_used;
  133. /* Next pool in the chain; used when freeing. */
  134. struct file_hash_entry_pool *next;
  135. /* The memory pool. */
  136. struct cpp_file_hash_entry pool[FILE_HASH_POOL_SIZE];
  137. };
  138. static bool open_file (_cpp_file *file);
  139. static bool pch_open_file (cpp_reader *pfile, _cpp_file *file,
  140. bool *invalid_pch);
  141. static bool find_file_in_dir (cpp_reader *pfile, _cpp_file *file,
  142. bool *invalid_pch);
  143. static bool read_file_guts (cpp_reader *pfile, _cpp_file *file);
  144. static bool read_file (cpp_reader *pfile, _cpp_file *file);
  145. static bool should_stack_file (cpp_reader *, _cpp_file *file, bool import);
  146. static struct cpp_dir *search_path_head (cpp_reader *, const char *fname,
  147. int angle_brackets, enum include_type);
  148. static const char *dir_name_of_file (_cpp_file *file);
  149. static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int);
  150. static struct cpp_file_hash_entry *search_cache (struct cpp_file_hash_entry *head,
  151. const cpp_dir *start_dir);
  152. static _cpp_file *make_cpp_file (cpp_reader *, cpp_dir *, const char *fname);
  153. static void destroy_cpp_file (_cpp_file *);
  154. static cpp_dir *make_cpp_dir (cpp_reader *, const char *dir_name, int sysp);
  155. static void allocate_file_hash_entries (cpp_reader *pfile);
  156. static struct cpp_file_hash_entry *new_file_hash_entry (cpp_reader *pfile);
  157. static int report_missing_guard (void **slot, void *b);
  158. static hashval_t file_hash_hash (const void *p);
  159. static int file_hash_eq (const void *p, const void *q);
  160. static char *read_filename_string (int ch, FILE *f);
  161. static void read_name_map (cpp_dir *dir);
  162. static char *remap_filename (cpp_reader *pfile, _cpp_file *file);
  163. static char *append_file_to_dir (const char *fname, cpp_dir *dir);
  164. static bool validate_pch (cpp_reader *, _cpp_file *file, const char *pchname);
  165. static int pchf_save_compare (const void *e1, const void *e2);
  166. static int pchf_compare (const void *d_p, const void *e_p);
  167. static bool check_file_against_entries (cpp_reader *, _cpp_file *, bool);
  168. /* Given a filename in FILE->PATH, with the empty string interpreted
  169. as <stdin>, open it.
  170. On success FILE contains an open file descriptor and stat
  171. information for the file. On failure the file descriptor is -1 and
  172. the appropriate errno is also stored in FILE. Returns TRUE iff
  173. successful.
  174. We used to open files in nonblocking mode, but that caused more
  175. problems than it solved. Do take care not to acquire a controlling
  176. terminal by mistake (this can't happen on sane systems, but
  177. paranoia is a virtue).
  178. Use the three-argument form of open even though we aren't
  179. specifying O_CREAT, to defend against broken system headers.
  180. O_BINARY tells some runtime libraries (notably DJGPP) not to do
  181. newline translation; we can handle DOS line breaks just fine
  182. ourselves. */
  183. static bool
  184. open_file (_cpp_file *file)
  185. {
  186. if (file->path[0] == '\0')
  187. {
  188. file->fd = 0;
  189. set_stdin_to_binary_mode ();
  190. }
  191. else
  192. file->fd = open (file->path, O_RDONLY | O_NOCTTY | O_BINARY, 0666);
  193. if (file->fd != -1)
  194. {
  195. if (fstat (file->fd, &file->st) == 0)
  196. {
  197. if (!S_ISDIR (file->st.st_mode))
  198. {
  199. file->err_no = 0;
  200. return true;
  201. }
  202. /* Ignore a directory and continue the search. The file we're
  203. looking for may be elsewhere in the search path. */
  204. errno = ENOENT;
  205. }
  206. close (file->fd);
  207. file->fd = -1;
  208. }
  209. #if defined(_WIN32) && !defined(__CYGWIN__)
  210. else if (errno == EACCES)
  211. {
  212. /* On most UNIX systems, open succeeds on a directory. Above,
  213. we check if we have opened a directory and if so, set errno
  214. to ENOENT. However, on Windows, opening a directory
  215. fails with EACCES. We want to return ENOENT in that
  216. case too. */
  217. if (stat (file->path, &file->st) == 0
  218. && S_ISDIR (file->st.st_mode))
  219. errno = ENOENT;
  220. else
  221. /* The call to stat may have reset errno. */
  222. errno = EACCES;
  223. }
  224. #endif
  225. else if (errno == ENOTDIR)
  226. errno = ENOENT;
  227. file->err_no = errno;
  228. return false;
  229. }
  230. /* Temporary PCH intercept of opening a file. Try to find a PCH file
  231. based on FILE->name and FILE->dir, and test those found for
  232. validity using PFILE->cb.valid_pch. Return true iff a valid file is
  233. found. Set *INVALID_PCH if a PCH file is found but wasn't valid. */
  234. static bool
  235. pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
  236. {
  237. static const char extension[] = ".gch";
  238. const char *path = file->path;
  239. size_t len, flen;
  240. char *pchname;
  241. struct stat st;
  242. bool valid = false;
  243. /* No PCH on <stdin> or if not requested. */
  244. if (file->name[0] == '\0' || !pfile->cb.valid_pch)
  245. return false;
  246. /* If the file is not included as first include from either the toplevel
  247. file or the command-line it is not a valid use of PCH. */
  248. for (_cpp_file *f = pfile->all_files; f; f = f->next_file)
  249. if (f->implicit_preinclude)
  250. continue;
  251. else if (f->main_file)
  252. break;
  253. else
  254. return false;
  255. flen = strlen (path);
  256. len = flen + sizeof (extension);
  257. pchname = XNEWVEC (char, len);
  258. memcpy (pchname, path, flen);
  259. memcpy (pchname + flen, extension, sizeof (extension));
  260. if (stat (pchname, &st) == 0)
  261. {
  262. DIR *pchdir;
  263. struct dirent *d;
  264. size_t dlen, plen = len;
  265. if (!S_ISDIR (st.st_mode))
  266. valid = validate_pch (pfile, file, pchname);
  267. else if ((pchdir = opendir (pchname)) != NULL)
  268. {
  269. pchname[plen - 1] = '/';
  270. while ((d = readdir (pchdir)) != NULL)
  271. {
  272. dlen = strlen (d->d_name) + 1;
  273. if ((strcmp (d->d_name, ".") == 0)
  274. || (strcmp (d->d_name, "..") == 0))
  275. continue;
  276. if (dlen + plen > len)
  277. {
  278. len += dlen + 64;
  279. pchname = XRESIZEVEC (char, pchname, len);
  280. }
  281. memcpy (pchname + plen, d->d_name, dlen);
  282. valid = validate_pch (pfile, file, pchname);
  283. if (valid)
  284. break;
  285. }
  286. closedir (pchdir);
  287. }
  288. if (!valid)
  289. *invalid_pch = true;
  290. }
  291. if (valid)
  292. file->pchname = pchname;
  293. else
  294. free (pchname);
  295. return valid;
  296. }
  297. /* Canonicalize the path to FILE. Return the canonical form if it is
  298. shorter, otherwise return NULL. This function does NOT free the
  299. memory pointed by FILE. */
  300. static char *
  301. maybe_shorter_path (const char * file)
  302. {
  303. char * file2 = lrealpath (file);
  304. if (file2 && strlen (file2) < strlen (file))
  305. {
  306. return file2;
  307. }
  308. else
  309. {
  310. free (file2);
  311. return NULL;
  312. }
  313. }
  314. /* Try to open the path FILE->name appended to FILE->dir. This is
  315. where remap and PCH intercept the file lookup process. Return true
  316. if the file was found, whether or not the open was successful.
  317. Set *INVALID_PCH to true if a PCH file is found but wasn't valid. */
  318. static bool
  319. find_file_in_dir (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
  320. {
  321. char *path;
  322. if (CPP_OPTION (pfile, remap) && (path = remap_filename (pfile, file)))
  323. ;
  324. else
  325. if (file->dir->construct)
  326. path = file->dir->construct (file->name, file->dir);
  327. else
  328. path = append_file_to_dir (file->name, file->dir);
  329. if (path)
  330. {
  331. hashval_t hv;
  332. char *copy;
  333. void **pp;
  334. /* We try to canonicalize system headers. For DOS based file
  335. * system, we always try to shorten non-system headers, as DOS
  336. * has a tighter constraint on max path length. */
  337. if ((CPP_OPTION (pfile, canonical_system_headers) && file->dir->sysp)
  338. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  339. || !file->dir->sysp
  340. #endif
  341. )
  342. {
  343. char * canonical_path = maybe_shorter_path (path);
  344. if (canonical_path)
  345. {
  346. /* The canonical path was newly allocated. Let's free the
  347. non-canonical one. */
  348. free (path);
  349. path = canonical_path;
  350. }
  351. }
  352. hv = htab_hash_string (path);
  353. if (htab_find_with_hash (pfile->nonexistent_file_hash, path, hv) != NULL)
  354. {
  355. file->err_no = ENOENT;
  356. return false;
  357. }
  358. file->path = path;
  359. if (pch_open_file (pfile, file, invalid_pch))
  360. return true;
  361. if (open_file (file))
  362. return true;
  363. if (file->err_no != ENOENT)
  364. {
  365. open_file_failed (pfile, file, 0);
  366. return true;
  367. }
  368. /* We copy the path name onto an obstack partly so that we don't
  369. leak the memory, but mostly so that we don't fragment the
  370. heap. */
  371. copy = (char *) obstack_copy0 (&pfile->nonexistent_file_ob, path,
  372. strlen (path));
  373. free (path);
  374. pp = htab_find_slot_with_hash (pfile->nonexistent_file_hash,
  375. copy, hv, INSERT);
  376. *pp = copy;
  377. file->path = file->name;
  378. }
  379. else
  380. {
  381. file->err_no = ENOENT;
  382. file->path = NULL;
  383. }
  384. return false;
  385. }
  386. /* Return tue iff the missing_header callback found the given HEADER. */
  387. static bool
  388. search_path_exhausted (cpp_reader *pfile, const char *header, _cpp_file *file)
  389. {
  390. missing_header_cb func = pfile->cb.missing_header;
  391. /* When the regular search path doesn't work, try context dependent
  392. headers search paths. */
  393. if (func
  394. && file->dir == NULL)
  395. {
  396. if ((file->path = func (pfile, header, &file->dir)) != NULL)
  397. {
  398. if (open_file (file))
  399. return true;
  400. free ((void *)file->path);
  401. }
  402. file->path = file->name;
  403. }
  404. return false;
  405. }
  406. bool
  407. _cpp_find_failed (_cpp_file *file)
  408. {
  409. return file->err_no != 0;
  410. }
  411. /* Given a filename FNAME search for such a file in the include path
  412. starting from START_DIR. If FNAME is the empty string it is
  413. interpreted as STDIN if START_DIR is PFILE->no_search_path.
  414. If the file is not found in the file cache fall back to the O/S and
  415. add the result to our cache.
  416. If the file was not found in the filesystem, or there was an error
  417. opening it, then ERR_NO is nonzero and FD is -1. If the file was
  418. found, then ERR_NO is zero and FD could be -1 or an open file
  419. descriptor. FD can be -1 if the file was found in the cache and
  420. had previously been closed. To open it again pass the return value
  421. to open_file().
  422. If IMPLICIT_PREINCLUDE then it is OK for the file to be missing.
  423. If present, it is OK for a precompiled header to be included after
  424. it.
  425. */
  426. _cpp_file *
  427. _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
  428. bool fake, int angle_brackets, bool implicit_preinclude)
  429. {
  430. struct cpp_file_hash_entry *entry;
  431. void **hash_slot;
  432. _cpp_file *file;
  433. bool invalid_pch = false;
  434. bool saw_bracket_include = false;
  435. bool saw_quote_include = false;
  436. struct cpp_dir *found_in_cache = NULL;
  437. /* Ensure we get no confusion between cached files and directories. */
  438. if (start_dir == NULL)
  439. cpp_error (pfile, CPP_DL_ICE, "NULL directory in find_file");
  440. hash_slot
  441. = htab_find_slot_with_hash (pfile->file_hash, fname,
  442. htab_hash_string (fname), INSERT);
  443. /* First check the cache before we resort to memory allocation. */
  444. entry = search_cache ((struct cpp_file_hash_entry *) *hash_slot, start_dir);
  445. if (entry)
  446. return entry->u.file;
  447. file = make_cpp_file (pfile, start_dir, fname);
  448. file->implicit_preinclude = implicit_preinclude;
  449. /* Try each path in the include chain. */
  450. for (; !fake ;)
  451. {
  452. if (find_file_in_dir (pfile, file, &invalid_pch))
  453. break;
  454. file->dir = file->dir->next;
  455. if (file->dir == NULL)
  456. {
  457. if (search_path_exhausted (pfile, fname, file))
  458. {
  459. /* Although this file must not go in the cache, because
  460. the file found might depend on things (like the current file)
  461. that aren't represented in the cache, it still has to go in
  462. the list of all files so that #import works. */
  463. file->next_file = pfile->all_files;
  464. pfile->all_files = file;
  465. if (*hash_slot == NULL)
  466. {
  467. /* If *hash_slot is NULL, the above htab_find_slot_with_hash
  468. call just created the slot, but we aren't going to store
  469. there anything, so need to remove the newly created entry.
  470. htab_clear_slot requires that it is non-NULL, so store
  471. there some non-NULL pointer, htab_clear_slot will
  472. overwrite it immediately. */
  473. *hash_slot = file;
  474. htab_clear_slot (pfile->file_hash, hash_slot);
  475. }
  476. return file;
  477. }
  478. if (invalid_pch)
  479. {
  480. cpp_error (pfile, CPP_DL_ERROR,
  481. "one or more PCH files were found, but they were invalid");
  482. if (!cpp_get_options (pfile)->warn_invalid_pch)
  483. cpp_error (pfile, CPP_DL_ERROR,
  484. "use -Winvalid-pch for more information");
  485. }
  486. if (implicit_preinclude)
  487. {
  488. free ((char *) file->name);
  489. free (file);
  490. if (*hash_slot == NULL)
  491. {
  492. /* See comment on the above htab_clear_slot call. */
  493. *hash_slot = file;
  494. htab_clear_slot (pfile->file_hash, hash_slot);
  495. }
  496. return NULL;
  497. }
  498. else
  499. open_file_failed (pfile, file, angle_brackets);
  500. break;
  501. }
  502. /* Only check the cache for the starting location (done above)
  503. and the quote and bracket chain heads because there are no
  504. other possible starting points for searches. */
  505. if (file->dir == pfile->bracket_include)
  506. saw_bracket_include = true;
  507. else if (file->dir == pfile->quote_include)
  508. saw_quote_include = true;
  509. else
  510. continue;
  511. entry = search_cache ((struct cpp_file_hash_entry *) *hash_slot, file->dir);
  512. if (entry)
  513. {
  514. found_in_cache = file->dir;
  515. break;
  516. }
  517. }
  518. if (entry)
  519. {
  520. /* Cache for START_DIR too, sharing the _cpp_file structure. */
  521. free ((char *) file->name);
  522. free (file);
  523. file = entry->u.file;
  524. }
  525. else
  526. {
  527. /* This is a new file; put it in the list. */
  528. file->next_file = pfile->all_files;
  529. pfile->all_files = file;
  530. }
  531. /* Store this new result in the hash table. */
  532. entry = new_file_hash_entry (pfile);
  533. entry->next = (struct cpp_file_hash_entry *) *hash_slot;
  534. entry->start_dir = start_dir;
  535. entry->location = pfile->line_table->highest_location;
  536. entry->u.file = file;
  537. *hash_slot = (void *) entry;
  538. /* If we passed the quote or bracket chain heads, cache them also.
  539. This speeds up processing if there are lots of -I options. */
  540. if (saw_bracket_include
  541. && pfile->bracket_include != start_dir
  542. && found_in_cache != pfile->bracket_include)
  543. {
  544. entry = new_file_hash_entry (pfile);
  545. entry->next = (struct cpp_file_hash_entry *) *hash_slot;
  546. entry->start_dir = pfile->bracket_include;
  547. entry->location = pfile->line_table->highest_location;
  548. entry->u.file = file;
  549. *hash_slot = (void *) entry;
  550. }
  551. if (saw_quote_include
  552. && pfile->quote_include != start_dir
  553. && found_in_cache != pfile->quote_include)
  554. {
  555. entry = new_file_hash_entry (pfile);
  556. entry->next = (struct cpp_file_hash_entry *) *hash_slot;
  557. entry->start_dir = pfile->quote_include;
  558. entry->location = pfile->line_table->highest_location;
  559. entry->u.file = file;
  560. *hash_slot = (void *) entry;
  561. }
  562. return file;
  563. }
  564. /* Read a file into FILE->buffer, returning true on success.
  565. If FILE->fd is something weird, like a block device, we don't want
  566. to read it at all. Don't even try to figure out what something is,
  567. except for plain files and block devices, since there is no
  568. reliable portable way of doing this.
  569. FIXME: Flush file cache and try again if we run out of memory. */
  570. static bool
  571. read_file_guts (cpp_reader *pfile, _cpp_file *file)
  572. {
  573. ssize_t size, total, count;
  574. uchar *buf;
  575. bool regular;
  576. if (S_ISBLK (file->st.st_mode))
  577. {
  578. cpp_error (pfile, CPP_DL_ERROR, "%s is a block device", file->path);
  579. return false;
  580. }
  581. regular = S_ISREG (file->st.st_mode) != 0;
  582. if (regular)
  583. {
  584. /* off_t might have a wider range than ssize_t - in other words,
  585. the max size of a file might be bigger than the address
  586. space. We can't handle a file that large. (Anyone with
  587. a single source file bigger than 2GB needs to rethink
  588. their coding style.) Some systems (e.g. AIX 4.1) define
  589. SSIZE_MAX to be much smaller than the actual range of the
  590. type. Use INTTYPE_MAXIMUM unconditionally to ensure this
  591. does not bite us. */
  592. if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t))
  593. {
  594. cpp_error (pfile, CPP_DL_ERROR, "%s is too large", file->path);
  595. return false;
  596. }
  597. size = file->st.st_size;
  598. }
  599. else
  600. /* 8 kilobytes is a sensible starting size. It ought to be bigger
  601. than the kernel pipe buffer, and it's definitely bigger than
  602. the majority of C source files. */
  603. size = 8 * 1024;
  604. /* The + 16 here is space for the final '\n' and 15 bytes of padding,
  605. used to quiet warnings from valgrind or Address Sanitizer, when the
  606. optimized lexer accesses aligned 16-byte memory chunks, including
  607. the bytes after the malloced, area, and stops lexing on '\n'. */
  608. buf = XNEWVEC (uchar, size + 16);
  609. total = 0;
  610. while ((count = read (file->fd, buf + total, size - total)) > 0)
  611. {
  612. total += count;
  613. if (total == size)
  614. {
  615. if (regular)
  616. break;
  617. size *= 2;
  618. buf = XRESIZEVEC (uchar, buf, size + 16);
  619. }
  620. }
  621. if (count < 0)
  622. {
  623. cpp_errno (pfile, CPP_DL_ERROR, file->path);
  624. free (buf);
  625. return false;
  626. }
  627. if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
  628. cpp_error (pfile, CPP_DL_WARNING,
  629. "%s is shorter than expected", file->path);
  630. file->buffer = _cpp_convert_input (pfile,
  631. CPP_OPTION (pfile, input_charset),
  632. buf, size + 16, total,
  633. &file->buffer_start,
  634. &file->st.st_size);
  635. file->buffer_valid = true;
  636. return true;
  637. }
  638. /* Convenience wrapper around read_file_guts that opens the file if
  639. necessary and closes the file descriptor after reading. FILE must
  640. have been passed through find_file() at some stage. */
  641. static bool
  642. read_file (cpp_reader *pfile, _cpp_file *file)
  643. {
  644. /* If we already have its contents in memory, succeed immediately. */
  645. if (file->buffer_valid)
  646. return true;
  647. /* If an earlier read failed for some reason don't try again. */
  648. if (file->dont_read || file->err_no)
  649. return false;
  650. if (file->fd == -1 && !open_file (file))
  651. {
  652. open_file_failed (pfile, file, 0);
  653. return false;
  654. }
  655. file->dont_read = !read_file_guts (pfile, file);
  656. close (file->fd);
  657. file->fd = -1;
  658. return !file->dont_read;
  659. }
  660. /* Returns TRUE if FILE's contents have been successfully placed in
  661. FILE->buffer and the file should be stacked, otherwise false. */
  662. static bool
  663. should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
  664. {
  665. _cpp_file *f;
  666. /* Skip once-only files. */
  667. if (file->once_only)
  668. return false;
  669. /* We must mark the file once-only if #import now, before header
  670. guard checks. Otherwise, undefining the header guard might
  671. cause the file to be re-stacked. */
  672. if (import)
  673. {
  674. _cpp_mark_file_once_only (pfile, file);
  675. /* Don't stack files that have been stacked before. */
  676. if (file->stack_count)
  677. return false;
  678. }
  679. /* Skip if the file had a header guard and the macro is defined.
  680. PCH relies on this appearing before the PCH handler below. */
  681. if (file->cmacro && file->cmacro->type == NT_MACRO)
  682. return false;
  683. /* Handle PCH files immediately; don't stack them. */
  684. if (file->pchname)
  685. {
  686. pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path);
  687. file->fd = -1;
  688. free ((void *) file->pchname);
  689. file->pchname = NULL;
  690. return false;
  691. }
  692. if (!read_file (pfile, file))
  693. return false;
  694. /* Check the file against the PCH file. This is done before
  695. checking against files we've already seen, since it may save on
  696. I/O. */
  697. if (check_file_against_entries (pfile, file, import))
  698. {
  699. /* If this isn't a #import, but yet we can't include the file,
  700. that means that it was #import-ed in the PCH file,
  701. so we can never include it again. */
  702. if (! import)
  703. _cpp_mark_file_once_only (pfile, file);
  704. return false;
  705. }
  706. /* Now we've read the file's contents, we can stack it if there
  707. are no once-only files. */
  708. if (!pfile->seen_once_only)
  709. return true;
  710. /* We may have read the file under a different name. Look
  711. for likely candidates and compare file contents to be sure. */
  712. for (f = pfile->all_files; f; f = f->next_file)
  713. {
  714. if (f == file)
  715. continue;
  716. if ((import || f->once_only)
  717. && f->err_no == 0
  718. && f->st.st_mtime == file->st.st_mtime
  719. && f->st.st_size == file->st.st_size)
  720. {
  721. _cpp_file *ref_file;
  722. bool same_file_p = false;
  723. if (f->buffer && !f->buffer_valid)
  724. {
  725. /* We already have a buffer but it is not valid, because
  726. the file is still stacked. Make a new one. */
  727. ref_file = make_cpp_file (pfile, f->dir, f->name);
  728. ref_file->path = f->path;
  729. }
  730. else
  731. /* The file is not stacked anymore. We can reuse it. */
  732. ref_file = f;
  733. same_file_p = read_file (pfile, ref_file)
  734. /* Size might have changed in read_file(). */
  735. && ref_file->st.st_size == file->st.st_size
  736. && !memcmp (ref_file->buffer,
  737. file->buffer,
  738. file->st.st_size);
  739. if (f->buffer && !f->buffer_valid)
  740. {
  741. ref_file->path = 0;
  742. destroy_cpp_file (ref_file);
  743. }
  744. if (same_file_p)
  745. break;
  746. }
  747. }
  748. return f == NULL;
  749. }
  750. /* Place the file referenced by FILE into a new buffer on the buffer
  751. stack if possible. IMPORT is true if this stacking attempt is
  752. because of a #import directive. Returns true if a buffer is
  753. stacked. */
  754. bool
  755. _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
  756. {
  757. cpp_buffer *buffer;
  758. int sysp;
  759. if (!should_stack_file (pfile, file, import))
  760. return false;
  761. if (pfile->buffer == NULL || file->dir == NULL)
  762. sysp = 0;
  763. else
  764. sysp = MAX (pfile->buffer->sysp, file->dir->sysp);
  765. /* Add the file to the dependencies on its first inclusion. */
  766. if (CPP_OPTION (pfile, deps.style) > !!sysp && !file->stack_count)
  767. {
  768. if (!file->main_file || !CPP_OPTION (pfile, deps.ignore_main_file))
  769. deps_add_dep (pfile->deps, file->path);
  770. }
  771. /* Clear buffer_valid since _cpp_clean_line messes it up. */
  772. file->buffer_valid = false;
  773. file->stack_count++;
  774. /* Stack the buffer. */
  775. buffer = cpp_push_buffer (pfile, file->buffer, file->st.st_size,
  776. CPP_OPTION (pfile, preprocessed)
  777. && !CPP_OPTION (pfile, directives_only));
  778. buffer->file = file;
  779. buffer->sysp = sysp;
  780. buffer->to_free = file->buffer_start;
  781. /* Initialize controlling macro state. */
  782. pfile->mi_valid = true;
  783. pfile->mi_cmacro = 0;
  784. /* Generate the call back. */
  785. _cpp_do_file_change (pfile, LC_ENTER, file->path, 1, sysp);
  786. return true;
  787. }
  788. /* Mark FILE to be included once only. */
  789. void
  790. _cpp_mark_file_once_only (cpp_reader *pfile, _cpp_file *file)
  791. {
  792. pfile->seen_once_only = true;
  793. file->once_only = true;
  794. }
  795. /* Return the directory from which searching for FNAME should start,
  796. considering the directive TYPE and ANGLE_BRACKETS. If there is
  797. nothing left in the path, returns NULL. */
  798. static struct cpp_dir *
  799. search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets,
  800. enum include_type type)
  801. {
  802. cpp_dir *dir;
  803. _cpp_file *file;
  804. if (IS_ABSOLUTE_PATH (fname))
  805. return &pfile->no_search_path;
  806. /* pfile->buffer is NULL when processing an -include command-line flag. */
  807. file = pfile->buffer == NULL ? pfile->main_file : pfile->buffer->file;
  808. /* For #include_next, skip in the search path past the dir in which
  809. the current file was found, but if it was found via an absolute
  810. path use the normal search logic. */
  811. if (type == IT_INCLUDE_NEXT && file->dir
  812. && file->dir != &pfile->no_search_path)
  813. dir = file->dir->next;
  814. else if (angle_brackets)
  815. dir = pfile->bracket_include;
  816. else if (type == IT_CMDLINE)
  817. /* -include and -imacros use the #include "" chain with the
  818. preprocessor's cwd prepended. */
  819. return make_cpp_dir (pfile, "./", false);
  820. else if (pfile->quote_ignores_source_dir)
  821. dir = pfile->quote_include;
  822. else
  823. return make_cpp_dir (pfile, dir_name_of_file (file),
  824. pfile->buffer ? pfile->buffer->sysp : 0);
  825. if (dir == NULL)
  826. cpp_error (pfile, CPP_DL_ERROR,
  827. "no include path in which to search for %s", fname);
  828. return dir;
  829. }
  830. /* Strip the basename from the file's path. It ends with a slash if
  831. of nonzero length. Note that this procedure also works for
  832. <stdin>, which is represented by the empty string. */
  833. static const char *
  834. dir_name_of_file (_cpp_file *file)
  835. {
  836. if (!file->dir_name)
  837. {
  838. size_t len = lbasename (file->path) - file->path;
  839. char *dir_name = XNEWVEC (char, len + 1);
  840. memcpy (dir_name, file->path, len);
  841. dir_name[len] = '\0';
  842. file->dir_name = dir_name;
  843. }
  844. return file->dir_name;
  845. }
  846. /* Handles #include-family directives (distinguished by TYPE),
  847. including HEADER, and the command line -imacros and -include.
  848. Returns true if a buffer was stacked. */
  849. bool
  850. _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
  851. enum include_type type)
  852. {
  853. struct cpp_dir *dir;
  854. _cpp_file *file;
  855. bool stacked;
  856. /* For -include command-line flags we have type == IT_CMDLINE.
  857. When the first -include file is processed we have the case, where
  858. pfile->cur_token == pfile->cur_run->base, we are directly called up
  859. by the front end. However in the case of the second -include file,
  860. we are called from _cpp_lex_token -> _cpp_get_fresh_line ->
  861. cpp_push_include, with pfile->cur_token != pfile->cur_run->base,
  862. and pfile->cur_token[-1].src_loc not (yet) initialized.
  863. However, when the include file cannot be found, we need src_loc to
  864. be initialized to some safe value: 0 means UNKNOWN_LOCATION. */
  865. if (type == IT_CMDLINE && pfile->cur_token != pfile->cur_run->base)
  866. pfile->cur_token[-1].src_loc = 0;
  867. dir = search_path_head (pfile, fname, angle_brackets, type);
  868. if (!dir)
  869. return false;
  870. file = _cpp_find_file (pfile, fname, dir, false, angle_brackets,
  871. type == IT_DEFAULT);
  872. if (type == IT_DEFAULT && file == NULL)
  873. return false;
  874. /* Compensate for the increment in linemap_add that occurs if
  875. _cpp_stack_file actually stacks the file. In the case of a
  876. normal #include, we're currently at the start of the line
  877. *following* the #include. A separate source_location for this
  878. location makes no sense (until we do the LC_LEAVE), and
  879. complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we
  880. found a PCH file (in which case linemap_add is not called) or we
  881. were included from the command-line. */
  882. if (file->pchname == NULL && file->err_no == 0
  883. && type != IT_CMDLINE && type != IT_DEFAULT)
  884. pfile->line_table->highest_location--;
  885. stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT);
  886. if (!stacked)
  887. /* _cpp_stack_file didn't stack the file, so let's rollback the
  888. compensation dance we performed above. */
  889. pfile->line_table->highest_location++;
  890. return stacked;
  891. }
  892. /* Could not open FILE. The complication is dependency output. */
  893. static void
  894. open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets)
  895. {
  896. int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffer->sysp : 0;
  897. bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp);
  898. if (pfile->state.in__has_include__)
  899. return;
  900. errno = file->err_no;
  901. if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
  902. {
  903. deps_add_dep (pfile->deps, file->name);
  904. /* If the preprocessor output (other than dependency information) is
  905. being used, we must also flag an error. */
  906. if (CPP_OPTION (pfile, deps.need_preprocessor_output))
  907. cpp_errno (pfile, CPP_DL_FATAL, file->path);
  908. }
  909. else
  910. {
  911. /* If we are not outputting dependencies, or if we are and dependencies
  912. were requested for this file, or if preprocessor output is needed
  913. in addition to dependency information, this is an error.
  914. Otherwise (outputting dependencies but not for this file, and not
  915. using the preprocessor output), we can still produce correct output
  916. so it's only a warning. */
  917. if (CPP_OPTION (pfile, deps.style) == DEPS_NONE
  918. || print_dep
  919. || CPP_OPTION (pfile, deps.need_preprocessor_output))
  920. cpp_errno (pfile, CPP_DL_FATAL, file->path);
  921. else
  922. cpp_errno (pfile, CPP_DL_WARNING, file->path);
  923. }
  924. }
  925. /* Search in the chain beginning at HEAD for a file whose search path
  926. started at START_DIR != NULL. */
  927. static struct cpp_file_hash_entry *
  928. search_cache (struct cpp_file_hash_entry *head, const cpp_dir *start_dir)
  929. {
  930. while (head && head->start_dir != start_dir)
  931. head = head->next;
  932. return head;
  933. }
  934. /* Allocate a new _cpp_file structure. */
  935. static _cpp_file *
  936. make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname)
  937. {
  938. _cpp_file *file;
  939. file = XCNEW (_cpp_file);
  940. file->main_file = !pfile->buffer;
  941. file->fd = -1;
  942. file->dir = dir;
  943. file->name = xstrdup (fname);
  944. return file;
  945. }
  946. /* Release a _cpp_file structure. */
  947. static void
  948. destroy_cpp_file (_cpp_file *file)
  949. {
  950. free ((void *) file->buffer_start);
  951. free ((void *) file->name);
  952. free (file);
  953. }
  954. /* Release all the files allocated by this reader. */
  955. static void
  956. destroy_all_cpp_files (cpp_reader *pfile)
  957. {
  958. _cpp_file *iter = pfile->all_files;
  959. while (iter)
  960. {
  961. _cpp_file *next = iter->next_file;
  962. destroy_cpp_file (iter);
  963. iter = next;
  964. }
  965. }
  966. /* A hash of directory names. The directory names are the path names
  967. of files which contain a #include "", the included file name is
  968. appended to this directories.
  969. To avoid duplicate entries we follow the convention that all
  970. non-empty directory names should end in a '/'. DIR_NAME must be
  971. stored in permanently allocated memory. */
  972. static cpp_dir *
  973. make_cpp_dir (cpp_reader *pfile, const char *dir_name, int sysp)
  974. {
  975. struct cpp_file_hash_entry *entry, **hash_slot;
  976. cpp_dir *dir;
  977. hash_slot = (struct cpp_file_hash_entry **)
  978. htab_find_slot_with_hash (pfile->dir_hash, dir_name,
  979. htab_hash_string (dir_name),
  980. INSERT);
  981. /* Have we already hashed this directory? */
  982. for (entry = *hash_slot; entry; entry = entry->next)
  983. if (entry->start_dir == NULL)
  984. return entry->u.dir;
  985. dir = XCNEW (cpp_dir);
  986. dir->next = pfile->quote_include;
  987. dir->name = (char *) dir_name;
  988. dir->len = strlen (dir_name);
  989. dir->sysp = sysp;
  990. dir->construct = 0;
  991. /* Store this new result in the hash table. */
  992. entry = new_file_hash_entry (pfile);
  993. entry->next = *hash_slot;
  994. entry->start_dir = NULL;
  995. entry->location = pfile->line_table->highest_location;
  996. entry->u.dir = dir;
  997. *hash_slot = entry;
  998. return dir;
  999. }
  1000. /* Create a new block of memory for file hash entries. */
  1001. static void
  1002. allocate_file_hash_entries (cpp_reader *pfile)
  1003. {
  1004. struct file_hash_entry_pool *pool = XNEW (struct file_hash_entry_pool);
  1005. pool->file_hash_entries_used = 0;
  1006. pool->next = pfile->file_hash_entries;
  1007. pfile->file_hash_entries = pool;
  1008. }
  1009. /* Return a new file hash entry. */
  1010. static struct cpp_file_hash_entry *
  1011. new_file_hash_entry (cpp_reader *pfile)
  1012. {
  1013. unsigned int idx;
  1014. if (pfile->file_hash_entries->file_hash_entries_used == FILE_HASH_POOL_SIZE)
  1015. allocate_file_hash_entries (pfile);
  1016. idx = pfile->file_hash_entries->file_hash_entries_used++;
  1017. return &pfile->file_hash_entries->pool[idx];
  1018. }
  1019. /* Free the file hash entry pools. */
  1020. static void
  1021. free_file_hash_entries (cpp_reader *pfile)
  1022. {
  1023. struct file_hash_entry_pool *iter = pfile->file_hash_entries;
  1024. while (iter)
  1025. {
  1026. struct file_hash_entry_pool *next = iter->next;
  1027. free (iter);
  1028. iter = next;
  1029. }
  1030. }
  1031. /* Returns TRUE if a file FNAME has ever been successfully opened.
  1032. This routine is not intended to correctly handle filenames aliased
  1033. by links or redundant . or .. traversals etc. */
  1034. bool
  1035. cpp_included (cpp_reader *pfile, const char *fname)
  1036. {
  1037. struct cpp_file_hash_entry *entry;
  1038. entry = (struct cpp_file_hash_entry *)
  1039. htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
  1040. while (entry && (entry->start_dir == NULL || entry->u.file->err_no))
  1041. entry = entry->next;
  1042. return entry != NULL;
  1043. }
  1044. /* Returns TRUE if a file FNAME has ever been successfully opened
  1045. before LOCATION. This routine is not intended to correctly handle
  1046. filenames aliased by links or redundant . or .. traversals etc. */
  1047. bool
  1048. cpp_included_before (cpp_reader *pfile, const char *fname,
  1049. source_location location)
  1050. {
  1051. struct cpp_file_hash_entry *entry;
  1052. entry = (struct cpp_file_hash_entry *)
  1053. htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
  1054. while (entry && (entry->start_dir == NULL || entry->u.file->err_no
  1055. || entry->location > location))
  1056. entry = entry->next;
  1057. return entry != NULL;
  1058. }
  1059. /* Calculate the hash value of a file hash entry P. */
  1060. static hashval_t
  1061. file_hash_hash (const void *p)
  1062. {
  1063. struct cpp_file_hash_entry *entry = (struct cpp_file_hash_entry *) p;
  1064. const char *hname;
  1065. if (entry->start_dir)
  1066. hname = entry->u.file->name;
  1067. else
  1068. hname = entry->u.dir->name;
  1069. return htab_hash_string (hname);
  1070. }
  1071. /* Compare a string Q against a file hash entry P. */
  1072. static int
  1073. file_hash_eq (const void *p, const void *q)
  1074. {
  1075. struct cpp_file_hash_entry *entry = (struct cpp_file_hash_entry *) p;
  1076. const char *fname = (const char *) q;
  1077. const char *hname;
  1078. if (entry->start_dir)
  1079. hname = entry->u.file->name;
  1080. else
  1081. hname = entry->u.dir->name;
  1082. return filename_cmp (hname, fname) == 0;
  1083. }
  1084. /* Compare entries in the nonexistent file hash table. These are just
  1085. strings. */
  1086. static int
  1087. nonexistent_file_hash_eq (const void *p, const void *q)
  1088. {
  1089. return filename_cmp ((const char *) p, (const char *) q) == 0;
  1090. }
  1091. /* Initialize everything in this source file. */
  1092. void
  1093. _cpp_init_files (cpp_reader *pfile)
  1094. {
  1095. pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
  1096. NULL, xcalloc, free);
  1097. pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
  1098. NULL, xcalloc, free);
  1099. allocate_file_hash_entries (pfile);
  1100. pfile->nonexistent_file_hash = htab_create_alloc (127, htab_hash_string,
  1101. nonexistent_file_hash_eq,
  1102. NULL, xcalloc, free);
  1103. obstack_specify_allocation (&pfile->nonexistent_file_ob, 0, 0,
  1104. xmalloc, free);
  1105. }
  1106. /* Finalize everything in this source file. */
  1107. void
  1108. _cpp_cleanup_files (cpp_reader *pfile)
  1109. {
  1110. htab_delete (pfile->file_hash);
  1111. htab_delete (pfile->dir_hash);
  1112. htab_delete (pfile->nonexistent_file_hash);
  1113. obstack_free (&pfile->nonexistent_file_ob, 0);
  1114. free_file_hash_entries (pfile);
  1115. destroy_all_cpp_files (pfile);
  1116. }
  1117. /* Make the parser forget about files it has seen. This can be useful
  1118. for resetting the parser to start another run. */
  1119. void
  1120. cpp_clear_file_cache (cpp_reader *pfile)
  1121. {
  1122. _cpp_cleanup_files (pfile);
  1123. pfile->file_hash_entries = NULL;
  1124. pfile->all_files = NULL;
  1125. _cpp_init_files (pfile);
  1126. }
  1127. /* Enter a file name in the hash for the sake of cpp_included. */
  1128. void
  1129. _cpp_fake_include (cpp_reader *pfile, const char *fname)
  1130. {
  1131. _cpp_find_file (pfile, fname, pfile->buffer->file->dir, true, 0, false);
  1132. }
  1133. /* Not everyone who wants to set system-header-ness on a buffer can
  1134. see the details of a buffer. This is an exported interface because
  1135. fix-header needs it. */
  1136. void
  1137. cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
  1138. {
  1139. int flags = 0;
  1140. const struct line_maps *line_table = pfile->line_table;
  1141. const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
  1142. /* 1 = system header, 2 = system header to be treated as C. */
  1143. if (syshdr)
  1144. flags = 1 + (externc != 0);
  1145. pfile->buffer->sysp = flags;
  1146. _cpp_do_file_change (pfile, LC_RENAME, ORDINARY_MAP_FILE_NAME (map),
  1147. SOURCE_LINE (map, pfile->line_table->highest_line), flags);
  1148. }
  1149. /* Allow the client to change the current file. Used by the front end
  1150. to achieve pseudo-file names like <built-in>.
  1151. If REASON is LC_LEAVE, then NEW_NAME must be NULL. */
  1152. void
  1153. cpp_change_file (cpp_reader *pfile, enum lc_reason reason,
  1154. const char *new_name)
  1155. {
  1156. _cpp_do_file_change (pfile, reason, new_name, 1, 0);
  1157. }
  1158. struct report_missing_guard_data
  1159. {
  1160. const char **paths;
  1161. size_t count;
  1162. };
  1163. /* Callback function for htab_traverse. */
  1164. static int
  1165. report_missing_guard (void **slot, void *d)
  1166. {
  1167. struct cpp_file_hash_entry *entry = (struct cpp_file_hash_entry *) *slot;
  1168. struct report_missing_guard_data *data
  1169. = (struct report_missing_guard_data *) d;
  1170. /* Skip directories. */
  1171. if (entry->start_dir != NULL)
  1172. {
  1173. _cpp_file *file = entry->u.file;
  1174. /* We don't want MI guard advice for the main file. */
  1175. if (!file->once_only && file->cmacro == NULL
  1176. && file->stack_count == 1 && !file->main_file)
  1177. {
  1178. if (data->paths == NULL)
  1179. {
  1180. data->paths = XCNEWVEC (const char *, data->count);
  1181. data->count = 0;
  1182. }
  1183. data->paths[data->count++] = file->path;
  1184. }
  1185. }
  1186. /* Keep traversing the hash table. */
  1187. return 1;
  1188. }
  1189. /* Comparison function for qsort. */
  1190. static int
  1191. report_missing_guard_cmp (const void *p1, const void *p2)
  1192. {
  1193. return strcmp (*(const char *const *) p1, *(const char *const *) p2);
  1194. }
  1195. /* Report on all files that might benefit from a multiple include guard.
  1196. Triggered by -H. */
  1197. void
  1198. _cpp_report_missing_guards (cpp_reader *pfile)
  1199. {
  1200. struct report_missing_guard_data data;
  1201. data.paths = NULL;
  1202. data.count = htab_elements (pfile->file_hash);
  1203. htab_traverse (pfile->file_hash, report_missing_guard, &data);
  1204. if (data.paths != NULL)
  1205. {
  1206. size_t i;
  1207. /* Sort the paths to avoid outputting them in hash table
  1208. order. */
  1209. qsort (data.paths, data.count, sizeof (const char *),
  1210. report_missing_guard_cmp);
  1211. fputs (_("Multiple include guards may be useful for:\n"),
  1212. stderr);
  1213. for (i = 0; i < data.count; i++)
  1214. {
  1215. fputs (data.paths[i], stderr);
  1216. putc ('\n', stderr);
  1217. }
  1218. free (data.paths);
  1219. }
  1220. }
  1221. /* Locate HEADER, and determine whether it is newer than the current
  1222. file. If it cannot be located or dated, return -1, if it is
  1223. newer, return 1, otherwise 0. */
  1224. int
  1225. _cpp_compare_file_date (cpp_reader *pfile, const char *fname,
  1226. int angle_brackets)
  1227. {
  1228. _cpp_file *file;
  1229. struct cpp_dir *dir;
  1230. dir = search_path_head (pfile, fname, angle_brackets, IT_INCLUDE);
  1231. if (!dir)
  1232. return -1;
  1233. file = _cpp_find_file (pfile, fname, dir, false, angle_brackets, false);
  1234. if (file->err_no)
  1235. return -1;
  1236. if (file->fd != -1)
  1237. {
  1238. close (file->fd);
  1239. file->fd = -1;
  1240. }
  1241. return file->st.st_mtime > pfile->buffer->file->st.st_mtime;
  1242. }
  1243. /* Pushes the given file onto the buffer stack. Returns nonzero if
  1244. successful. */
  1245. bool
  1246. cpp_push_include (cpp_reader *pfile, const char *fname)
  1247. {
  1248. return _cpp_stack_include (pfile, fname, false, IT_CMDLINE);
  1249. }
  1250. /* Pushes the given file, implicitly included at the start of a
  1251. compilation, onto the buffer stack but without any errors if the
  1252. file is not found. Returns nonzero if successful. */
  1253. bool
  1254. cpp_push_default_include (cpp_reader *pfile, const char *fname)
  1255. {
  1256. return _cpp_stack_include (pfile, fname, true, IT_DEFAULT);
  1257. }
  1258. /* Do appropriate cleanup when a file INC's buffer is popped off the
  1259. input stack. */
  1260. void
  1261. _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file,
  1262. const unsigned char *to_free)
  1263. {
  1264. /* Record the inclusion-preventing macro, which could be NULL
  1265. meaning no controlling macro. */
  1266. if (pfile->mi_valid && file->cmacro == NULL)
  1267. file->cmacro = pfile->mi_cmacro;
  1268. /* Invalidate control macros in the #including file. */
  1269. pfile->mi_valid = false;
  1270. if (to_free)
  1271. {
  1272. if (to_free == file->buffer_start)
  1273. {
  1274. file->buffer_start = NULL;
  1275. file->buffer = NULL;
  1276. file->buffer_valid = false;
  1277. }
  1278. free ((void *) to_free);
  1279. }
  1280. }
  1281. /* Return the file name associated with FILE. */
  1282. const char *
  1283. _cpp_get_file_name (_cpp_file *file)
  1284. {
  1285. return file->name;
  1286. }
  1287. /* Inteface to file statistics record in _cpp_file structure. */
  1288. struct stat *
  1289. _cpp_get_file_stat (_cpp_file *file)
  1290. {
  1291. return &file->st;
  1292. }
  1293. /* Set the include chain for "" to QUOTE, for <> to BRACKET. If
  1294. QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
  1295. directory of the including file.
  1296. If BRACKET does not lie in the QUOTE chain, it is set to QUOTE. */
  1297. void
  1298. cpp_set_include_chains (cpp_reader *pfile, cpp_dir *quote, cpp_dir *bracket,
  1299. int quote_ignores_source_dir)
  1300. {
  1301. pfile->quote_include = quote;
  1302. pfile->bracket_include = quote;
  1303. pfile->quote_ignores_source_dir = quote_ignores_source_dir;
  1304. for (; quote; quote = quote->next)
  1305. {
  1306. quote->name_map = NULL;
  1307. quote->len = strlen (quote->name);
  1308. if (quote == bracket)
  1309. pfile->bracket_include = bracket;
  1310. }
  1311. }
  1312. /* Append the file name to the directory to create the path, but don't
  1313. turn / into // or // into ///; // may be a namespace escape. */
  1314. static char *
  1315. append_file_to_dir (const char *fname, cpp_dir *dir)
  1316. {
  1317. size_t dlen, flen;
  1318. char *path;
  1319. dlen = dir->len;
  1320. flen = strlen (fname);
  1321. path = XNEWVEC (char, dlen + 1 + flen + 1);
  1322. memcpy (path, dir->name, dlen);
  1323. if (dlen && !IS_DIR_SEPARATOR (path[dlen - 1]))
  1324. path[dlen++] = '/';
  1325. memcpy (&path[dlen], fname, flen + 1);
  1326. return path;
  1327. }
  1328. /* Read a space delimited string of unlimited length from a stdio
  1329. file F. */
  1330. static char *
  1331. read_filename_string (int ch, FILE *f)
  1332. {
  1333. char *alloc, *set;
  1334. int len;
  1335. len = 20;
  1336. set = alloc = XNEWVEC (char, len + 1);
  1337. if (! is_space (ch))
  1338. {
  1339. *set++ = ch;
  1340. while ((ch = getc (f)) != EOF && ! is_space (ch))
  1341. {
  1342. if (set - alloc == len)
  1343. {
  1344. len *= 2;
  1345. alloc = XRESIZEVEC (char, alloc, len + 1);
  1346. set = alloc + len / 2;
  1347. }
  1348. *set++ = ch;
  1349. }
  1350. }
  1351. *set = '\0';
  1352. ungetc (ch, f);
  1353. return alloc;
  1354. }
  1355. /* Read the file name map file for DIR. */
  1356. static void
  1357. read_name_map (cpp_dir *dir)
  1358. {
  1359. static const char FILE_NAME_MAP_FILE[] = "header.gcc";
  1360. char *name;
  1361. FILE *f;
  1362. size_t len, count = 0, room = 9;
  1363. len = dir->len;
  1364. name = (char *) alloca (len + sizeof (FILE_NAME_MAP_FILE) + 1);
  1365. memcpy (name, dir->name, len);
  1366. if (len && !IS_DIR_SEPARATOR (name[len - 1]))
  1367. name[len++] = '/';
  1368. strcpy (name + len, FILE_NAME_MAP_FILE);
  1369. f = fopen (name, "r");
  1370. dir->name_map = XNEWVEC (const char *, room);
  1371. /* Silently return NULL if we cannot open. */
  1372. if (f)
  1373. {
  1374. int ch;
  1375. while ((ch = getc (f)) != EOF)
  1376. {
  1377. char *to;
  1378. if (is_space (ch))
  1379. continue;
  1380. if (count + 2 > room)
  1381. {
  1382. room += 8;
  1383. dir->name_map = XRESIZEVEC (const char *, dir->name_map, room);
  1384. }
  1385. dir->name_map[count] = read_filename_string (ch, f);
  1386. while ((ch = getc (f)) != EOF && is_hspace (ch))
  1387. ;
  1388. to = read_filename_string (ch, f);
  1389. if (IS_ABSOLUTE_PATH (to))
  1390. dir->name_map[count + 1] = to;
  1391. else
  1392. {
  1393. dir->name_map[count + 1] = append_file_to_dir (to, dir);
  1394. free (to);
  1395. }
  1396. count += 2;
  1397. while ((ch = getc (f)) != '\n')
  1398. if (ch == EOF)
  1399. break;
  1400. }
  1401. fclose (f);
  1402. }
  1403. /* Terminate the list of maps. */
  1404. dir->name_map[count] = NULL;
  1405. }
  1406. /* Remap a FILE's name based on the file_name_map, if any, for
  1407. FILE->dir. If the file name has any directory separators,
  1408. recursively check those directories too. */
  1409. static char *
  1410. remap_filename (cpp_reader *pfile, _cpp_file *file)
  1411. {
  1412. const char *fname, *p;
  1413. char *new_dir;
  1414. cpp_dir *dir;
  1415. size_t index, len;
  1416. dir = file->dir;
  1417. fname = file->name;
  1418. for (;;)
  1419. {
  1420. if (!dir->name_map)
  1421. read_name_map (dir);
  1422. for (index = 0; dir->name_map[index]; index += 2)
  1423. if (!filename_cmp (dir->name_map[index], fname))
  1424. return xstrdup (dir->name_map[index + 1]);
  1425. if (IS_ABSOLUTE_PATH (fname))
  1426. return NULL;
  1427. p = strchr (fname, '/');
  1428. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  1429. {
  1430. char *p2 = strchr (fname, '\\');
  1431. if (!p || (p > p2))
  1432. p = p2;
  1433. }
  1434. #endif
  1435. if (!p || p == fname)
  1436. return NULL;
  1437. len = dir->len + (p - fname + 1);
  1438. new_dir = XNEWVEC (char, len + 1);
  1439. memcpy (new_dir, dir->name, dir->len);
  1440. memcpy (new_dir + dir->len, fname, p - fname + 1);
  1441. new_dir[len] = '\0';
  1442. dir = make_cpp_dir (pfile, new_dir, dir->sysp);
  1443. fname = p + 1;
  1444. }
  1445. }
  1446. /* Returns true if PCHNAME is a valid PCH file for FILE. */
  1447. static bool
  1448. validate_pch (cpp_reader *pfile, _cpp_file *file, const char *pchname)
  1449. {
  1450. const char *saved_path = file->path;
  1451. bool valid = false;
  1452. file->path = pchname;
  1453. if (open_file (file))
  1454. {
  1455. valid = 1 & pfile->cb.valid_pch (pfile, pchname, file->fd);
  1456. if (!valid)
  1457. {
  1458. close (file->fd);
  1459. file->fd = -1;
  1460. }
  1461. if (CPP_OPTION (pfile, print_include_names))
  1462. {
  1463. unsigned int i;
  1464. for (i = 1; i < pfile->line_table->depth; i++)
  1465. putc ('.', stderr);
  1466. fprintf (stderr, "%c %s\n",
  1467. valid ? '!' : 'x', pchname);
  1468. }
  1469. }
  1470. file->path = saved_path;
  1471. return valid;
  1472. }
  1473. /* Get the path associated with the _cpp_file F. The path includes
  1474. the base name from the include directive and the directory it was
  1475. found in via the search path. */
  1476. const char *
  1477. cpp_get_path (struct _cpp_file *f)
  1478. {
  1479. return f->path;
  1480. }
  1481. /* Get the directory associated with the _cpp_file F. */
  1482. cpp_dir *
  1483. cpp_get_dir (struct _cpp_file *f)
  1484. {
  1485. return f->dir;
  1486. }
  1487. /* Get the cpp_buffer currently associated with the cpp_reader
  1488. PFILE. */
  1489. cpp_buffer *
  1490. cpp_get_buffer (cpp_reader *pfile)
  1491. {
  1492. return pfile->buffer;
  1493. }
  1494. /* Get the _cpp_file associated with the cpp_buffer B. */
  1495. _cpp_file *
  1496. cpp_get_file (cpp_buffer *b)
  1497. {
  1498. return b->file;
  1499. }
  1500. /* Get the previous cpp_buffer given a cpp_buffer B. The previous
  1501. buffer is the buffer that included the given buffer. */
  1502. cpp_buffer *
  1503. cpp_get_prev (cpp_buffer *b)
  1504. {
  1505. return b->prev;
  1506. }
  1507. /* This data structure holds the list of header files that were seen
  1508. while the PCH was being built. The 'entries' field is kept sorted
  1509. in memcmp() order; yes, this means that on little-endian systems,
  1510. it's sorted initially by the least-significant byte of 'size', but
  1511. that's OK. The code does rely on having entries with the same size
  1512. next to each other. */
  1513. struct pchf_entry {
  1514. /* The size of this file. This is used to save running a MD5 checksum
  1515. if the sizes don't match. */
  1516. off_t size;
  1517. /* The MD5 checksum of this file. */
  1518. unsigned char sum[16];
  1519. /* Is this file to be included only once? */
  1520. bool once_only;
  1521. };
  1522. struct pchf_data {
  1523. /* Number of pchf_entry structures. */
  1524. size_t count;
  1525. /* Are there any values with once_only set?
  1526. This is used as an optimisation, it means we don't have to search
  1527. the structure if we're processing a regular #include. */
  1528. bool have_once_only;
  1529. struct pchf_entry entries[1];
  1530. };
  1531. static struct pchf_data *pchf;
  1532. /* A qsort ordering function for pchf_entry structures. */
  1533. static int
  1534. pchf_save_compare (const void *e1, const void *e2)
  1535. {
  1536. return memcmp (e1, e2, sizeof (struct pchf_entry));
  1537. }
  1538. /* Create and write to F a pchf_data structure. */
  1539. bool
  1540. _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
  1541. {
  1542. size_t count = 0;
  1543. struct pchf_data *result;
  1544. size_t result_size;
  1545. _cpp_file *f;
  1546. bool ret;
  1547. for (f = pfile->all_files; f; f = f->next_file)
  1548. ++count;
  1549. result_size = (sizeof (struct pchf_data)
  1550. + sizeof (struct pchf_entry) * (count - 1));
  1551. result = XCNEWVAR (struct pchf_data, result_size);
  1552. result->count = 0;
  1553. result->have_once_only = false;
  1554. for (f = pfile->all_files; f; f = f->next_file)
  1555. {
  1556. size_t count;
  1557. /* This should probably never happen, since if a read error occurred
  1558. the PCH file shouldn't be written... */
  1559. if (f->dont_read || f->err_no)
  1560. continue;
  1561. if (f->stack_count == 0)
  1562. continue;
  1563. count = result->count++;
  1564. result->entries[count].once_only = f->once_only;
  1565. /* |= is avoided in the next line because of an HP C compiler bug */
  1566. result->have_once_only = result->have_once_only | f->once_only;
  1567. if (f->buffer_valid)
  1568. md5_buffer ((const char *)f->buffer,
  1569. f->st.st_size, result->entries[count].sum);
  1570. else
  1571. {
  1572. FILE *ff;
  1573. int oldfd = f->fd;
  1574. if (!open_file (f))
  1575. {
  1576. open_file_failed (pfile, f, 0);
  1577. free (result);
  1578. return false;
  1579. }
  1580. ff = fdopen (f->fd, "rb");
  1581. md5_stream (ff, result->entries[count].sum);
  1582. fclose (ff);
  1583. f->fd = oldfd;
  1584. }
  1585. result->entries[count].size = f->st.st_size;
  1586. }
  1587. result_size = (sizeof (struct pchf_data)
  1588. + sizeof (struct pchf_entry) * (result->count - 1));
  1589. qsort (result->entries, result->count, sizeof (struct pchf_entry),
  1590. pchf_save_compare);
  1591. ret = fwrite (result, result_size, 1, fp) == 1;
  1592. free (result);
  1593. return ret;
  1594. }
  1595. /* Read the pchf_data structure from F. */
  1596. bool
  1597. _cpp_read_file_entries (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f)
  1598. {
  1599. struct pchf_data d;
  1600. if (fread (&d, sizeof (struct pchf_data) - sizeof (struct pchf_entry), 1, f)
  1601. != 1)
  1602. return false;
  1603. pchf = XNEWVAR (struct pchf_data, sizeof (struct pchf_data)
  1604. + sizeof (struct pchf_entry) * (d.count - 1));
  1605. memcpy (pchf, &d, sizeof (struct pchf_data) - sizeof (struct pchf_entry));
  1606. if (fread (pchf->entries, sizeof (struct pchf_entry), d.count, f)
  1607. != d.count)
  1608. return false;
  1609. return true;
  1610. }
  1611. /* The parameters for pchf_compare. */
  1612. struct pchf_compare_data
  1613. {
  1614. /* The size of the file we're looking for. */
  1615. off_t size;
  1616. /* The MD5 checksum of the file, if it's been computed. */
  1617. unsigned char sum[16];
  1618. /* Is SUM valid? */
  1619. bool sum_computed;
  1620. /* Do we need to worry about entries that don't have ONCE_ONLY set? */
  1621. bool check_included;
  1622. /* The file that we're searching for. */
  1623. _cpp_file *f;
  1624. };
  1625. /* bsearch comparison function; look for D_P in E_P. */
  1626. static int
  1627. pchf_compare (const void *d_p, const void *e_p)
  1628. {
  1629. const struct pchf_entry *e = (const struct pchf_entry *)e_p;
  1630. struct pchf_compare_data *d = (struct pchf_compare_data *)d_p;
  1631. int result;
  1632. result = memcmp (&d->size, &e->size, sizeof (off_t));
  1633. if (result != 0)
  1634. return result;
  1635. if (! d->sum_computed)
  1636. {
  1637. _cpp_file *const f = d->f;
  1638. md5_buffer ((const char *)f->buffer, f->st.st_size, d->sum);
  1639. d->sum_computed = true;
  1640. }
  1641. result = memcmp (d->sum, e->sum, 16);
  1642. if (result != 0)
  1643. return result;
  1644. if (d->check_included || e->once_only)
  1645. return 0;
  1646. else
  1647. return 1;
  1648. }
  1649. /* Check that F is not in a list read from a PCH file (if any).
  1650. Assumes that f->buffer_valid is true. Return TRUE if the file
  1651. should not be read. */
  1652. static bool
  1653. check_file_against_entries (cpp_reader *pfile ATTRIBUTE_UNUSED,
  1654. _cpp_file *f,
  1655. bool check_included)
  1656. {
  1657. struct pchf_compare_data d;
  1658. if (pchf == NULL
  1659. || (! check_included && ! pchf->have_once_only))
  1660. return false;
  1661. d.size = f->st.st_size;
  1662. d.sum_computed = false;
  1663. d.f = f;
  1664. d.check_included = check_included;
  1665. return bsearch (&d, pchf->entries, pchf->count, sizeof (struct pchf_entry),
  1666. pchf_compare) != NULL;
  1667. }
  1668. /* Return true if the file FNAME is found in the appropriate include file path
  1669. as indicated by ANGLE_BRACKETS. */
  1670. bool
  1671. _cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets,
  1672. enum include_type type)
  1673. {
  1674. cpp_dir *start_dir = search_path_head (pfile, fname, angle_brackets, type);
  1675. _cpp_file *file = _cpp_find_file (pfile, fname, start_dir,
  1676. /*fake=*/false, angle_brackets,
  1677. /*implicit_preinclude=*/false);
  1678. return file->err_no != ENOENT;
  1679. }