MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / read_first_line

Function read_first_line

libCacheSim/traceReader/generalReader/csv.c:51–74  ·  view source on GitHub ↗

* @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 */

Source from the content-addressed store, hash-verified

49 * @return int
50 */
51static 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

Callers 2

csv_detect_delimiterFunction · 0.85
csv_detect_headerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected