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.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.cxx')
-rw-r--r-- | sal/osl/unx/file.cxx | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index ae1bc31c9069..9f888579e3a9 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -33,6 +33,7 @@ #include "file_impl.hxx" #include "file_url.hxx" #include "uunxapi.hxx" +#include "unixerrnostring.hxx" #include <algorithm> #include <cassert> @@ -257,7 +258,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize) if (nCurPos == off_t(-1)) { int e = errno; - SAL_INFO("sal.file", "lseek(" << m_fd << ",0,SEEK_CUR): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "lseek(" << m_fd << ",0,SEEK_CUR): " << UnixErrnoString(e)); return result; } else @@ -267,7 +268,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize) if (lseek(m_fd, static_cast<off_t>(nSize - 1), SEEK_SET) == -1) { int e = errno; - SAL_INFO("sal.file", "lseek(" << m_fd << "," << nSize - 1 << ",SEEK_SET): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "lseek(" << m_fd << "," << nSize - 1 << ",SEEK_SET): " << UnixErrnoString(e)); return result; } else @@ -277,7 +278,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize) { /* Failure. Restore saved position */ int e = errno; - SAL_INFO("sal.file", "write(" << m_fd << ",\"\",1): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "write(" << m_fd << ",\"\",1): " << UnixErrnoString(e)); (void) lseek(m_fd, nCurPos, SEEK_SET); return result; } @@ -912,7 +913,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (f == -1) { int e = errno; - SAL_INFO("sal.file", "fcntl(" << fd << ",F_GETFL,0): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fcntl(" << fd << ",F_GETFL,0): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -924,7 +925,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (fcntl(fd, F_SETFL, (f & ~O_NONBLOCK)) == -1) { int e = errno; - SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETFL,(f & ~O_NONBLOCK)): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETFL,(f & ~O_NONBLOCK)): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -940,7 +941,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (fstat(fd, &aFileStat) == -1) { int e = errno; - SAL_INFO("sal.file", "fstat(" << fd << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fstat(" << fd << "): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -964,7 +965,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (flock(fd, LOCK_EX | LOCK_NB) == -1) { int e = errno; - SAL_INFO("sal.file", "flock(" << fd << ",LOCK_EX|LOCK_NB): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "flock(" << fd << ",LOCK_EX|LOCK_NB): " << UnixErrnoString(e)); /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */ // Restore errno after possibly having been overwritten by the SAL_INFO above... @@ -990,7 +991,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (fcntl(fd, F_SETLK, &aflock) == -1) { int e = errno; - SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETLK): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETLK): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -1070,7 +1071,7 @@ oslFileError SAL_CALL osl_closeFile(oslFileHandle Handle) else if (close(pImpl->m_fd) == -1) { int e = errno; - SAL_INFO("sal.file", "close(" << pImpl->m_fd << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "close(" << pImpl->m_fd << "): " << UnixErrnoString(e)); /* translate error code */ result = oslTranslateFileError(e); } @@ -1102,7 +1103,7 @@ oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle) if (fsync(pImpl->m_fd) == -1) { int e = errno; - SAL_INFO("sal.file", "fsync(" << pImpl->m_fd << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fsync(" << pImpl->m_fd << "): " << UnixErrnoString(e)); return oslTranslateFileError(e); } else @@ -1204,7 +1205,7 @@ oslFileError SAL_CALL osl_mapFile( #elif defined __sun if (madvise(static_cast< caddr_t >(p), nLength, MADV_WILLNEED) != 0) - SAL_INFO("sal.file", "madvise(..., MADV_WILLNEED) failed with " << strerror(errno)); + SAL_INFO("sal.file", "madvise(..., MADV_WILLNEED) failed with " << UnixErrnoString(errno)); #endif } |