mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 15:28:30 +00:00
Make minor improvements
This commit is contained in:
parent
04caf6f9ad
commit
95b142e4e5
95 changed files with 3818 additions and 2760 deletions
|
@ -22,14 +22,25 @@
|
|||
#include "libc/x/x.h"
|
||||
|
||||
/**
|
||||
* Joins paths.
|
||||
* Joins paths, e.g.
|
||||
*
|
||||
* "a" + "b" → "a/b"
|
||||
* "a/" + "b" → "a/b"
|
||||
* "a" + "b/" → "a/b/"
|
||||
* "a" + "/b" → "/b"
|
||||
* "." + "b" → "b"
|
||||
* "" + "b" → "b"
|
||||
*
|
||||
* @return newly allocated string of resulting path
|
||||
*/
|
||||
char *xjoinpaths(const char *path, const char *other) {
|
||||
if (!*other) {
|
||||
return xstrdup(path);
|
||||
} else if (startswith(other, "/") || strcmp(path, ".") == 0) {
|
||||
} else if (!*path) {
|
||||
return xstrdup(other);
|
||||
} else if (endswith(other, "/")) {
|
||||
} else if (startswith(other, "/") || !strcmp(path, ".")) {
|
||||
return xstrdup(other);
|
||||
} else if (endswith(path, "/")) {
|
||||
return xstrcat(path, other);
|
||||
} else {
|
||||
return xstrcat(path, '/', other);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue