diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-10-18 14:30:42 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-10-19 14:43:05 +0200 |
commit | 22a2ed832bae50f85a254f0604d375aeca207c9e (patch) | |
tree | d4269487c15685fc1dd8a20319ba89169f79c2e8 /sal/osl/unx/file_misc.cxx | |
parent | 9a373521d7a328197a4bf9abeb0a981b7acba896 (diff) |
Introduce UnixErrnoString() and use it in sal/osl/unx
The UnixErrnoString() function returns the symbolic name of an errno
value, like "ENOENT". For now this is local to sal/osl/unx.
If it can't figure out the symbolic name, it returns it as a number
followed by the cleartext description (as from strerror()) in
parentheses.
Rationale why to use this and not strerror(): This is intended to be
used in SAL_INFO() and SAL_WARN(). Such messages are intended to be
read by developers, not end-users. Developers are (or should be)
familiar with symbolic errno names in code anyway. The symbolic names
of errno values are (or should be) instantly recognizable as such,
they all start with E and are in UPPERCASE.
strerror() can be localised although in LibreOffice it apparently
isn't as there allegedly aren't setlocale() calls. But, anyway, the
error strings might be less familiar to a developer than the symbolc
errno names that one uses when coding.
When encountering an unfamiliar error string the developer might want
to add special handling for that error case in the code. They would
need a reverse mapping from error string to errno value, by manually
searching <errno.h>, looking at the comments there, hoping the match
what strerror() produces, to find the corresponding symbolic errno
value.
Change-Id: Idc11595d528e8432a32bf474e6791f4ea7262a1e
Reviewed-on: https://gerrit.libreoffice.org/61931
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'sal/osl/unx/file_misc.cxx')
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index a45d32e4c79e..05e72997070b 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -34,6 +34,7 @@ #include "file_url.hxx" #include "uunxapi.hxx" #include "readwrite_helper.hxx" +#include "unixerrnostring.hxx" #include <sys/types.h> #include <errno.h> @@ -217,7 +218,7 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect else { int e = errno; - SAL_INFO("sal.file", "opendir(" << path << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "opendir(" << path << "): " << UnixErrnoString(e)); // Restore errno after possible modification by SAL_INFO above errno = e; } @@ -250,7 +251,7 @@ oslFileError SAL_CALL osl_closeDirectory(oslDirectory pDirectory) if (closedir( pDirImpl->pDirStruct) != 0) { int e = errno; - SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): " << UnixErrnoString(e)); err = oslTranslateFileError(e); } else @@ -470,7 +471,7 @@ oslFileError osl_psz_createDirectory(char const * pszPath, sal_uInt32 flags) if ( nRet < 0 ) { nRet=errno; - SAL_INFO("sal.file", "mkdir(" << pszPath << ",0" << std::oct << mode << std::dec << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "mkdir(" << pszPath << ",0" << std::oct << mode << std::dec << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -488,7 +489,7 @@ static oslFileError osl_psz_removeDirectory( const sal_Char* pszPath ) if ( nRet < 0 ) { nRet=errno; - SAL_INFO("sal.file", "rmdir(" << pszPath << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "rmdir(" << pszPath << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -712,7 +713,7 @@ static oslFileError osl_unlinkFile(const sal_Char* pszPath) if (nRet < 0) { nRet=errno; - SAL_INFO("sal.file", "unlink(" << pszPath << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "unlink(" << pszPath << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -730,7 +731,7 @@ static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* ps if (nRet < 0) { nRet=errno; - SAL_INFO("sal.file", "rename(" << pszPath << "," << pszDestPath << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "rename(" << pszPath << "," << pszDestPath << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -820,7 +821,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* { int e = errno; SAL_INFO("sal.file", "rename(" << pszDestFileName << ", " << tmpDestFile - << "): errno " << e << ": " << strerror(e)); + << "): " << UnixErrnoString(e)); if (e == ENOENT) { DestFileExists = 0; @@ -859,7 +860,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* if (unlink(pszDestFileName) != 0) { int e = errno; - SAL_INFO("sal.file", "unlink(" << pszDestFileName << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "unlink(" << pszDestFileName << "): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "unlink(" << pszDestFileName << "): OK"); @@ -868,7 +869,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* { int e = errno; SAL_INFO("sal.file", "rename(" << tmpDestFile << ", " << pszDestFileName - << "): errno " << e << ": " << strerror(e)); + << "): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "rename(" << tmpDestFile << ", " << pszDestFileName << "): OK"); @@ -898,7 +899,7 @@ void attemptChangeMetadata( const sal_Char* pszFileName, mode_t nMode, time_t nA #endif { int e = errno; - SAL_INFO("sal.file", "chmod(" << pszFileName << ",0" << std::oct << nMode << std::dec <<"): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "chmod(" << pszFileName << ",0" << std::oct << nMode << std::dec <<"): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "chmod(" << pszFileName << ",0" << std::oct << nMode << std::dec <<"): OK"); @@ -979,7 +980,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD if ( DestFileFD < 0 ) { nRet=errno; - SAL_INFO("sal.file", "open(" << pszDestFileName << ",O_WRONLY|O_CREAT,0" << std::oct << mode << std::dec << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "open(" << pszDestFileName << ",O_WRONLY|O_CREAT,0" << std::oct << mode << std::dec << "): " << UnixErrnoString(nRet)); osl_closeFile(SourceFileFH); return nRet; } @@ -1023,7 +1024,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD if ( close( DestFileFD ) == -1 ) { int e = errno; - SAL_INFO("sal.file", "close(" << DestFileFD << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "close(" << DestFileFD << "): " << UnixErrnoString(e)); if ( nRet == 0 ) nRet = e; } |