• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 Intel Corporation
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "intel_perf_common.h"
7 
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 
13 bool
read_file_uint64(const char * file,uint64_t * val)14 read_file_uint64(const char *file, uint64_t *val)
15 {
16     char buf[32];
17     int fd, n;
18 
19     fd = open(file, 0);
20     if (fd < 0)
21        return false;
22     while ((n = read(fd, buf, sizeof (buf) - 1)) < 0 &&
23            errno == EINTR);
24     close(fd);
25     if (n < 0)
26        return false;
27 
28     buf[n] = '\0';
29     *val = strtoull(buf, NULL, 0);
30 
31     return true;
32 }
33