src/share/vm/runtime/os.cpp

Print this page
rev 2100 : 7017193 Small memory leak in get_stack_bounds // os::create_stack_guard_pages

*** 1290,1294 **** --- 1290,1325 ---- result = true; } } return result; } + + //Read file line by line, if line is longer than bsize, + //skip rest of line. + int os::get_line_chars(int fd, char* buf, size_t bsize){ + unsigned int sz,i = 0; + + while( (sz=read(fd, &buf[i], 1)) == 1 && i < (bsize-1) && buf[i] != '\n' ) { + ++i; + } + + // whole line was read, kill eol char and return + if (buf[i] == '\n'){ + buf[i] = 0; + return i-1; + } + + buf[i+1] = 0; + + // EOF reached. if we have characters in buf return + // partially read line and delay eof to next call + if (sz != 1) { + return (i == 0) ? -1 : i; + } + + // line is longer than bsize, skip to EOL + int ch; + while( read(fd, &ch, 1) == 1 && ch != '\n' ); + + // ignore eof, will catch it next time + return i; + } \ No newline at end of file