summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2020-04-03 16:26:38 +0300
committerTor Lillqvist <tml@collabora.com>2020-04-04 10:40:01 +0200
commit70de006670880df7931fb1c39966d181e2893a61 (patch)
tree2f9906b5cac64ed02bb1985f8aaae19c0b15317c
parentdc3e213dcd81be3eee8d139ea5ad55606a44eeff (diff)
Show flags and modes symbolically in the SAL_INFO() for open() and access()
Change-Id: I0d3f7f7216d35bb6f636797894832a4714bcc388 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91677 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r--sal/osl/unx/file_misc.cxx4
-rw-r--r--sal/osl/unx/uunxapi.cxx8
-rw-r--r--sal/osl/unx/uunxapi.hxx122
3 files changed, 128 insertions, 6 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index f9f316d8b5fb..31dd9157fd29 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -1005,12 +1005,12 @@ static int oslDoCopyFile(const char* pszSourceFileName, const char* pszDestFileN
if ( DestFileFD < 0 )
{
nRet=errno;
- SAL_INFO("sal.file", "open(" << pszDestFileName << ",O_WRONLY|O_CREAT,0" << std::oct << mode << std::dec << "): " << UnixErrnoString(nRet));
+ SAL_INFO("sal.file", "open(" << pszDestFileName << "," << osl::openFlagsToString(O_WRONLY|O_CREAT) << "," << osl::openModeToString(mode) << "): " << UnixErrnoString(nRet));
osl_closeFile(SourceFileFH);
return nRet;
}
else
- SAL_INFO("sal.file", "open(" << pszDestFileName << ",O_WRONLY|O_CREAT,0" << std::oct << mode << std::dec << "): OK");
+ SAL_INFO("sal.file", "open(" << pszDestFileName << "," << osl::openFlagsToString(O_WRONLY|O_CREAT) << "," << osl::openModeToString(mode) << "): OK");
size_t nRemains = nSourceSize;
diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx
index e8901784c878..3c358c8523a8 100644
--- a/sal/osl/unx/uunxapi.cxx
+++ b/sal/osl/unx/uunxapi.cxx
@@ -183,9 +183,9 @@ int osl::access(const OString& pstrPath, int mode)
int result = ::access(fn.getStr(), mode);
int saved_errno = errno;
if (result == -1)
- SAL_INFO("sal.file", "access(" << fn << ",0" << std::oct << mode << std::dec << "): " << UnixErrnoString(saved_errno));
+ SAL_INFO("sal.file", "access(" << fn << "," << osl::accessModeToString(mode) << "): " << UnixErrnoString(saved_errno));
else
- SAL_INFO("sal.file", "access(" << fn << ",0" << std::oct << mode << std::dec << "): OK");
+ SAL_INFO("sal.file", "access(" << fn << "," << osl::accessModeToString(mode) << "): OK");
done_accessing_file_path(fn.getStr(), state);
@@ -360,9 +360,9 @@ int open_c(const char *cpPath, int oflag, int mode)
int result = open(cpPath, 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(" << cpPath << "," << osl::openFlagsToString(oflag) << "," << osl::openModeToString(mode) << "): " << UnixErrnoString(saved_errno));
else
- SAL_INFO("sal.file", "open(" << cpPath << ",0" << std::oct << oflag << ",0" << mode << std::dec << ") => " << result);
+ SAL_INFO("sal.file", "open(" << cpPath << "," << osl::openFlagsToString(oflag) << "," << osl::openModeToString(mode) << ") => " << result);
#if HAVE_FEATURE_MACOSX_SANDBOX
if (isSandboxed && result != -1 && (oflag & O_CREAT) && (oflag & O_EXCL))
diff --git a/sal/osl/unx/uunxapi.hxx b/sal/osl/unx/uunxapi.hxx
index f182b755e53b..867443b45746 100644
--- a/sal/osl/unx/uunxapi.hxx
+++ b/sal/osl/unx/uunxapi.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_SAL_OSL_UNX_UUNXAPI_HXX
#define INCLUDED_SAL_OSL_UNX_UUNXAPI_HXX
+#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -72,6 +73,127 @@ namespace osl
int lstat(const OString& strPath, struct stat& buf);
int mkdir(const OString& aPath, mode_t aMode);
+
+ inline OString openFlagsToString(int flags)
+ {
+ OString result;
+ switch (flags & O_ACCMODE)
+ {
+ case O_RDONLY:
+ result = "O_RDONLY";
+ break;
+ case O_WRONLY:
+ result = "O_WRONLY";
+ break;
+ break;
+ case O_RDWR:
+ result = "O_RDWR";
+ break;
+ }
+ if (flags & O_CREAT)
+ result += "|O_CREAT";
+ if (flags & O_EXCL)
+ result += "|O_EXCL";
+ if (flags & O_NOCTTY)
+ result += "|O_NOCTTY";
+ if (flags & O_TRUNC)
+ result += "|O_TRUNC";
+ if (flags & O_NONBLOCK)
+ result += "|O_NONBLOCK";
+ if (flags & O_NONBLOCK)
+ result += "|O_NONBLOCK";
+ if ((flags & O_SYNC) == O_SYNC)
+ result += "|O_SYNC";
+ if (flags & O_ASYNC)
+ result += "|O_ASYNC";
+
+#if defined __O_LARGEFILE
+ if (flags & __O_LARGEFILE)
+ result += "|O_LARGEFILE";
+#endif
+
+#if defined __O_DIRECTORY
+ if (flags & __O_DIRECTORY)
+ result += "|O_DIRECTORY";
+#elif defined O_DIRECTORY
+ if (flags & O_DIRECTORY)
+ result += "|O_DIRECTORY";
+#endif
+
+#if defined __O_NOFOLLOW
+ if (flags & __O_NOFOLLOW)
+ result += "|O_NOFOLLOW";
+#elif defined O_NOFOLLOW
+ if (flags & O_NOFOLLOW)
+ result += "|O_NOFOLLOW";
+#endif
+
+#if defined __O_CLOEXEC
+ if (flags & __O_CLOEXEC)
+ result += "|O_CLOEXEC";
+#elif defined O_CLOEXEC
+ if (flags & O_CLOEXEC)
+ result += "|O_CLOEXEC";
+#endif
+
+#if defined __O_DIRECT
+ if (flags & __O_DIRECT)
+ result += "|O_DIRECT";
+#endif
+
+#if defined __O_NOATIME
+ if (flags & __O_NOATIME)
+ result += "|O_NOATIME";
+#endif
+
+#if defined __O_PATH
+ if (flags & __O_PATH)
+ result += "|O_PATH";
+#endif
+
+#if defined __O_DSYNC
+ if (flags & __O_DSYNC)
+ result += "|O_DSYNC";
+#endif
+
+#if defined __O_TMPFILE
+ if ((flags & __O_TMPFILE) == __O_TMPFILE)
+ result += "|O_TMPFILE";
+#endif
+
+ return result;
+ }
+
+ inline OString openModeToString(int mode)
+ {
+ if (mode == 0)
+ return "0";
+ else
+ return "0" + OString::number(mode, 8);
+ }
+
+ inline OString accessModeToString(int mode)
+ {
+ if (mode == F_OK)
+ return "F_OK";
+ OString result;
+ if (mode & R_OK)
+ result = "R_OK";
+ if (mode & W_OK)
+ {
+ if (!result.isEmpty())
+ result += "|";
+ result += "W_OK";
+ }
+ if (mode & X_OK)
+ {
+ if (!result.isEmpty())
+ result += "|";
+ result += "X_OK";
+ }
+ return result;
+ }
+
} // end namespace osl
#endif // INCLUDED_SAL_OSL_UNX_UUNXAPI_HXX