2 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #ifndef OSSL_INTERNAL_COMMON_H
11 # define OSSL_INTERNAL_COMMON_H
16 # include "../../e_os.h" /* To get strncasecmp() on Windows */
18 # include "internal/nelem.h"
21 # define ossl_assert(x) ((x) != 0)
23 __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
24 const char *file, int line)
27 OPENSSL_die(exprstr, file, line);
32 # define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \
37 /* Check if |pre|, which must be a string literal, is a prefix of |str| */
38 #define HAS_PREFIX(str, pre) (strncmp(str, pre "", sizeof(pre) - 1) == 0)
39 /* As before, and if check succeeds, advance |str| past the prefix |pre| */
40 #define CHECK_AND_SKIP_PREFIX(str, pre) \
41 (HAS_PREFIX(str, pre) ? ((str) += sizeof(pre) - 1, 1) : 0)
42 /* Check if the string literal |p| is a case-insensitive prefix of |s| */
43 #define HAS_CASE_PREFIX(s, p) (strncasecmp(s, p "", sizeof(p) - 1) == 0)
44 /* As before, and if check succeeds, advance |str| past the prefix |pre| */
45 #define CHECK_AND_SKIP_CASE_PREFIX(str, pre) \
46 (HAS_CASE_PREFIX(str, pre) ? ((str) += sizeof(pre) - 1, 1) : 0)
47 /* Check if the string literal |suffix| is a case-insensitive suffix of |str| */
48 #define HAS_CASE_SUFFIX(str, suffix) (strlen(str) < sizeof(suffix) - 1 ? 0 : \
49 strcasecmp(str + strlen(str) - sizeof(suffix) + 1, suffix "") == 0)
52 * Use this inside a union with the field that needs to be aligned to a
53 * reasonable boundary for the platform. The most pessimistic alignment
54 * of the listed types will be used by the compiler.
56 # define OSSL_UNION_ALIGN \
58 ossl_uintmax_t align_int; \
61 # define OPENSSL_CONF "openssl.cnf"
63 # ifndef OPENSSL_SYS_VMS
64 # define X509_CERT_AREA OPENSSLDIR
65 # define X509_CERT_DIR OPENSSLDIR "/certs"
66 # define X509_CERT_FILE OPENSSLDIR "/cert.pem"
67 # define X509_PRIVATE_DIR OPENSSLDIR "/private"
68 # define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf"
70 # define X509_CERT_AREA "OSSL$DATAROOT:[000000]"
71 # define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]"
72 # define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem"
73 # define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]"
74 # define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf"
77 # define X509_CERT_DIR_EVP "SSL_CERT_DIR"
78 # define X509_CERT_FILE_EVP "SSL_CERT_FILE"
79 # define CTLOG_FILE_EVP "CTLOG_FILE"
81 /* size of string representations */
82 # define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
83 # define HEX_SIZE(type) (sizeof(type)*2)
85 static ossl_inline int ossl_ends_with_dirsep(const char *path)
88 path += strlen(path) - 1;
90 if (*path == ']' || *path == '>' || *path == ':')
99 static ossl_inline int ossl_is_absolute_path(const char *path)
102 if (strchr(path, ':') != NULL
103 || ((path[0] == '[' || path[0] == '<')
104 && path[1] != '.' && path[1] != '-'
105 && path[1] != ']' && path[1] != '>'))
107 # elif defined _WIN32
109 || (path[0] != '\0' && path[1] == ':'))
112 return path[0] == '/';