src/backend/utils/init/miscinit.c
/*
 * If the given pathname isn't already absolute, make it so, interpreting
 * it relative to the current working directory.
 *
 * Also canonicalizes the path.  The result is always a malloc'd copy.
 *
 * Note: interpretation of relative-path arguments during postmaster startup
 * should happen before doing ChangeToDataDir(), else the user will probably
 * not like the results.
 */
If the given pathname isn't already absolute, make it so, interpreting
it relative to the current working directory.

Also canonicalizes the path.  The result is always a malloc'd copy.

interpretation of relative-path arguments during postmaster startup
should happen before doing ChangeToDataDir(), else the user will probably
not like the results.
If the given pathname isn ' t already absolute make it so interpreting it relative to the current working directory . Also canonicalizes the path . The result is always a malloc ' d copy . interpretation of relative - path arguments during postmaster startup should happen before doing ChangeToDataDir () else the user will probably not like the results .
char *
make_absolute_path(const char *path)
{
	char	   *new;
	if (path == NULL)
		return NULL;
	if (!is_absolute_path(path))
	{
		char	   *buf;
		size_t		buflen;
		buflen = MAXPGPATH;
		for (;;)
		{
			buf = malloc(buflen);
			if (!buf)
				ereport(FATAL,
						(errcode(ERRCODE_OUT_OF_MEMORY),
						 errmsg("out of memory")));
			if (getcwd(buf, buflen))
				break;
			else if (errno == ERANGE)
			{
				free(buf);
				buflen *= 2;
				continue;
			}
			else
			{
				free(buf);
				elog(FATAL, "could not get current working directory: %m");
			}
		}
		new = malloc(strlen(buf) + strlen(path) + 2);
		if (!new)
			ereport(FATAL,
					(errcode(ERRCODE_OUT_OF_MEMORY),
					 errmsg("out of memory")));
		sprintf(new, "%s/%s", buf, path);
		free(buf);
	}
	else
	{
		new = strdup(path);
		if (!new)
			ereport(FATAL,
					(errcode(ERRCODE_OUT_OF_MEMORY),
					 errmsg("out of memory")));
	}
	canonicalize_path(new);
	return new;
}
char * make_absolute_path ( const char * path ) { char * new ; if ( path == NULL ) return NULL ; if ( ! is_absolute_path ( path ) ) { char * buf ; size_t buflen ; buflen = MAXPGPATH ; for ( ; ; ) { buf = malloc ( buflen ) ; if ( ! buf ) ereport ( FATAL , ( errcode ( ERRCODE_OUT_OF_MEMORY ) , errmsg ( " " ) ) ) ; if ( getcwd ( buf , buflen ) ) break ; else if ( errno == ERANGE ) { free ( buf ) ; buflen *= 2 ; continue ; } else { free ( buf ) ; elog ( FATAL , " " ) ; } } new = malloc ( strlen ( buf ) + strlen ( path ) + 2 ) ; if ( ! new ) ereport ( FATAL , ( errcode ( ERRCODE_OUT_OF_MEMORY ) , errmsg ( " " ) ) ) ; sprintf ( new , " " , buf , path ) ; free ( buf ) ; } else { new = strdup ( path ) ; if ( ! new ) ereport ( FATAL , ( errcode ( ERRCODE_OUT_OF_MEMORY ) , errmsg ( " " ) ) ) ; } canonicalize_path ( new ) ; return new ; }
If the given pathname isn't already absolute, make it so, interpreting
 it relative to the current working directory.
If the given pathname isn ' t already absolute make it so interpreting it relative to the current working directory .
/* Returning null for null input is convenient for some callers */ /* Make sure punctuation is canonical, too */