Path: blob/main/crypto/krb5/src/include/k5-regex.h
34878 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* include/k5-regex.h - Compatibility glue for std::regex on Windows */23/*4* Copyright (C) 2024 United States Government as represented by the5* Secretary of the Navy.6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11*12* * Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14*15* * Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in17* the documentation and/or other materials provided with the18* distribution.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS23* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE24* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,25* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES26* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR27* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,29* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)30* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED31* OF THE POSSIBILITY OF SUCH DAMAGE.32*/3334/*35* On POSIX platforms we can use the standardized regcomp()/regexec() function36* calls. Windows does not provide POSIX regex functions, but does provide a37* C++ interface (std::regex) that has the same functionality.38*/3940#ifndef _K5_REGEX_H_41#define _K5_REGEX_H_4243#ifndef _WIN324445/* On POSIX platforms, just include regex.h. */46#include <regex.h>4748#else /* _WIN32 */4950#ifdef __cplusplus51extern "C" {52#endif /* __cplusplus */5354/* On Windows, emulate the POSIX interface using functions from55* libkrb5support. */5657typedef struct {58size_t re_nsub; /* Number of subexpressions */59void *regex; /* Pointer to std::basic_regex */60char errmsg[128]; /* Regular expression error message */61} regex_t;6263typedef ssize_t regoff_t;6465typedef struct {66regoff_t rm_so;67regoff_t rm_eo;68} regmatch_t;6970/*71* Flags to k5_regcomp()72*/7374#define REG_BASIC 0x00 /* Basic regular expressions */75#define REG_EXTENDED 0x01 /* Extended regular expressions */76#define REG_ICASE 0x02 /* Case-insensitive match */77#define REG_NOSUB 0x04 /* Do not do submatching */7879/*80* Flags to k5_regexec()81*/8283#define REG_NOTBOL 0x01 /* First character not at beginning of line */84#define REG_NOTEOL 0x02 /* Last character not at end of line */8586/*87* Error return codes for k5_regcomp()/k5_regexec()88*89* We only define REG_NOMATCH and REG_BADPAT, since no Kerberos code looks90* for anything other than success and REG_NOMATCH.91*/9293#define REG_NOMATCH 194#define REG_BADPAT 29596/*97* Note that we don't follow the POSIX API exactly because k5_regexec()98* doesn't declare regex_t as const; that's so we can store an error99* string.100*/101int k5_regcomp(regex_t *preg, const char *pattern, int flags);102int k5_regexec(regex_t *preg, const char *string, size_t,103regmatch_t pmatch[], int flags);104size_t k5_regerror(int code, const regex_t *preg, char *errmsg,105size_t errmsg_size);106void k5_regfree(regex_t *preg);107108#define regcomp k5_regcomp109#define regexec k5_regexec110#define regerror k5_regerror111#define regfree k5_regfree112113#ifdef __cplusplus114}115#endif /* __cplusplus */116#endif /* _WIN32 */117#endif /* _K5_REGEX_H_ */118119120