/* If path ends with suffix (complete path components), returns the part before suffix (sans trailing directory separators). Otherwise returns NULL.  */
char* strip_path_suffix(const char *path, const char *suffix)
/* If path ends with suffix (complete path components), returns the part before suffix (sans trailing directory separators). Otherwise returns NULL.  */
char* strip_path_suffix(const char *path, const char *suffix)
{
	int path_len = strlen(path), suffix_len = strlen(suffix);
	while (suffix_len) {
		if (!path_len)
			return NULL;
		if (is_dir_sep(path[path_len - 1])) {
			if (!is_dir_sep(suffix[suffix_len - 1]))
				return NULL;
			path_len = chomp_trailing_dir_sep(path, path_len);
			suffix_len = chomp_trailing_dir_sep(suffix, suffix_len);
		}
		else if (path[--path_len] != suffix[--suffix_len])
			return NULL;
	}
	if (path_len && !is_dir_sep(path[path_len - 1]))
		return NULL;
	return xstrndup(path, chomp_trailing_dir_sep(path, path_len));
}