diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-21 08:30:29 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-21 11:17:22 +0200 |
commit | eecc113e6f6e51e5e37059235c1069dc9c4c1cc8 (patch) | |
tree | 89000ed98e33d2b83d893908484de2b78c6b729d /sal | |
parent | 9f5e5ea0011a8f04fbfc242a199630ab1fbf8c0d (diff) |
rtl_String->OString in sal
Change-Id: I259c0dbe56fad2292f5ac0dc8e8f1047ead343c3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134699
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/file.cxx | 42 | ||||
-rw-r--r-- | sal/osl/unx/file_impl.hxx | 3 | ||||
-rw-r--r-- | sal/osl/unx/uunxapi.cxx | 12 | ||||
-rw-r--r-- | sal/osl/unx/uunxapi.hxx | 4 |
4 files changed, 30 insertions, 31 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index d8396f6279b6..cbf6e4fa57b6 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -19,6 +19,7 @@ #include <config_features.h> #include <o3tl/safeint.hxx> +#include <o3tl/string_view.hxx> #include <o3tl/typed_flags_set.hxx> #include <sal/log.hxx> #include <osl/diagnose.h> @@ -81,7 +82,7 @@ namespace { struct FileHandle_Impl { pthread_mutex_t m_mutex; - rtl_String * m_strFilePath; /*< holds native file path */ + OString m_strFilePath; /*< holds native file path */ int m_fd; enum Kind @@ -108,7 +109,7 @@ struct FileHandle_Impl rtl_String* m_memstreambuf; /*< used for in-memory streams */ #endif - explicit FileHandle_Impl(int fd, Kind kind = KIND_FD, char const * path = "<anon>"); + explicit FileHandle_Impl(int fd, Kind kind = KIND_FD, OString path = "<anon>"); ~FileHandle_Impl(); static void* operator new (size_t n); @@ -184,8 +185,8 @@ FileHandle_Impl::Guard::~Guard() (void) pthread_mutex_unlock(m_mutex); } -FileHandle_Impl::FileHandle_Impl(int fd, enum Kind kind, char const * path) - : m_strFilePath(nullptr), +FileHandle_Impl::FileHandle_Impl(int fd, enum Kind kind, OString path) + : m_strFilePath(std::move(path)), m_fd (fd), m_kind (kind), m_state (State::Seekable | State::Readable), @@ -198,7 +199,6 @@ FileHandle_Impl::FileHandle_Impl(int fd, enum Kind kind, char const * path) m_buffer (nullptr) { (void) pthread_mutex_init(&m_mutex, nullptr); - rtl_string_newFromStr(&m_strFilePath, path); if (m_kind == KIND_FD) { size_t const pagesize = getpagesize(); @@ -220,8 +220,6 @@ FileHandle_Impl::~FileHandle_Impl() m_buffer = nullptr; } - rtl_string_release(m_strFilePath); - m_strFilePath = nullptr; (void) pthread_mutex_destroy(&m_mutex); // ignoring EBUSY ... } @@ -752,7 +750,7 @@ oslFileHandle osl::detail::createFileHandleFromFD(int fd) return static_cast<oslFileHandle>(pImpl); } -static int osl_file_adjustLockFlags(const char *path, int flags) +static int osl_file_adjustLockFlags(const OString& path, int flags) { #ifdef MACOSX /* @@ -763,7 +761,7 @@ static int osl_file_adjustLockFlags(const char *path, int flags) * for the filesystem name. */ struct statfs s; - if(statfs(path, &s) >= 0) + if(statfs(path.getStr(), &s) >= 0) { if(strncmp("afpfs", s.f_fstypename, 5) == 0) { @@ -814,7 +812,7 @@ namespace { static oslFileError openMemoryAsFile(const OString &rData, oslFileHandle *pHandle, - const char *path) + const OString& path) { const char *address = rData.getStr(); size_t size = rData.getLength(); @@ -889,7 +887,7 @@ private: #endif -oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, +oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle, sal_uInt32 uFlags, mode_t mode) { oslFileError eRet; @@ -898,16 +896,16 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, /* Opening a file from /assets read-only means * we should mmap it from the .apk file */ - if (strncmp(cpFilePath, "/assets/", sizeof ("/assets/") - 1) == 0) + if (o3tl::starts_with(filePath, "/assets/")) { OString aData; bool bCache = true; - const char *cpAssetsPath = cpFilePath + sizeof("/assets/") - 1; + const char *cpAssetsPath = filePath.getStr() + sizeof("/assets/") - 1; // some requests are /assets//foo... if (cpAssetsPath[0] == '/') { - __android_log_print(ANDROID_LOG_DEBUG,"libo:sal/osl/unx/file", "double-slash in path: %s", cpFilePath); + __android_log_print(ANDROID_LOG_DEBUG,"libo:sal/osl/unx/file", "double-slash in path: %s", filePath.getStr()); cpAssetsPath++; } @@ -922,7 +920,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, if (pMiss) { errno = ENOENT; - __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "miss cache: failed to open %s", cpFilePath); + __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "miss cache: failed to open %s", filePath.getStr()); return osl_File_E_NOENT; } AAssetManager* mgr = lo_get_native_assetmgr(); @@ -931,7 +929,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, { AndroidFileCache::getMissCache().insert(cpAssetsPath, aData); errno = ENOENT; - __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", cpFilePath); + __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", filePath.getStr()); return osl_File_E_NOENT; } else @@ -957,9 +955,9 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, // loading a document from /assets fails with that idiotic // "General Error" dialog... } - SAL_INFO("sal.file", "osl_openFile(" << cpFilePath << ") => '" << cpAssetsPath << "'" + SAL_INFO("sal.file", "osl_openFile(" << filePath << ") => '" << cpAssetsPath << "'" << aData.getLength() << " bytes from file " << (bCache ? "cache" : "system")); - return openMemoryAsFile(aData, pHandle, cpFilePath); + return openMemoryAsFile(aData, pHandle, filePath); } #endif @@ -997,7 +995,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, } else { - flags = osl_file_adjustLockFlags (cpFilePath, flags); + flags = osl_file_adjustLockFlags (filePath, flags); } // O_EXCL can be set only when O_CREAT is set @@ -1005,7 +1003,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, flags &= ~O_EXCL; /* open the file */ - int fd = open_c( cpFilePath, flags, mode ); + int fd = open_c( filePath, flags, mode ); if (fd == -1) { return oslTranslateFileError(errno); @@ -1059,7 +1057,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, if (!S_ISREG(aFileStat.st_mode)) { /* we only open regular files here */ - SAL_INFO("sal.file", "osl_openFile(" << cpFilePath << "): not a regular file"); + SAL_INFO("sal.file", "osl_openFile(" << filePath << "): not a regular file"); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); return osl_File_E_INVAL; @@ -1107,7 +1105,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, } /* allocate memory for impl structure */ - FileHandle_Impl *pImpl = new FileHandle_Impl(fd, FileHandle_Impl::KIND_FD, cpFilePath); + FileHandle_Impl *pImpl = new FileHandle_Impl(fd, FileHandle_Impl::KIND_FD, filePath); if (flags & O_RDWR) pImpl->m_state |= State::Writeable; diff --git a/sal/osl/unx/file_impl.hxx b/sal/osl/unx/file_impl.hxx index 06b9e5f6001e..9ab44ef55fd2 100644 --- a/sal/osl/unx/file_impl.hxx +++ b/sal/osl/unx/file_impl.hxx @@ -23,6 +23,7 @@ #include <osl/file.h> #include <stddef.h> #include <sys/types.h> +#include <rtl/string.hxx> struct DirectoryItem_Impl { @@ -48,7 +49,7 @@ oslFileError openFile( mode_t mode); oslFileError openFilePath( - const char *cpFilePath, + const OString& filePath, oslFileHandle* pHandle, sal_uInt32 uFlags, mode_t mode ); diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx index eaa902839428..0aff1e469e04 100644 --- a/sal/osl/unx/uunxapi.cxx +++ b/sal/osl/unx/uunxapi.cxx @@ -361,16 +361,16 @@ int osl::mkdir(const OString& path, mode_t mode) return result; } -int open_c(const char *cpPath, int oflag, int mode) +int open_c(const OString& path, int oflag, int mode) { accessFilePathState *state = prepare_to_access_file_path(cpPath); - int result = open(cpPath, oflag, mode); + int result = open(path.getStr(), oflag, mode); int saved_errno = errno; if (result == -1) - SAL_INFO("sal.file", "open(" << cpPath << ",0" << std::oct << oflag << ",0" << mode << std::dec << "): " << UnixErrnoString(saved_errno)); + SAL_INFO("sal.file", "open(" << path << ",0" << std::oct << oflag << ",0" << mode << std::dec << "): " << UnixErrnoString(saved_errno)); else - SAL_INFO("sal.file", "open(" << cpPath << ",0" << std::oct << oflag << ",0" << mode << std::dec << ") => " << result); + SAL_INFO("sal.file", "open(" << path << ",0" << std::oct << oflag << ",0" << mode << std::dec << ") => " << result); #if HAVE_FEATURE_MACOSX_SANDBOX if (isSandboxed && result != -1 && (oflag & O_CREAT) && (oflag & O_EXCL)) @@ -399,7 +399,7 @@ int open_c(const char *cpPath, int oflag, int mode) } #endif - done_accessing_file_path(cpPath, state); + done_accessing_file_path(path, state); errno = saved_errno; @@ -417,7 +417,7 @@ int utime_c(const char *cpPath, struct utimbuf *times) return result; } -int ftruncate_with_name(int fd, sal_uInt64 uSize, rtl_String* path) +int ftruncate_with_name(int fd, sal_uInt64 uSize, const OString& path) { /* When sandboxed on macOS, ftruncate(), even if it takes an * already open file descriptor which was returned from an open() diff --git a/sal/osl/unx/uunxapi.hxx b/sal/osl/unx/uunxapi.hxx index b5c0c9ed9d41..9f792765c582 100644 --- a/sal/osl/unx/uunxapi.hxx +++ b/sal/osl/unx/uunxapi.hxx @@ -38,11 +38,11 @@ int lstat_c(const char *cpPath, struct stat* buf); int mkdir_c(OString const & path, mode_t mode); -int open_c(const char *cpPath, int oflag, int mode); +int open_c(const OString& path, int oflag, int mode); int utime_c(const char *cpPath, struct utimbuf *times); -int ftruncate_with_name(int fd, sal_uInt64 uSize, rtl_String* path); +int ftruncate_with_name(int fd, sal_uInt64 uSize, const OString& path); namespace osl { |