This class, derived from the C++ standard library class bsl::streambuf, is a mechanism that can be associated with an opened file descriptor, and, except for changing the locale, enables the caller to invoke all the standard bsl::streambuf operations on that file descriptor. Note that objects of this class are always in exactly one of the 5 modes outlined in the enum FdStreamBuf::FdStreamBufMode.
See bdls_fdstreambuf
| bdls::FdStreamBuf::FdStreamBuf |
( |
FilesystemUtil::FileDescriptor |
fileDescriptor, |
|
|
bool |
writableFlag, |
|
|
bool |
willCloseOnResetFlag = true, |
|
|
bool |
binaryModeFlag = false, |
|
|
bslma::Allocator * |
basicAllocator = 0 |
|
) |
| |
|
explicit |
Create a FdStreamBuf associated with the specified fileDescriptor that refers to an already opened file or device, and specify writableFlag which, if true, indicates that fileDescriptor is writable, otherwise it is not. The optionally specified willCloseOnResetFlag, if true, indicates that fileDescriptor is to be closed the next time this object is reset, cleared or destroyed, or if false the file descriptor is to be left open. Optionally specify a binaryModeFlag which is ignored on Unix; if false on Windows, it indicates that \ns are to be translated to and from \r\n sequences on the device. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. Note that if FilesystemUtil::k_INVALID_FD is passed to fileDescriptor, no file descriptor is to be associated with this object. Also note that the state of the fileDescriptor is unchanged by this call (i.e., there is no implicit seek).
| int_type bdls::FdStreamBuf::pbackfail |
( |
int_type |
c = traits_type::eof() | ) |
|
|
protected |
If the optionally specified c is not given, move the current input position back one character and return the character at that position. Otherwise specify a value for c other than traits_type::eof. If c is equal to the previous character in the read buffer, the behavior is the same as if eof() was passed. If c is not eof and is not equal to the previous character in the putback buffer push the character c is back into the input buffer, if possible. Return the backed up character on success and traits_type::eof() otherwise. If the input buffer is readonly, or gptr() is already at the beginning of the input buffer, this object enters INPUT_PUTBACK_MODE and c is stuffed back into the putback buffer. Note that only PBACK_BUF_SIZE characters can be backed up into the putback buffer, if this limit is exceeded, traits_type::eof() will be returned. Also note that this method is called by public methods sputbackc or sungetc in the base class, and only when simply decrementing the current position in the input buffer won't satisfy the request, either because c doesn't match the previously input character, or because the input position is already at the beginning of the input buffer.
| int bdls::FdStreamBuf::reset |
( |
FilesystemUtil::FileDescriptor |
fileDescriptor, |
|
|
bool |
writableFlag, |
|
|
bool |
willCloseOnResetFlag = true, |
|
|
bool |
binaryModeFlag = false |
|
) |
| |
|
inline |
Associate this object with the specified fileDescriptor, and record the state of the specified writableFlag which, if true, indicates that fileDescriptor is writable, otherwise it is not. Before making this association, if, prior to this call, willCloseOnReset is true, close any file descriptor previously associated with this object, otherwise leave it open but disassociate this object from it. The Optionally specified willCloseOnResetFlag which will set willCloseOnReset, which, if true, indicates that the specified file descriptor is to be closed when this object is cleared, reset, or destroyed, otherwise no action will be taken on fileDescriptor at that time. Optionally specify a binaryModeFlag, which is ignored on Unix; if false on Windows, it indicates that \ns internally are to be translated to and from \r\n sequences on the device; on Unix or if binaryModeFlag is true no such translation is to occur. Return 0 on success, and a non-zero value otherwise. Note that if FilesystemUtil::k_INVALID_FD is passed as fileDescriptor, no file descriptor is to be associated with this object. Also note that the state of the fileDescriptor is unchanged by this call, there is no implicit seek.
| pos_type bdls::FdStreamBuf::seekoff |
( |
off_type |
offset, |
|
|
bsl::ios_base::seekdir |
whence, |
|
|
bsl::ios_base::openmode |
mode = bsl::ios_base::in|bsl::ios_base::out |
|
) |
| |
|
protected |
Set the file pointer associated with the file descriptor according to the specified offset and whence:
- If 'whence' is 'bsl::ios_base::beg', set the pointer to 'offset' bytes from the beginning of the file.
- If 'whence' is 'bsl::ios_base::cur', advance the pointer by 'offset' bytes
- If 'whence' is 'bsl::ios_base::end', set the pointer to 'offset' bytes beyond the end of the file.
Optionally specify mode, which is ignored. Return the new location of the file position, in bytes from the beginning of the file, on success, and -1 otherwise. The behavior is undefined unless the file descriptor is on a device capable of seeking. Note that seeking does not change the size of the file if the pointer advances beyond the end of the file; instead, the next write at the pointer will increase the file size. Also note that seeks are always in terms of bytes on the device, meaning that in Windows text mode, seeking past a \n perceived by the caller will count as 2 bytes since it has to seek over a \r\n sequence on the device.