diff --git a/opal/util/path.c b/opal/util/path.c index bab22cd6f6..5e420239d7 100644 --- a/opal/util/path.c +++ b/opal/util/path.c @@ -32,6 +32,21 @@ static void path_env_load(char *path, int *pargc, char ***pargv); static char *path_access(char *fname, char *path, int mode); static char *list_env_get(char *var, char **list); +bool opal_path_is_absolute( const char *path ) +{ +#if defined(__WINDOWS__) + /* On Windows an absolute path always start with [a-z]:\ */ + if( ':' == path[1] ) { + return true; + } +#else + if( OPAL_PATH_SEP[0] == *path ) { + return true; + } +#endif /* defined(__WINDOWS__) */ + return false; +} + /** * Locates a file with certain permissions */ @@ -44,8 +59,7 @@ char *opal_path_find(char *fname, char **pathv, int mode, char **envv) int i; /* If absolute path is given, return it without searching. */ - - if (OPAL_PATH_SEP[0] == *fname) { + if( opal_path_is_absolute(fname) ) { return path_access(fname, "", mode); } diff --git a/opal/util/path.h b/opal/util/path.h index e0c111859b..bc06bd4244 100644 --- a/opal/util/path.h +++ b/opal/util/path.h @@ -69,6 +69,19 @@ extern "C" { */ OPAL_DECLSPEC char *opal_path_findv(char *fname, int mode, char **envv, char *wrkdir); + /** + * Detect if the requested path is absolute or relative. + * + * @param path File name + * + * @retval true if the path is absolute + * @retval false otherwise + * + * Detect if a path is absolute or relative. Handle Windows + * with special care as an absolute path on Windows starts + * with [A-Za-z]: instead of the usual / on UNIX. + */ + OPAL_DECLSPEC bool opal_path_is_absolute( const char *path ); #if defined(c_plusplus) || defined(__cplusplus) }