I have checked my solution and it is somewhat relevant for the question as asked. As I've mentioned, I'd struggled with the same issue. In the z/OS environment I am not required to provide both POSIX and PCRE at the same time. Also, for technical reasons I have to supply short name (8 characters or less) for many of the functions (where the function name and file name are the same). I have separated the native POSIX functions from the PCRE equivalent and gave them distinct different names. I've also provided LE (the 'standard' IBM common Language Environment) API that allows usage of short or long names and the normal POSIX names at will. Here is the relevant section from my port documentation:
13. POSIX API in PCRE2----------------------Support for the POSIX API in PCRE2 was never meant to support the regex model of POSIX, just to provide the user with the familiar API, but with the PCRE2 (Perl Compatibility) regex model. In order to prevent undue conflicts in the binding (linkedit) step, I've decided to change the API by providing PCRE2 specific names for the four POSIX functions. The user is advised, of course, never to use the regex.h header in conjunction with PCRE2 in order to prevent conflict in compile time (for C.)Users may, obviously, use the provided PCRE2 function names (and include the POSIX module PC2POSIX in the binding step,) as is done internally in PCRE2 for z/OS. However to give the user the full beauty of this functionality, the user may include the provided header file PC2PSXPG.h (of four pragma map statements,) and continue to use the native POSIX function names. Remember that you need also the posixh.h and the pcre2.h header files. The provided IBMSAMPL.c program demonstrates how to compile such programs with option to use either the original POSIX functionality [UNDEF(COMPILE_WITH_PCRE2=1)] or the PCRE2 functionality [DEF(COMPILE_WITH_PCRE2=1)]. See the provided output snippets below to demonstrate the difference. For languages that do not have pragma map or any equivalent, just use the PCRE2 function names.Note that the provided API program, PCOBAPI2.c had a section that tried to deal with the issue. This section is now commented out and the compile option UNDEF(NATIVE_ZOS_POSIX) does nothing.
The COMPILE_WITH_PCRE2 is implemented in a standard header PC2PSXAP.h, that will replace the aforementioned PC2PSXPG.h in the next release. The header looks like this:
...PCRE License, etc....#ifdef COMPILE_WITH_PCRE2/* This header contains a few pragma statements to make the compiler use the PCRE2 equivalents of the traditional POSIX functions*/#include "pcre2.h"#include "posixh.h"#pragma map (regfree, "PREGFREE")#pragma map (regerror, "PREGERR")#pragma map (regexec, "PREGEXEC")#pragma map (regcomp, "PREGCOMP")static unsigned char COMPILE_OPTION[] = "COMPILE WITH PCRE2";#elsestatic unsigned char COMPILE_OPTION[] = "COMPILE WITH POSIX";#include <regex.h>#endif