8#ifndef INCLUDED_BDLS_FDSTREAMBUF
9#define INCLUDED_BDLS_FDSTREAMBUF
388#include <bdlscm_version.h>
401#include <bsl_algorithm.h>
402#include <bsl_cstddef.h>
403#include <bsl_cstring.h>
405#include <bsl_iosfwd.h>
406#include <bsl_locale.h>
407#include <bsl_streambuf.h>
431 static bsls::AtomicOperations::AtomicTypes::Int
436 FilesystemUtil::FileDescriptor
445 bool d_regularFileFlag;
449 bsl::ios_base::openmode
453 bool d_willCloseOnResetFlag;
461 bool d_peekBufferFlag;
468#ifdef BSLS_PLATFORM_OS_WINDOWS
475 int windowsWriteText(
const char *buffer,
int numChars);
522 bool willCloseOnResetFlag =
true,
523 bool binaryModeFlag =
false);
546 int read(
char *buffer,
int numBytes);
553 int write(
const char *buffer,
int numBytes);
581 void *
mmap(bsl::streamoff offset, bsl::streamoff length);
588 void unmap(
void *mappedMemory, bsl::streamoff length);
613 bsl::streamoff
getOffset(
char *first,
char *last)
const;
657 enum { k_PBACK_BUF_SIZE = 8 };
659 enum FdStreamBufMode {
665 e_INPUT_PUTBACK_MODE = 2,
690 FdStreamBufMode d_mode;
692 bool d_dynamicBufferFlag;
698 char d_pBackBuf[k_PBACK_BUF_SIZE];
714 char *d_savedEback_p;
716 char *d_savedEgptr_p;
725 bsl::streamoff d_mmapLen;
737 void exitPutbackMode();
744 int switchToInputMode();
754 int exitInputMode(
bool correctSeek);
761 int switchToOutputMode();
786 int allocateBuffer(
char *buffer,
int numBytes);
792 int allocateBuffer();
797 void deallocateBuffer();
810 pos_type seekReturn(pos_type offset);
891 bsl::ios_base::seekdir whence,
892 bsl::ios_base::openmode mode =
bsl::ios_base::in |
bsl::ios_base::out)
904 bsl::ios_base::openmode mode =
bsl::ios_base::in |
bsl::ios_base::out)
969 bool willCloseOnResetFlag = true,
970 bool binaryModeFlag = false,
971 bslma::Allocator *basicAllocator = 0);
1001 bool willCloseOnResetFlag = true,
1002 bool binaryModeFlag = false);
1054 d_willCloseOnResetFlag =
false;
1067 d_willCloseOnResetFlag = booleanValue;
1076 return d_openModeFlags & bsl::ios_base::binary
1078 : bsl::count(first, last,
'\n') + last - first;
1084#if defined(BSLS_PLATFORM_OS_UNIX)
1089 return (d_openModeFlags & bsl::ios_base::binary) != 0;
1096 return d_openedFlag;
1102 return d_regularFileFlag;
1108 return (
int) d_openModeFlags;
1114 return d_willCloseOnResetFlag;
1118FilesystemUtil::FileDescriptor
1130void FdStreamBuf::exitPutbackMode()
1132 setg(d_savedEback_p, d_savedGptr_p, d_savedEgptr_p);
1133 d_mode = e_INPUT_MODE;
1139FdStreamBuf::pos_type
1140FdStreamBuf::seekReturn(pos_type offset)
1142 if (e_INPUT_MODE == d_mode || e_INPUT_PUTBACK_MODE == d_mode) {
1143 if (0 != exitInputMode(
false)) {
1146 return (pos_type) - 1;
1152 d_mode = e_NULL_MODE;
1161 bool willCloseOnResetFlag,
1162 bool binaryModeFlag)
1164 bool ok = 0 == flush();
1171 willCloseOnResetFlag,
Definition bdls_fdstreambuf.h:427
FilesystemUtil::FileDescriptor fileDescriptor() const
Definition bdls_fdstreambuf.h:1119
static bsl::size_t pageSize()
Return the operating system's page size.
Definition bdls_fdstreambuf.h:1045
bool isInBinaryMode() const
Definition bdls_fdstreambuf.h:1082
int openMode() const
Definition bdls_fdstreambuf.h:1106
void setWillCloseOnReset(bool booleanValue)
Definition bdls_fdstreambuf.h:1065
int reset(FilesystemUtil::FileDescriptor fileDescriptor, bool writableFlag, bool willCloseOnResetFlag=true, bool binaryModeFlag=false)
bool isRegularFile() const
Definition bdls_fdstreambuf.h:1100
~FdStreamBuf_FileHandler()
int write(const char *buffer, int numBytes)
void unmap(void *mappedMemory, bsl::streamoff length)
bsl::streamoff fileSize() const
void release()
Definition bdls_fdstreambuf.h:1052
void * mmap(bsl::streamoff offset, bsl::streamoff length)
bsl::streamoff getOffset(char *first, char *last) const
Definition bdls_fdstreambuf.h:1072
int clear()
Definition bdls_fdstreambuf.h:1059
FdStreamBuf_FileHandler()
bsl::streampos seek(bsl::streamoff offset, FilesystemUtil::Whence dir)
int read(char *buffer, int numBytes)
bool willCloseOnReset() const
Definition bdls_fdstreambuf.h:1112
bool isOpened() const
Definition bdls_fdstreambuf.h:1094
Definition bdls_fdstreambuf.h:653
int_type overflow(int_type c=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
bsl::streamsize showmanyc() BSLS_KEYWORD_OVERRIDE
bsl::streamsize xsputn(const char *buffer, bsl::streamsize numBytes) BSLS_KEYWORD_OVERRIDE
bool willCloseOnReset() const
Definition bdls_fdstreambuf.h:1205
int_type pbackfail(int_type c=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
int sync() BSLS_KEYWORD_OVERRIDE
int clear()
Definition bdls_fdstreambuf.h:1186
bool isOpened() const
Definition bdls_fdstreambuf.h:1199
pos_type seekpos(pos_type offset, bsl::ios_base::openmode mode=bsl::ios_base::in|bsl::ios_base::out) BSLS_KEYWORD_OVERRIDE
int_type underflow() BSLS_KEYWORD_OVERRIDE
void imbue(const bsl::locale &locale) BSLS_KEYWORD_OVERRIDE
int reset(FilesystemUtil::FileDescriptor fileDescriptor, bool writableFlag, bool willCloseOnResetFlag=true, bool binaryModeFlag=false)
Definition bdls_fdstreambuf.h:1159
bsl::streamsize xsgetn(char *buffer, bsl::streamsize numBytes) BSLS_KEYWORD_OVERRIDE
FilesystemUtil::FileDescriptor fileDescriptor() const
Definition bdls_fdstreambuf.h:1193
FdStreamBuf * setbuf(char_type *buffer, bsl::streamsize numBytes) BSLS_KEYWORD_OVERRIDE
pos_type seekoff(off_type offset, bsl::ios_base::seekdir whence, bsl::ios_base::openmode mode=bsl::ios_base::in|bsl::ios_base::out) BSLS_KEYWORD_OVERRIDE
void release()
Definition bdls_fdstreambuf.h:1179
Definition bslma_allocator.h:457
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bdls_fdstreambuf.h:412
Definition bdlb_printmethods.h:283
Definition balxml_encoderoptions.h:68
Definition bdls_filesystemutil.h:362
Whence
Definition bdls_filesystemutil.h:411
static const FileDescriptor k_INVALID_FD
Definition bdls_filesystemutil.h:482
static int getIntRelaxed(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1534