* Read the content of /proc/cpuinfo into a user-provided buffer. * Return the length of the data, or -1 on error. Does *not* * zero-terminate the content. Will not read more * than 'buffsize' bytes. */
| 93 | * than 'buffsize' bytes. |
| 94 | */ |
| 95 | static int |
| 96 | read_file(const char* pathname, char* buffer, size_t buffsize) |
| 97 | { |
| 98 | int fd, count; |
| 99 | |
| 100 | fd = open(pathname, O_RDONLY); |
| 101 | if (fd < 0) { |
| 102 | return -1; |
| 103 | } |
| 104 | count = 0; |
| 105 | while (count < (int)buffsize) { |
| 106 | int ret = read(fd, buffer + count, buffsize - count); |
| 107 | if (ret < 0) { |
| 108 | if (errno == EINTR) { |
| 109 | continue; |
| 110 | } |
| 111 | if (count == 0) { |
| 112 | count = -1; |
| 113 | } |
| 114 | break; |
| 115 | } |
| 116 | if (ret == 0) { |
| 117 | break; |
| 118 | } |
| 119 | count += ret; |
| 120 | } |
| 121 | close(fd); |
| 122 | return count; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Extract the content of a the first occurrence of a given field in |
no test coverage detected