1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <stdlib.h> #include <stdio.h> #include <errno.h> static const char *state_path = "/sys/power/state"; int main(void) { FILE *fp = fopen(state_path, "w"); if (fp) { fprintf(fp, "mem"); } else { perror(state_path); return errno; } return EXIT_SUCCESS; }