-
-
Save dlevi309/b9a372ecd320965fa19f42d61df477c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <IOKit/pwr_mgt/IOPMLib.h> | |
#include <IOKit/IOMessage.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sysexits.h> | |
static void sleepHandler(int sleepType) | |
{ | |
io_connect_t connect = IOPMFindPowerManagement(kIOMasterPortDefault); | |
IOReturn ret = IOPMSleepSystem(connect); | |
if (ret != kIOReturnSuccess) { | |
if (ret == kIOReturnNotPrivileged) { | |
printf("Sleep error 0x%08x; You must run this as root.\n", ret); | |
exit(EX_NOPERM); | |
} else { | |
printf("Unable to sleep system: error 0x%08x\n", ret); | |
exit(EX_OSERR); | |
} | |
} else { | |
printf("Sleeping now...\n"); | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
int sleepType = 0; | |
sleepHandler(sleepType); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment