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
476 int windowsWriteText(
const char *buffer,
int numChars);
525 bool willCloseOnResetFlag =
true,
526 bool binaryModeFlag =
false);
553 int read(
char *buffer,
int numBytes);
562 int write(
const char *buffer,
int numBytes);
593 void *
mmap(bsl::streamoff offset, bsl::streamoff length);
601 void unmap(
void *mappedMemory, bsl::streamoff length);
627 bsl::streamoff
getOffset(
char *first,
char *last)
const;
675 enum { k_PBACK_BUF_SIZE = 8 };
677 enum FdStreamBufMode {
683 e_INPUT_PUTBACK_MODE = 2,
708 FdStreamBufMode d_mode;
710 bool d_dynamicBufferFlag;
716 char d_pBackBuf[k_PBACK_BUF_SIZE];
732 char *d_savedEback_p;
734 char *d_savedEgptr_p;
743 bsl::streamoff d_mmapLen;
756 void exitPutbackMode();
764 int switchToInputMode();
776 int exitInputMode(
bool correctSeek);
784 int switchToOutputMode();
813 int allocateBuffer(
char *buffer,
int numBytes);
820 int allocateBuffer();
826 void deallocateBuffer();
839 pos_type seekReturn(pos_type offset);
926 bsl::ios_base::seekdir whence,
927 bsl::ios_base::openmode mode =
bsl::ios_base::in |
bsl::ios_base::out)
939 bsl::ios_base::openmode mode =
bsl::ios_base::in |
bsl::ios_base::out)
1011 bool willCloseOnResetFlag = true,
1012 bool binaryModeFlag = false,
1013 bslma::Allocator *basicAllocator = 0);
1046 bool willCloseOnResetFlag = true,
1047 bool binaryModeFlag = false);
1101 d_willCloseOnResetFlag =
false;
1114 d_willCloseOnResetFlag = booleanValue;
1123 return d_openModeFlags & bsl::ios_base::binary
1125 : bsl::count(first, last,
'\n') + last - first;
1131#if defined(BSLS_PLATFORM_OS_UNIX)
1136 return (d_openModeFlags & bsl::ios_base::binary) != 0;
1143 return d_openedFlag;
1149 return d_regularFileFlag;
1155 return (
int) d_openModeFlags;
1161 return d_willCloseOnResetFlag;
1165FilesystemUtil::FileDescriptor
1177void FdStreamBuf::exitPutbackMode()
1179 setg(d_savedEback_p, d_savedGptr_p, d_savedEgptr_p);
1180 d_mode = e_INPUT_MODE;
1186FdStreamBuf::pos_type
1187FdStreamBuf::seekReturn(pos_type offset)
1189 if (e_INPUT_MODE == d_mode || e_INPUT_PUTBACK_MODE == d_mode) {
1190 if (0 != exitInputMode(
false)) {
1193 return (pos_type) - 1;
1199 d_mode = e_NULL_MODE;
1208 bool willCloseOnResetFlag,
1209 bool binaryModeFlag)
1211 bool ok = 0 == flush();
1218 willCloseOnResetFlag,
Definition bdls_fdstreambuf.h:427
FilesystemUtil::FileDescriptor fileDescriptor() const
Definition bdls_fdstreambuf.h:1166
static bsl::size_t pageSize()
Return the operating system's page size.
Definition bdls_fdstreambuf.h:1092
bool isInBinaryMode() const
Definition bdls_fdstreambuf.h:1129
int openMode() const
Definition bdls_fdstreambuf.h:1153
void setWillCloseOnReset(bool booleanValue)
Definition bdls_fdstreambuf.h:1112
int reset(FilesystemUtil::FileDescriptor fileDescriptor, bool writableFlag, bool willCloseOnResetFlag=true, bool binaryModeFlag=false)
bool isRegularFile() const
Definition bdls_fdstreambuf.h:1147
~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:1099
void * mmap(bsl::streamoff offset, bsl::streamoff length)
bsl::streamoff getOffset(char *first, char *last) const
Definition bdls_fdstreambuf.h:1119
int clear()
Definition bdls_fdstreambuf.h:1106
FdStreamBuf_FileHandler()
bsl::streampos seek(bsl::streamoff offset, FilesystemUtil::Whence dir)
int read(char *buffer, int numBytes)
bool willCloseOnReset() const
Definition bdls_fdstreambuf.h:1159
bool isOpened() const
Definition bdls_fdstreambuf.h:1141
Definition bdls_fdstreambuf.h:671
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:1252
int_type pbackfail(int_type c=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
int sync() BSLS_KEYWORD_OVERRIDE
int clear()
Definition bdls_fdstreambuf.h:1233
bool isOpened() const
Definition bdls_fdstreambuf.h:1246
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:1206
bsl::streamsize xsgetn(char *buffer, bsl::streamsize numBytes) BSLS_KEYWORD_OVERRIDE
FilesystemUtil::FileDescriptor fileDescriptor() const
Definition bdls_fdstreambuf.h:1240
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:1226
Definition bslma_allocator.h:545
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition bdls_fdstreambuf.h:412
Definition bdlat_valuetypefunctions.h:939
Definition baljsn_encoder_testtypes.h:76
Definition bdls_filesystemutil.h:364
Whence
Definition bdls_filesystemutil.h:413
static const FileDescriptor k_INVALID_FD
Definition bdls_filesystemutil.h:484
static int getIntRelaxed(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1536