base/fs/m_fs_path_norm.c
/* Create an absolute path from a relative path using the cwd. */
Create an absolute path from a relative path using the cwd.
Create an absolute path from a relative path using the cwd .
static M_bool M_fs_path_norm_abs(M_list_str_t **dirs, M_fs_system_t sys_type)
{
	M_list_str_t *temp_l;
	char         *temp;
	const char   *part;
	size_t        path_max;
#ifdef _WIN32
	DWORD         dpath_max;
#endif
	if (dirs == NULL || *dirs == NULL) {
		return M_FALSE;
	}
	if (M_list_str_len(*dirs) == 0) {
		return M_FALSE;
	}
	sys_type = M_fs_path_get_system_type(sys_type);
	path_max = M_fs_path_get_path_max(sys_type);
	temp     = M_malloc(path_max);
	part = M_list_str_at(*dirs, 0);
	if ((part != NULL && *part == '\0') || (sys_type == M_FS_SYSTEM_WINDOWS && M_fs_path_isabs(part, sys_type))) {
		M_free(temp);
		return M_TRUE;
	}
#ifdef _WIN32
	if (!M_win32_size_t_to_dword(path_max, &dpath_max)) {
		M_free(temp);
		return M_FALSE;
	}
	if (GetCurrentDirectory(dpath_max-1, temp) == 0) {
#else
	if (!getcwd(temp, path_max-1)) {
#endif
		M_free(temp);
		return M_FALSE;
	}
	temp_l = M_fs_path_componentize_path(temp, sys_type);
	M_free(temp);
	M_list_str_merge(&temp_l, *dirs, M_TRUE);
	*dirs = temp_l;
	return M_TRUE;
}
static M_bool M_fs_path_norm_abs ( M_list_str_t * * dirs , M_fs_system_t sys_type ) { M_list_str_t * temp_l ; char * temp ; const char * part ; size_t path_max ; #ifdef _WIN32 DWORD dpath_max ; #endif if ( dirs == NULL || * dirs == NULL ) { return M_FALSE ; } if ( M_list_str_len ( * dirs ) == 0 ) { return M_FALSE ; } sys_type = M_fs_path_get_system_type ( sys_type ) ; path_max = M_fs_path_get_path_max ( sys_type ) ; temp = M_malloc ( path_max ) ; part = M_list_str_at ( * dirs , 0 ) ; if ( ( part != NULL && * part == ' \0 ' ) || ( sys_type == M_FS_SYSTEM_WINDOWS && M_fs_path_isabs ( part , sys_type ) ) ) { M_free ( temp ) ; return M_TRUE ; } #ifdef _WIN32 if ( ! M_win32_size_t_to_dword ( path_max , & dpath_max ) ) { M_free ( temp ) ; return M_FALSE ; } if ( GetCurrentDirectory ( dpath_max - 1 , temp ) == 0 ) { #else 
	if (!getcwd(temp, path_max-1)) { #endif 
		M_free(temp); return M_FALSE ; } temp_l = M_fs_path_componentize_path ( temp , sys_type ) ; M_free ( temp ) ; M_list_str_merge ( & temp_l , * dirs , M_TRUE ) ; * dirs = temp_l ; return M_TRUE ; }
Create an absolute path from a relative path using the cwd.
Create an absolute path from a relative path using the cwd .
/* If the path starts with an empty then this is already an abs path so we
	 * don't need to do anything */ /* Try to get the cwd. */ /* Put the componitized cwd in front of the list of dirs */