comparison files.c @ 104:91f600e6647b

Allow absolute paths in include files.
author David A. Holland
date Tue, 11 Jun 2013 11:13:58 -0400
parents 60184aa42604
children 33954a07d013
comparison
equal deleted inserted replaced
103:343af355df1b 104:91f600e6647b
338 char *file; 338 char *file;
339 int fd; 339 int fd;
340 340
341 assert(place != NULL); 341 assert(place != NULL);
342 342
343 num = incdirarray_num(path); 343 if (name[0] == '/') {
344 for (i=0; i<num; i++) { 344 fd = file_tryopen(name);
345 id = incdirarray_get(path, i);
346 file = mkfilename(id->name, name);
347 fd = file_tryopen(file);
348 if (fd >= 0) { 345 if (fd >= 0) {
349 pf = place_addfile(place, file, id->issystem); 346 pf = place_addfile(place, name, true);
350 file_read(pf, fd, file, false); 347 file_read(pf, fd, name, false);
351 dostrfree(file);
352 close(fd); 348 close(fd);
353 return; 349 return;
354 } 350 }
355 dostrfree(file); 351 } else {
352 num = incdirarray_num(path);
353 for (i=0; i<num; i++) {
354 id = incdirarray_get(path, i);
355 file = mkfilename(id->name, name);
356 fd = file_tryopen(file);
357 if (fd >= 0) {
358 pf = place_addfile(place, file, id->issystem);
359 file_read(pf, fd, file, false);
360 dostrfree(file);
361 close(fd);
362 return;
363 }
364 dostrfree(file);
365 }
356 } 366 }
357 complain(place, "Include file %s not found", name); 367 complain(place, "Include file %s not found", name);
358 complain_fail(); 368 complain_fail();
359 } 369 }
360 370