| 169 | } |
| 170 | |
| 171 | txString fxRealFilePath(txParser* parser, txString path) |
| 172 | { |
| 173 | #if mxWindows |
| 174 | char buffer[C_PATH_MAX]; |
| 175 | DWORD attributes; |
| 176 | if (_fullpath(buffer, path, C_PATH_MAX) != NULL) { |
| 177 | attributes = GetFileAttributes(buffer); |
| 178 | if ((attributes != 0xFFFFFFFF) && (!(attributes & FILE_ATTRIBUTE_DIRECTORY))) { |
| 179 | return fxNewParserString(parser, buffer, mxStringLength(buffer)); |
| 180 | } |
| 181 | } |
| 182 | #else |
| 183 | char buffer[C_PATH_MAX]; |
| 184 | struct stat a_stat; |
| 185 | if (realpath(path, buffer) != NULL) { |
| 186 | if (stat(buffer, &a_stat) == 0) { |
| 187 | if (S_ISREG(a_stat.st_mode)) { |
| 188 | return fxNewParserString(parser, buffer, mxStringLength(buffer)); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | #endif |
| 193 | parser->error = C_EINVAL; |
| 194 | fprintf(stderr, "# file not found: %s!\n", path); |
| 195 | c_longjmp(parser->firstJump->jmp_buf, 1); |
| 196 | } |
| 197 | |
| 198 | txString fxRealFilePathIf(txParser* parser, txString path) |
| 199 | { |
no test coverage detected