I've done a lot more work on this, and I have the impression that this is a bug in macOS, at least on 12 and 13 Intel. #include #include #include #include #include #include // used for debugging apple pointer issues, see // https://bugs.kde.org/show_bug.cgi?id=517304 #define DEBUG_ENV // On Darwin there's this secret fourth argument, 'apple'. // That's kind of like a cut down obfuscated version of auxv. // For the moment we only support the first entry, executable_path= int main(int argc, char *argv[], char *envp[], char *apple[]) { char *pargv = calloc((PATH_MAX+1), sizeof(char)), *pappl = calloc((PATH_MAX+1), sizeof(char)); int i; for (i = 0; envp[i]; i++) { #if defined(DEBUG_ENV) fprintf(stderr, apple-main-arg: i %d &envp[i] %p envp[i] %sn, i, &envp[i], envp[i]); #endif } #if defined(DEBUG_ENV) fprintf(stderr, 2 slots after envpn); fprintf(stderr, apple-main-arg: i %d &envp[i] %p envp[i] %sn, i, &envp[i], envp[i]); fprintf(stderr, apple-main-arg: i %d &envp[i] %p envp[i] %sn, i+1,