在哪里可以找到对函数 write 的引用?
Where can I find a reference to the function write?
我有以下用于定义 streambuf class 的代码。我必须使它适应我的需要。在此之前,我必须了解代码的实际工作原理。谁能告诉我在哪里可以找到对 flushBuffer.write 函数的引用。它需要 3 个参数和 returns 一个 int。 std::streambuf没有这样的会员...
//code taken from: The C++ Standard Library Second Edition, Nicolai M. Josuttis, p. 837
class Outbuf_buffered_orig : public std::streambuf {
protected:
static const int bufferSize = 10; // size of data buffer
char buffer[bufferSize]; // data buffer
public:
// constructor
// - initialize data buffer
// - one character less to let the bufferSizeth character cause a call of overflow()
Outbuf_buffered_orig() {
setp (buffer, buffer+(bufferSize-1));
}
// destructor
// - flush data buffer
virtual ~Outbuf_buffered_orig() {
sync();
}
protected:
// flush the characters in the buffer
int flushBuffer () {
int num = pptr()-pbase();
if (write (1, buffer, num) != num) {
return EOF;
}
pbump (-num); // reset put pointer accordingly
return num;
}
// buffer full
// - write c and all previous characters
virtual int_type overflow (int_type c) {
if (c != EOF) {
// insert character into the buffer
*pptr() = c;
pbump(1);
}
// flush the buffer
if (flushBuffer() == EOF) {
// ERROR
return EOF;
}
return c;
}
// synchronize data with file/destination
// - flush the data in the buffer
virtual int sync () {
if (flushBuffer() == EOF) {
// ERROR
return -1;
}
return 0;
}
}; //Outbuf_buffered
Can anyone tell me where I can find a reference to the write function
这是 Linux' ssize_t write(int fd, const void *buf, size_t count)
,在 <unistd.h>
中定义。
有关详细信息,请参阅 man 2 write
。
注意:write(1, ...)
写入文件描述符 #1:标准输出。
我有以下用于定义 streambuf class 的代码。我必须使它适应我的需要。在此之前,我必须了解代码的实际工作原理。谁能告诉我在哪里可以找到对 flushBuffer.write 函数的引用。它需要 3 个参数和 returns 一个 int。 std::streambuf没有这样的会员...
//code taken from: The C++ Standard Library Second Edition, Nicolai M. Josuttis, p. 837
class Outbuf_buffered_orig : public std::streambuf {
protected:
static const int bufferSize = 10; // size of data buffer
char buffer[bufferSize]; // data buffer
public:
// constructor
// - initialize data buffer
// - one character less to let the bufferSizeth character cause a call of overflow()
Outbuf_buffered_orig() {
setp (buffer, buffer+(bufferSize-1));
}
// destructor
// - flush data buffer
virtual ~Outbuf_buffered_orig() {
sync();
}
protected:
// flush the characters in the buffer
int flushBuffer () {
int num = pptr()-pbase();
if (write (1, buffer, num) != num) {
return EOF;
}
pbump (-num); // reset put pointer accordingly
return num;
}
// buffer full
// - write c and all previous characters
virtual int_type overflow (int_type c) {
if (c != EOF) {
// insert character into the buffer
*pptr() = c;
pbump(1);
}
// flush the buffer
if (flushBuffer() == EOF) {
// ERROR
return EOF;
}
return c;
}
// synchronize data with file/destination
// - flush the data in the buffer
virtual int sync () {
if (flushBuffer() == EOF) {
// ERROR
return -1;
}
return 0;
}
}; //Outbuf_buffered
Can anyone tell me where I can find a reference to the write function
这是 Linux' ssize_t write(int fd, const void *buf, size_t count)
,在 <unistd.h>
中定义。
有关详细信息,请参阅 man 2 write
。
注意:write(1, ...)
写入文件描述符 #1:标准输出。