| /* | |
| * Copyright 2024 Intel Corporation | |
| * SPDX-License-Identifier: MIT | |
| */ | |
| #include "intel_perf_common.h" | |
| #include <errno.h> | |
| #include <fcntl.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| bool | |
| read_file_uint64(const char *file, uint64_t *val) | |
| { | |
| char buf[32]; | |
| int fd, n; | |
| fd = open(file, 0); | |
| if (fd < 0) | |
| return false; | |
| while ((n = read(fd, buf, sizeof (buf) - 1)) < 0 && | |
| errno == EINTR); | |
| close(fd); | |
| if (n < 0) | |
| return false; | |
| buf[n] = '\0'; | |
| *val = strtoull(buf, NULL, 0); | |
| return true; | |
| } |