equal
deleted
inserted
replaced
1289 result = true; |
1289 result = true; |
1290 } |
1290 } |
1291 } |
1291 } |
1292 return result; |
1292 return result; |
1293 } |
1293 } |
|
1294 |
|
1295 // Read file line by line, if line is longer than bsize, |
|
1296 // skip rest of line. |
|
1297 int os::get_line_chars(int fd, char* buf, const size_t bsize){ |
|
1298 size_t sz, i = 0; |
|
1299 |
|
1300 // read until EOF, EOL or buf is full |
|
1301 while ((sz = (int) read(fd, &buf[i], 1)) == 1 && i < (bsize-1) && buf[i] != '\n') { |
|
1302 ++i; |
|
1303 } |
|
1304 |
|
1305 if (buf[i] == '\n') { |
|
1306 // EOL reached so ignore EOL character and return |
|
1307 |
|
1308 buf[i] = 0; |
|
1309 return (int) i; |
|
1310 } |
|
1311 |
|
1312 buf[i+1] = 0; |
|
1313 |
|
1314 if (sz != 1) { |
|
1315 // EOF reached. if we read chars before EOF return them and |
|
1316 // return EOF on next call otherwise return EOF |
|
1317 |
|
1318 return (i == 0) ? -1 : (int) i; |
|
1319 } |
|
1320 |
|
1321 // line is longer than size of buf, skip to EOL |
|
1322 int ch; |
|
1323 while (read(fd, &ch, 1) == 1 && ch != '\n') { |
|
1324 // Do nothing |
|
1325 } |
|
1326 |
|
1327 // return initial part of line that fits in buf. |
|
1328 // If we reached EOF, it will be returned on next call. |
|
1329 |
|
1330 return (int) i; |
|
1331 } |