base/fs/m_fs_path_norm.c
/* Try to follow a path if it was an environment variable. Rewrite the dirs approperately. */
/* Try to follow a path as if it was a symlink. If it is a symlink rewrite the
 * dirs appropriatly.
 */
Try to follow a path if it was an environment variable. Rewrite the dirs approperately.
Try to follow a path as if it was a symlink. If it is a symlink rewrite the
dirs appropriatly.
Try to follow a path if it was an environment variable . Rewrite the dirs approperately . Try to follow a path as if it was a symlink . If it is a symlink rewrite the dirs appropriatly .
static M_fs_error_t M_fs_path_norm_symlink(char **out, M_list_str_t **base, const M_list_str_t *parts, M_fs_path_norm_t flags, M_fs_system_t sys_type, M_hash_strvp_t *seen)
{
	char         *path;
	char         *retpath = NULL;
	M_fs_error_t  ret;
	if (out == NULL || base == NULL || *base == NULL || M_list_str_len(*base) == 0 || parts == NULL) {
		return M_FS_ERROR_GENERIC;
	}
	*out = NULL;
	path = M_fs_path_join_parts(*base, sys_type);
	if (path == NULL) {
		return M_FS_ERROR_INVALID;
	}
	ret = M_fs_path_readlink_int(&retpath, path, M_list_str_len(parts) == 0 ? M_TRUE : M_FALSE, flags, sys_type);
	M_free(path);
	if (ret != M_FS_ERROR_SUCCESS || (ret == M_FS_ERROR_SUCCESS && retpath == NULL)) {
		M_free(retpath);
		return ret;
	}
	if (M_fs_path_isabs(retpath, sys_type)) {
		M_list_str_remove_range(*base, 0, M_list_str_len(*base));
	} else {
		M_list_str_remove_at(*base, M_list_str_len(*base)-1);
	}
	M_list_str_merge(base, M_fs_path_componentize_path(retpath, sys_type), M_TRUE);
	M_free(retpath);
	M_list_str_merge(base, M_list_str_duplicate(parts), M_TRUE);
	path = M_fs_path_join_parts(*base, sys_type);
	M_list_str_remove_range(*base, 0, M_list_str_len(*base));
	ret = M_fs_path_norm_int(out, path, flags, sys_type, seen);
	M_free(path);
	return ret;
}
static M_fs_error_t M_fs_path_norm_symlink ( char * * out , M_list_str_t * * base , const M_list_str_t * parts , M_fs_path_norm_t flags , M_fs_system_t sys_type , M_hash_strvp_t * seen ) { char * path ; char * retpath = NULL ; M_fs_error_t ret ; if ( out == NULL || base == NULL || * base == NULL || M_list_str_len ( * base ) == 0 || parts == NULL ) { return M_FS_ERROR_GENERIC ; } * out = NULL ; path = M_fs_path_join_parts ( * base , sys_type ) ; if ( path == NULL ) { return M_FS_ERROR_INVALID ; } ret = M_fs_path_readlink_int ( & retpath , path , M_list_str_len ( parts ) == 0 ? M_TRUE : M_FALSE , flags , sys_type ) ; M_free ( path ) ; if ( ret != M_FS_ERROR_SUCCESS || ( ret == M_FS_ERROR_SUCCESS && retpath == NULL ) ) { M_free ( retpath ) ; return ret ; } if ( M_fs_path_isabs ( retpath , sys_type ) ) { M_list_str_remove_range ( * base , 0 , M_list_str_len ( * base ) ) ; } else { M_list_str_remove_at ( * base , M_list_str_len ( * base ) - 1 ) ; } M_list_str_merge ( base , M_fs_path_componentize_path ( retpath , sys_type ) , M_TRUE ) ; M_free ( retpath ) ; M_list_str_merge ( base , M_list_str_duplicate ( parts ) , M_TRUE ) ; path = M_fs_path_join_parts ( * base , sys_type ) ; M_list_str_remove_range ( * base , 0 , M_list_str_len ( * base ) ) ; ret = M_fs_path_norm_int ( out , path , flags , sys_type , seen ) ; M_free ( path ) ; return ret ; }
Try to follow a path if it was an environment variable.
Try to follow a path if it was an environment variable .
/* Turn our path components into a path. */ /* Either we have a failure or a success where no symlink was followed. */ /* Otherwise we followed a symlink and we have a new path. */ /* Remove everything if the new path is an abs path. */ /* Only remove the last part if the new path is relative because it's
	 * relative to the last part. */ /* Put our new path into the list of parts. */ /* Merge our base with our remaining parts and normalize our new path.
 	 * We duplicate parts because the caller needs to handle destroying it. */ /* Remove everything from base because we don't need it anymore. but we shouldn't destory things we don't own. */