| 1542 | } |
| 1543 | |
| 1544 | static void *pj_open_lib_internal( |
| 1545 | PJ_CONTEXT *ctx, const char *name, const char *mode, |
| 1546 | void *(*open_file)(PJ_CONTEXT *, const char *, const char *), |
| 1547 | char *out_full_filename, size_t out_full_filename_size) { |
| 1548 | try { |
| 1549 | std::string fname; |
| 1550 | void *fid = nullptr; |
| 1551 | const char *tmpname = nullptr; |
| 1552 | std::string projLib; |
| 1553 | |
| 1554 | if (ctx == nullptr) { |
| 1555 | ctx = pj_get_default_ctx(); |
| 1556 | } |
| 1557 | |
| 1558 | if (out_full_filename != nullptr && out_full_filename_size > 0) |
| 1559 | out_full_filename[0] = '\0'; |
| 1560 | |
| 1561 | auto open_lib_from_paths = [&ctx, open_file, &name, &fname, |
| 1562 | &mode](const std::string &projLibPaths) { |
| 1563 | void *lib_fid = nullptr; |
| 1564 | auto paths = NS_PROJ::internal::split(projLibPaths, dirSeparator); |
| 1565 | for (const auto &path : paths) { |
| 1566 | fname = NS_PROJ::internal::stripQuotes(path); |
| 1567 | fname += DIR_CHAR; |
| 1568 | fname += name; |
| 1569 | lib_fid = open_file(ctx, fname.c_str(), mode); |
| 1570 | if (lib_fid) |
| 1571 | break; |
| 1572 | } |
| 1573 | return lib_fid; |
| 1574 | }; |
| 1575 | |
| 1576 | /* check if ~/name */ |
| 1577 | if (is_tilde_slash(name)) |
| 1578 | if (const char *home = getenv("HOME")) { |
| 1579 | fname = home; |
| 1580 | fname += DIR_CHAR; |
| 1581 | fname += name; |
| 1582 | } else |
| 1583 | return nullptr; |
| 1584 | |
| 1585 | /* or fixed path: /name, ./name or ../name */ |
| 1586 | else if (is_rel_or_absolute_filename(name)) { |
| 1587 | fname = name; |
| 1588 | #ifdef _WIN32 |
| 1589 | try { |
| 1590 | NS_PROJ::UTF8ToWString(name); |
| 1591 | } catch (const std::exception &) { |
| 1592 | fname = NS_PROJ::Win32Recode(name, CP_ACP, CP_UTF8); |
| 1593 | } |
| 1594 | #endif |
| 1595 | } |
| 1596 | |
| 1597 | else if (starts_with(name, "http://") || starts_with(name, "https://")) |
| 1598 | fname = name; |
| 1599 | |
| 1600 | /* or try to use application provided file finder */ |
| 1601 | else if (ctx->file_finder != nullptr && |
no test coverage detected