I have code that I want to run only if the user has not booted in safe mode. Is there any way I can use the standard CoreFoundation or C standard APIs that I can detect?
EDIT: here is my code thanks to my accepted answer:
#include <sys/sysctl.h> ... int safeBoot; int mib_name[2] = { CTL_KERN, KERN_SAFEBOOT }; size_t length = sizeof(safeBoot); if (!sysctl(mib_name, 2, &safeBoot, &length, NULL, 0)) { if (safeBoot == 1) { // We are in safe mode } else { // Normal mode. Continue… } } else { // Couldn't find safe boot information }
c macos
Alex zielenski
source share