diff options
author | Tomas Mraz <tmraz@fedoraproject.org> | 2020-11-03 18:34:16 +0100 |
---|---|---|
committer | Tomas Mraz <tmraz@fedoraproject.org> | 2020-11-11 16:06:30 +0100 |
commit | 368d9e030fac7355f0d1d24fb5059bf0c848fe4f (patch) | |
tree | 8ee01c7c08531fa87a5acd2f0c14b722d727b355 | |
parent | 69d16b70cf84f0e290990de424274fde20420b78 (diff) |
Add ossl_is_absolute_path function to detect absolute paths
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13306)
-rw-r--r-- | doc/internal/man3/ossl_ends_with_dirsep.pod | 15 | ||||
-rw-r--r-- | include/internal/cryptlib.h | 16 |
2 files changed, 27 insertions, 4 deletions
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<path> ends with a directory -separator in platform agnostic way. +separator in a platform agnostic way. + +ossl_is_absolute_path() detects whether the I<path> is absolute path in +a platform agnostic way. =head1 RETURN VALUES ossl_ends_with_dirsep() returns 1 if the I<path> ends with a directory separator, 0 otherwise. +ossl_is_absolute_path() returns 1 if the I<path> 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 |