src/bin/pg_upgrade/option.c
static void
check_required_directory(char **dirpath, const char *envVarName, bool useCwd,
						 const char *cmdLineOption, const char *description,
						 bool missingOk)
{
	if (*dirpath == NULL || strlen(*dirpath) == 0)
	{
		const char *envVar;

		if ((envVar = getenv(envVarName)) && strlen(envVar))
			*dirpath = pg_strdup(envVar);
		else if (useCwd)
		{
			char		cwd[MAXPGPATH];

			if (!getcwd(cwd, MAXPGPATH))
				pg_fatal("could not determine current directory\n");
			*dirpath = pg_strdup(cwd);
		}
		else if (missingOk)
			return;
		else
			pg_fatal("You must identify the directory where the %s.\n"
					 "Please use the %s command-line option or the %s environment variable.\n",
					 description, cmdLineOption, envVarName);
	}

	/*
	 * Clean up the path, in particular trimming any trailing path separators,
	 * because we construct paths by appending to this path.
	 */
	canonicalize_path(*dirpath);
}
/*
 * check_required_directory()
 *
 * Checks a directory option.
 *	dirpath		  - the directory name supplied on the command line, or NULL
 *	envVarName	  - the name of an environment variable to get if dirpath is NULL
 *	useCwd		  - true if OK to default to CWD
 *	cmdLineOption - the command line option for this directory
 *	description   - a description of this directory option
 *	missingOk	  - true if OK that both dirpath and envVarName are not existing
 *
 * We use the last two arguments to construct a meaningful error message if the
 * user hasn't provided the required directory name.
 */
check_required_directory()
Checks a directory option.

We use the last two arguments to construct a meaningful error message if the
user hasn't provided the required directory name.
check_required_directory () Checks a directory option . We use the last two arguments to construct a meaningful error message if the user hasn ' t provided the required directory name .
static void
check_required_directory(char **dirpath, const char *envVarName, bool useCwd,
						 const char *cmdLineOption, const char *description,
						 bool missingOk)
{
	if (*dirpath == NULL || strlen(*dirpath) == 0)
	{
		const char *envVar;
		if ((envVar = getenv(envVarName)) && strlen(envVar))
			*dirpath = pg_strdup(envVar);
		else if (useCwd)
		{
			char		cwd[MAXPGPATH];
			if (!getcwd(cwd, MAXPGPATH))
				pg_fatal("could not determine current directory\n");
			*dirpath = pg_strdup(cwd);
		}
		else if (missingOk)
			return;
		else
			pg_fatal("You must identify the directory where the %s.\n"
					 "Please use the %s command-line option or the %s environment variable.\n",
					 description, cmdLineOption, envVarName);
	}
	canonicalize_path(*dirpath);
}
static void check_required_directory ( char * * dirpath , const char * envVarName , bool useCwd , const char * cmdLineOption , const char * description , bool missingOk ) { if ( * dirpath == NULL || strlen ( * dirpath ) == 0 ) { const char * envVar ; if ( ( envVar = getenv ( envVarName ) ) && strlen ( envVar ) ) * dirpath = pg_strdup ( envVar ) ; else if ( useCwd ) { char cwd [ MAXPGPATH ] ; if ( ! getcwd ( cwd , MAXPGPATH ) ) pg_fatal ( " \n " ) ; * dirpath = pg_strdup ( cwd ) ; } else if ( missingOk ) return ; else pg_fatal ( " \n " " \n " , description , cmdLineOption , envVarName ) ; } canonicalize_path ( * dirpath ) ; }
check_required_directory()
 Checks a directory option.
check_required_directory () Checks a directory option .
/*
	 * Clean up the path, in particular trimming any trailing path separators,
	 * because we construct paths by appending to this path.
	 */