- if (file[1] == '/' && PATH_MAX > snprintf(path, PATH_MAX, "%.*s", f_len, file + 1)) {
- return try_include(cpp, path, &parsed) && parsed;
- } else {
+ if (!path) {
+ path = temp;
+ }
+
+ if (file->type == PSI_T_QUOTED_STRING && (!(flags & PSI_CPP_INCLUDE_NEXT) || file->text->val[0] == '/')) {
+ /* first try as is, full or relative path */
+ if (file->text->val[0] == '/') {
+ path = file->text->val;
+ } else {
+ char *dir;
+ size_t len;
+
+ strncpy(path, file->file->val, PATH_MAX);
+
+ dir = dirname(path);
+ len = strlen(dir);
+
+ assert(len + file->text->len + 1 < PATH_MAX);
+
+ memmove(path, dir, len);
+ path[len] = '/';
+ memcpy(&(path)[len + 1], file->text->val, file->text->len + 1);
+ }
+
+ PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP %s trying %s\n",
+ include_flavor[flags], path);
+ if (0 == eaccess(path, R_OK)) {
+ return true;
+ }
+ }
+
+ /* look through search paths */
+ if (file->text->val[0] != '/') {