/
| 1547 | |
| 1548 | /*****************************************************************************/ |
| 1549 | static char *path_append (char *buf, const char *app, size_t *buf_size) { |
| 1550 | /****************************************************************************** |
| 1551 | Helper for proj_info() below. Append app to buf, separated by a |
| 1552 | semicolon. Also handle allocation of longer buffer if needed. |
| 1553 | |
| 1554 | Returns buffer and adjusts *buf_size through provided pointer arg. |
| 1555 | ******************************************************************************/ |
| 1556 | char *p; |
| 1557 | size_t len, applen = 0, buflen = 0; |
| 1558 | #ifdef _WIN32 |
| 1559 | const char *delim = ";"; |
| 1560 | #else |
| 1561 | const char *delim = ":"; |
| 1562 | #endif |
| 1563 | |
| 1564 | /* Nothing to do? */ |
| 1565 | if (nullptr == app) |
| 1566 | return buf; |
| 1567 | applen = strlen (app); |
| 1568 | if (0 == applen) |
| 1569 | return buf; |
| 1570 | |
| 1571 | /* Start checking whether buf is long enough */ |
| 1572 | if (nullptr != buf) |
| 1573 | buflen = strlen (buf); |
| 1574 | len = buflen+applen+strlen (delim) + 1; |
| 1575 | |
| 1576 | /* "pj_realloc", so to speak */ |
| 1577 | if (*buf_size < len) { |
| 1578 | p = static_cast<char*>(calloc (2 * len, sizeof (char))); |
| 1579 | if (nullptr==p) { |
| 1580 | free (buf); |
| 1581 | return nullptr; |
| 1582 | } |
| 1583 | *buf_size = 2 * len; |
| 1584 | if (buf != nullptr) |
| 1585 | strcpy (p, buf); |
| 1586 | free (buf); |
| 1587 | buf = p; |
| 1588 | } |
| 1589 | assert(buf); |
| 1590 | |
| 1591 | /* Only append a delimiter if something's already there */ |
| 1592 | if (0 != buflen) |
| 1593 | strcat (buf, delim); |
| 1594 | strcat (buf, app); |
| 1595 | return buf; |
| 1596 | } |
| 1597 | |
| 1598 | static const char *empty = {""}; |
| 1599 | static char version[64] = {""}; |