Join strings p1 & p2 into "dest" with a guaranteed '/' between them. (If * p1 ends with a '/', no extra '/' is inserted.) Returns the length of both * strings + 1 (if '/' was inserted), regardless of whether the null-terminated * string fits into destsize. */
| 888 | * strings + 1 (if '/' was inserted), regardless of whether the null-terminated |
| 889 | * string fits into destsize. */ |
| 890 | size_t pathjoin(char *dest, size_t destsize, const char *p1, const char *p2) |
| 891 | { |
| 892 | size_t len = strlcpy(dest, p1, destsize); |
| 893 | if (len < destsize - 1) { |
| 894 | if (!len || dest[len-1] != '/') |
| 895 | dest[len++] = '/'; |
| 896 | if (len < destsize - 1) |
| 897 | len += strlcpy(dest + len, p2, destsize - len); |
| 898 | else { |
| 899 | dest[len] = '\0'; |
| 900 | len += strlen(p2); |
| 901 | } |
| 902 | } |
| 903 | else |
| 904 | len += strlen(p2) + 1; /* Assume we'd insert a '/'. */ |
| 905 | return len; |
| 906 | } |
| 907 | |
| 908 | /* Join any number of strings together, putting them in "dest". The return |
| 909 | * value is the length of all the strings, regardless of whether the null- |
no test coverage detected