8242485: Null _file checking in fileStream::flush()
Reviewed-by: dholmes, ysuenaga, iklam
This commit is contained in:
parent
23709c830e
commit
919027a90e
src/hotspot/share/utilities
@ -533,8 +533,8 @@ void fileStream::write(const char* s, size_t len) {
|
||||
if (_file != NULL) {
|
||||
// Make an unused local variable to avoid warning from gcc compiler.
|
||||
size_t count = fwrite(s, 1, len, _file);
|
||||
update_position(s, len);
|
||||
}
|
||||
update_position(s, len);
|
||||
}
|
||||
|
||||
long fileStream::fileSize() {
|
||||
@ -551,9 +551,12 @@ long fileStream::fileSize() {
|
||||
}
|
||||
|
||||
char* fileStream::readln(char *data, int count ) {
|
||||
char * ret = ::fgets(data, count, _file);
|
||||
//Get rid of annoying \n char
|
||||
data[::strlen(data)-1] = '\0';
|
||||
char * ret = NULL;
|
||||
if (_file != NULL) {
|
||||
ret = ::fgets(data, count, _file);
|
||||
//Get rid of annoying \n char
|
||||
data[::strlen(data)-1] = '\0';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -565,15 +568,17 @@ fileStream::~fileStream() {
|
||||
}
|
||||
|
||||
void fileStream::flush() {
|
||||
fflush(_file);
|
||||
if (_file != NULL) {
|
||||
fflush(_file);
|
||||
}
|
||||
}
|
||||
|
||||
void fdStream::write(const char* s, size_t len) {
|
||||
if (_fd != -1) {
|
||||
// Make an unused local variable to avoid warning from gcc compiler.
|
||||
size_t count = ::write(_fd, s, (int)len);
|
||||
update_position(s, len);
|
||||
}
|
||||
update_position(s, len);
|
||||
}
|
||||
|
||||
defaultStream* defaultStream::instance = NULL;
|
||||
|
@ -230,11 +230,11 @@ class fileStream : public outputStream {
|
||||
~fileStream();
|
||||
bool is_open() const { return _file != NULL; }
|
||||
virtual void write(const char* c, size_t len);
|
||||
size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
|
||||
size_t read(void *data, size_t size, size_t count) { return _file != NULL ? ::fread(data, size, count, _file) : 0; }
|
||||
char* readln(char *data, int count);
|
||||
int eof() { return feof(_file); }
|
||||
int eof() { return _file != NULL ? feof(_file) : -1; }
|
||||
long fileSize();
|
||||
void rewind() { ::rewind(_file); }
|
||||
void rewind() { if (_file != NULL) ::rewind(_file); }
|
||||
void flush();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user