* @brief read the first line of the trace without changing the state of the * reader * * @param reader * @param in_buf * @param in_buf_size * @return int */
| 49 | * @return int |
| 50 | */ |
| 51 | static int read_first_line(const reader_t *reader, char *in_buf, |
| 52 | const size_t in_buf_size) { |
| 53 | FILE *ifile = fopen(reader->trace_path, "r"); |
| 54 | char *buf = NULL; |
| 55 | size_t n = 0; |
| 56 | size_t read_size = getline(&buf, &n, ifile); |
| 57 | |
| 58 | if (in_buf_size < read_size) { |
| 59 | WARN( |
| 60 | "in_buf_size %zu is smaller than the first line size %zu, " |
| 61 | "the first line will be truncated", |
| 62 | in_buf_size, read_size); |
| 63 | } |
| 64 | |
| 65 | read_size = read_size > in_buf_size ? in_buf_size : read_size; |
| 66 | |
| 67 | /* + 1 to copy the null terminator */ |
| 68 | memcpy(in_buf, buf, read_size + 1); |
| 69 | |
| 70 | fclose(ifile); |
| 71 | free(buf); |
| 72 | |
| 73 | return read_size; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @brief detect delimiter in the csv trace |
no outgoing calls
no test coverage detected