91{
92 if (not m_rfile) {
93 B2ERROR("Trying to read from a closed file!");
94 return -1;
95 }
96 int br = std::fread(wrdbuf, sizeof(int), 1, m_rfile);
97 if (br <= 0) {
98 if (std::feof(m_rfile)) {
99 return 0;
100 }
101 B2ERROR("Error in getting the size: " << strerror(errno));
102 return br;
103 }
104
105 const int gcount = (wrdbuf[0] - 1);
106 if (gcount > len) {
107 B2ERROR("buffer too small! " << gcount << " < " << len);
108 return -1;
109 }
110
111 const int bcount = std::fread(&wrdbuf[1], sizeof(int), gcount, m_rfile);
112 if (bcount <= 0) {
113 if (std::feof(m_rfile)) {
114 return 0;
115 }
116 B2ERROR("Error in getting the data: " << strerror(errno));
117 return bcount;
118 }
119
120 B2ASSERT("Read buffer size != buffer size in data: " << bcount << " != " << gcount, bcount == gcount);
121 return (wrdbuf[0]);
122}