diff --git a/doc/internal/man3/ossl_ends_with_dirsep.pod b/doc/internal/man3/ossl_ends_with_dirsep.pod index 1924ab50f0..d19ce7a3b9 100644 --- a/doc/internal/man3/ossl_ends_with_dirsep.pod +++ b/doc/internal/man3/ossl_ends_with_dirsep.pod @@ -2,8 +2,8 @@ =head1 NAME -ossl_ends_with_dirsep - internal function to detect whether a path -ends with directory separator +ossl_ends_with_dirsep, ossl_is_absolute_path +- internal functions to work with paths =head1 SYNOPSIS @@ -11,19 +11,26 @@ ends with directory separator int ossl_ends_with_dirsep(const char *path); + int ossl_is_absolute_path(const char *path); + =head1 DESCRIPTION ossl_ends_with_dirsep() detects whether the I ends with a directory -separator in platform agnostic way. +separator in a platform agnostic way. + +ossl_is_absolute_path() detects whether the I is absolute path in +a platform agnostic way. =head1 RETURN VALUES ossl_ends_with_dirsep() returns 1 if the I ends with a directory separator, 0 otherwise. +ossl_is_absolute_path() returns 1 if the I is absolute, 0 otherwise. + =head1 HISTORY -The function described here was added in OpenSSL 3.0. +The functions described here were added in OpenSSL 3.0. =head1 COPYRIGHT diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h index f1c6ddfd30..eae10dfb6c 100644 --- a/include/internal/cryptlib.h +++ b/include/internal/cryptlib.h @@ -267,4 +267,20 @@ static ossl_inline int ossl_ends_with_dirsep(const char *path) return *path == '/'; } +static ossl_inline int ossl_is_absolute_path(const char *path) +{ +# if defined __VMS + if (strchr(path, ':') != NULL + || ((path[0] == '[' || path[0] == '<') + && path[1] != '.' && path[1] != '-' + && path[1] != ']' && path[1] != '>')) + return 1; +# elif defined _WIN32 + if (path[0] == '\\' + || (path[0] != '\0' && path[1] == ':')) + return 1; +# endif + return path[0] == '/'; +} + #endif