File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < stdio.h>
2
+ #include < stdlib.h>
3
+ #include < pthread.h>
4
+ #include < sys/sysctl.h>
5
+ #include < mach/mach.h>
6
+ #include < unistd.h> // geteuid();
7
+ #include < string.h>
8
+
9
+ char offargument[] = " --off" ;
10
+ char onargument[] = " --on" ;
11
+
12
+ kern_return_t get_privileges_status (){
13
+
14
+ if (geteuid () != 0 ){
15
+ return KERN_FAILURE;
16
+ } else if (geteuid () == 0 ){
17
+ // Got root
18
+ }
19
+ return KERN_SUCCESS;
20
+ }
21
+
22
+ int main (int argc, char *argv[])
23
+ {
24
+ if (argc < 2 ){
25
+ printf (" Usage: sleeputil --off / --on\n " );
26
+ return -1 ;
27
+ } else if (argc == 2 ){
28
+ if (get_privileges_status () == KERN_SUCCESS){
29
+ char *controlstring = new char [strlen (argv[1 ])];
30
+ strcpy (controlstring, argv[1 ]);
31
+ printf (" Sleeputil by GeoSn0w (@FCE365)\n A wrapper around pmset I did for my own use.\n Use at your own risk!\n\n NOTE! Other processes may prevent sleep from occuring!\n\n " );
32
+ if (strcmp (offargument, controlstring) == 0 ){
33
+ printf (" Disabling sleep on this Mac...\n\n " );
34
+ system (" pmset -b sleep 0" );
35
+ system (" pmset -b disablesleep 1" );
36
+ } else if (strcmp (onargument, controlstring) == 0 ){
37
+ printf (" Enabling sleep on this Mac...\n\n " );
38
+ system (" pmset -b sleep 5" );
39
+ system (" pmset -b disablesleep 0" );
40
+ } else {
41
+ printf (" Usage: sleeputil --off / --on\n " );
42
+ }
43
+ } else {
44
+ printf (" Please run this program as root. Do that with sudo\n " );
45
+ }
46
+ } else if (argc > 2 ){
47
+ printf (" Too many arguments!\n Usage: sleeputil --off / --on\n " );
48
+ return -1 ;
49
+ }
50
+ return 0 ;
51
+ }
You can’t perform that action at this time.
0 commit comments