MCPcopy Create free account
hub / github.com/OSGeo/PROJ / path_append

Function path_append

src/info.cpp:37–84  ·  view source on GitHub ↗

/

Source from the content-addressed store, hash-verified

35
36/*****************************************************************************/
37static char *path_append(char *buf, const char *app, size_t *buf_size) {
38 /******************************************************************************
39 Helper for proj_info() below. Append app to buf, separated by a
40 semicolon. Also handle allocation of longer buffer if needed.
41
42 Returns buffer and adjusts *buf_size through provided pointer arg.
43 ******************************************************************************/
44 char *p;
45 size_t len, applen = 0, buflen = 0;
46#ifdef _WIN32
47 const char *delim = ";";
48#else
49 const char *delim = ":";
50#endif
51
52 /* Nothing to do? */
53 if (nullptr == app)
54 return buf;
55 applen = strlen(app);
56 if (0 == applen)
57 return buf;
58
59 /* Start checking whether buf is long enough */
60 if (nullptr != buf)
61 buflen = strlen(buf);
62 len = buflen + applen + strlen(delim) + 1;
63
64 /* "pj_realloc", so to speak */
65 if (*buf_size < len) {
66 p = static_cast<char *>(calloc(2 * len, sizeof(char)));
67 if (nullptr == p) {
68 free(buf);
69 return nullptr;
70 }
71 *buf_size = 2 * len;
72 if (buf != nullptr)
73 strcpy(p, buf);
74 free(buf);
75 buf = p;
76 }
77 assert(buf);
78
79 /* Only append a delimiter if something's already there */
80 if (0 != buflen)
81 strcat(buf, delim);
82 strcat(buf, app);
83 return buf;
84}
85
86static const char *empty = {""};
87static char version[64] = {""};

Callers 1

proj_infoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected