Handout
This commit is contained in:
24
libsys/iostream.h
Normal file
24
libsys/iostream.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "outputstream.h"
|
||||
#include "stub.h"
|
||||
|
||||
class IOStream : public OutputStream {
|
||||
private:
|
||||
IOStream(IOStream ©); // no copy
|
||||
int fd;
|
||||
|
||||
public:
|
||||
explicit IOStream(int sysfd = 0) : fd(sysfd) {}
|
||||
|
||||
~IOStream() {
|
||||
if (pos > 0) {
|
||||
sys_write(fd, buffer, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void flush() override {
|
||||
sys_write(fd, buffer, pos);
|
||||
pos = 0;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user