123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #define _GNU_SOURCE
- #include "common-profile.h"
- #include "common-logging.h"
- const char *profile_path = "/sys/firmware/acpi/platform_profile";
- const char *get_profile_state(void)
- {
-
- static char profile[64] = { 0 };
- memset(profile, 0, sizeof(profile));
- FILE *f = fopen(profile_path, "r");
- if (!f) {
- LOG_ERROR("Failed to open file for read %s\n", profile_path);
- return "none";
- }
-
- fseek(f, 0, SEEK_END);
- long length = ftell(f);
- fseek(f, 0, SEEK_SET);
- if (length == -1) {
- LOG_ERROR("Failed to seek file %s\n", profile_path);
- } else {
- char contents[length + 1];
- if (fread(contents, 1, (size_t)length, f) > 0) {
- strtok(contents, "\n");
- strncpy(profile, contents, sizeof(profile) - 1);
- } else {
- LOG_ERROR("Failed to read contents of %s\n", profile_path);
- }
- }
- fclose(f);
- return profile;
- }
|