MCPcopy Create free account
hub / github.com/apache/trafficserver / path_join

Function path_join

include/tscore/ink_memory.h:587–609  ·  view source on GitHub ↗

Combine two strings as file paths. Trailing and leading separators for @a lhs and @a rhs respectively are handled to yield exactly one separator. @return A newly @x ats_malloc string of the combined paths. */

Source from the content-addressed store, hash-verified

585 @return A newly @x ats_malloc string of the combined paths.
586*/
587inline char *
588path_join(ats_scoped_str const &lhs, ats_scoped_str const &rhs)
589{
590 size_t ln = strlen(lhs);
591 size_t rn = strlen(rhs);
592 const char *rptr = rhs; // May need to be modified.
593
594 if (ln && lhs[ln - 1] == '/') {
595 --ln; // drop trailing separator.
596 }
597 if (rn && *rptr == '/') {
598 --rn, ++rptr; // drop leading separator.
599 }
600
601 ats_scoped_str x(ln + rn + 2);
602
603 memcpy(x, lhs, ln);
604 x[ln] = '/';
605 memcpy(x + ln + 1, rptr, rn);
606 x[ln + rn + 1] = 0; // terminate string.
607
608 return x.release();
609}
610
611struct ats_unique_buf_deleter {
612 void

Callers

nothing calls this directly

Calls 2

memcpyFunction · 0.50
releaseMethod · 0.45

Tested by

no test coverage detected