aboutsummaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-11-24 17:28:19 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-11-24 17:46:08 +0000
commit4e640edf7642cbc7bd2cc5d308b95cb14f8e236a (patch)
treef5180878a23c12e9ddbb47008f9d9464af08b0b0 /fastos
parent81affee11ad6a020b3f6a7381c6e6cc3f7cb5123 (diff)
Use c++11 strings instead of old c-style manual string manipulation.
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/vespa/fastos/file.cpp22
-rw-r--r--fastos/src/vespa/fastos/file.h6
-rw-r--r--fastos/src/vespa/fastos/process.cpp9
-rw-r--r--fastos/src/vespa/fastos/process.h10
-rw-r--r--fastos/src/vespa/fastos/unix_file.cpp8
5 files changed, 19 insertions, 36 deletions
diff --git a/fastos/src/vespa/fastos/file.cpp b/fastos/src/vespa/fastos/file.cpp
index 0764c9b1b66..1382aef7386 100644
--- a/fastos/src/vespa/fastos/file.cpp
+++ b/fastos/src/vespa/fastos/file.cpp
@@ -39,7 +39,7 @@ static const size_t MAX_WRITE_CHUNK_SIZE = 0x4000000; // 64 MB
FastOS_FileInterface::FastOS_FileInterface(const char *filename)
: _fAdviseOptions(_defaultFAdviseOptions),
_writeChunkSize(MAX_WRITE_CHUNK_SIZE),
- _filename(nullptr),
+ _filename(),
_openFlags(0),
_directIOEnabled(false),
_syncWritesEnabled(false)
@@ -49,10 +49,7 @@ FastOS_FileInterface::FastOS_FileInterface(const char *filename)
}
-FastOS_FileInterface::~FastOS_FileInterface()
-{
- free(_filename);
-}
+FastOS_FileInterface::~FastOS_FileInterface() = default;
bool FastOS_FileInterface::InitializeClass ()
{
@@ -358,18 +355,14 @@ FastOS_FileInterface::MakeDirIfNotPresentOrExit(const char *name)
void
FastOS_FileInterface::SetFileName(const char *filename)
{
- if (_filename != nullptr) {
- free(_filename);
- }
-
- _filename = strdup(filename);
+ _filename = filename;
}
const char *
FastOS_FileInterface::GetFileName() const
{
- return (_filename != nullptr) ? _filename : "";
+ return _filename.c_str();
}
@@ -502,11 +495,8 @@ void FastOS_FileInterface::dropFromCache() const
}
FastOS_DirectoryScanInterface::FastOS_DirectoryScanInterface(const char *path)
- : _searchPath(strdup(path))
+ : _searchPath(path)
{
}
-FastOS_DirectoryScanInterface::~FastOS_DirectoryScanInterface()
-{
- free(_searchPath);
-}
+FastOS_DirectoryScanInterface::~FastOS_DirectoryScanInterface() = default;
diff --git a/fastos/src/vespa/fastos/file.h b/fastos/src/vespa/fastos/file.h
index 40b33e49b35..2d83a1766f0 100644
--- a/fastos/src/vespa/fastos/file.h
+++ b/fastos/src/vespa/fastos/file.h
@@ -88,7 +88,7 @@ private:
void WriteBufInternal(const void *buffer, size_t length);
protected:
- char *_filename;
+ std::string _filename;
unsigned int _openFlags;
bool _directIOEnabled;
bool _syncWritesEnabled;
@@ -726,7 +726,7 @@ private:
FastOS_DirectoryScanInterface& operator= (const FastOS_DirectoryScanInterface&);
protected:
- char *_searchPath;
+ std::string _searchPath;
public:
@@ -750,7 +750,7 @@ public:
* This is an internal copy of the path specified in the constructor.
* @return Search path string.
*/
- const char *GetSearchPath () { return _searchPath; }
+ const char *GetSearchPath () { return _searchPath.c_str(); }
/**
* Read the next entry in the directory scan. Failure indicates
diff --git a/fastos/src/vespa/fastos/process.cpp b/fastos/src/vespa/fastos/process.cpp
index 29c53fe9326..332d82c6aad 100644
--- a/fastos/src/vespa/fastos/process.cpp
+++ b/fastos/src/vespa/fastos/process.cpp
@@ -1,14 +1,13 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "process.h"
-#include <cstring>
FastOS_ProcessInterface::FastOS_ProcessInterface (const char *cmdLine,
bool pipeStdin,
FastOS_ProcessRedirectListener *stdoutListener,
FastOS_ProcessRedirectListener *stderrListener,
int bufferSize) :
- _cmdLine(nullptr),
+ _cmdLine(cmdLine),
_pipeStdin(pipeStdin),
_stdoutListener(stdoutListener),
_stderrListener(stderrListener),
@@ -16,10 +15,6 @@ FastOS_ProcessInterface::FastOS_ProcessInterface (const char *cmdLine,
_next(nullptr),
_prev(nullptr)
{
- _cmdLine = strdup(cmdLine);
}
-FastOS_ProcessInterface::~FastOS_ProcessInterface ()
-{
- free (_cmdLine);
-}
+FastOS_ProcessInterface::~FastOS_ProcessInterface () = default;
diff --git a/fastos/src/vespa/fastos/process.h b/fastos/src/vespa/fastos/process.h
index 99f045d2f56..25d5224817a 100644
--- a/fastos/src/vespa/fastos/process.h
+++ b/fastos/src/vespa/fastos/process.h
@@ -12,6 +12,7 @@
#include "types.h"
#include <cstddef>
+#include <string>
/**
* This class serves as a sink for redirected (piped) output from
@@ -52,8 +53,8 @@ private:
protected:
- char *_cmdLine;
- bool _pipeStdin;
+ std::string _cmdLine;
+ bool _pipeStdin;
FastOS_ProcessRedirectListener *_stdoutListener;
FastOS_ProcessRedirectListener *_stderrListener;
@@ -179,10 +180,7 @@ public:
* Get command line string.
* @return Command line string
*/
- const char *GetCommandLine ()
- {
- return _cmdLine;
- }
+ const char *GetCommandLine () const { return _cmdLine.c_str(); }
};
#include <vespa/fastos/unix_process.h>
diff --git a/fastos/src/vespa/fastos/unix_file.cpp b/fastos/src/vespa/fastos/unix_file.cpp
index 2ef8c2f55ff..0fee991cac4 100644
--- a/fastos/src/vespa/fastos/unix_file.cpp
+++ b/fastos/src/vespa/fastos/unix_file.cpp
@@ -258,7 +258,7 @@ FastOS_UNIX_File::Open(unsigned int openFlags, const char *filename)
}
unsigned int accessFlags = CalcAccessFlags(openFlags);
- _filedes = open(_filename, accessFlags, 0664);
+ _filedes = open(_filename.c_str(), accessFlags, 0664);
rc = (_filedes != -1);
@@ -386,10 +386,10 @@ FastOS_UNIX_File::Delete(const char *name)
bool
FastOS_UNIX_File::Delete(void)
{
- assert(!IsOpened());
- assert(_filename != nullptr);
+ assert( ! IsOpened());
+ assert( ! _filename.empty());
- return (unlink(_filename) == 0);
+ return (unlink(_filename.c_str()) == 0);
}
bool FastOS_UNIX_File::Rename (const char *currentFileName, const char *newFileName)