Add BasicCStringRef to represent a null-termated string (#100)

and use it instead of BasicStringRef in cases that assume that the
string is null-terminated such as POSIX function and format string
parser.
This commit is contained in:
vitaut
2015-06-26 07:43:54 -07:00
parent 88c7c20102
commit 438bd9b0e6
7 changed files with 141 additions and 83 deletions

View File

@@ -83,7 +83,8 @@ fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT {
fmt::report_system_error(errno, "cannot close file");
}
fmt::BufferedFile::BufferedFile(fmt::StringRef filename, fmt::StringRef mode) {
fmt::BufferedFile::BufferedFile(
fmt::CStringRef filename, fmt::CStringRef mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0);
if (!file_)
throw SystemError(errno, "cannot open file {}", filename);
@@ -108,7 +109,7 @@ int fmt::BufferedFile::fileno() const {
return fd;
}
fmt::File::File(fmt::StringRef path, int oflag) {
fmt::File::File(fmt::CStringRef path, int oflag) {
int mode = S_IRUSR | S_IWUSR;
#if defined(_WIN32) && !defined(__MINGW32__)
fd_ = -1;