diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2008-07-30 06:29:16 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2008-07-30 06:29:16 +0000 |
| commit | f1f80e7b3b1e17e663113382219d992680461063 (patch) | |
| tree | 793644f4345437ed0c60ace0c5b7fdf07504e661 /cpp/src/qpid/sys | |
| parent | ab27cb344e9d2e1ea18c1c89cda65a02a7513e4b (diff) | |
| download | qpid-python-f1f80e7b3b1e17e663113382219d992680461063.tar.gz | |
Related to QPID-1198: Moved posix platform specific "strerror" code to
platform specific directory
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@680920 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys')
| -rw-r--r-- | cpp/src/qpid/sys/StrError.h | 35 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/posix/StrError.cpp | 44 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/posix/check.h | 3 |
3 files changed, 81 insertions, 1 deletions
diff --git a/cpp/src/qpid/sys/StrError.h b/cpp/src/qpid/sys/StrError.h new file mode 100644 index 0000000000..3843f2abe1 --- /dev/null +++ b/cpp/src/qpid/sys/StrError.h @@ -0,0 +1,35 @@ +#ifndef _sys_StrError_h +#define _sys_StrError_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <string> + +namespace qpid { +namespace sys { + +/** Get the error message for a system number err, e.g. errno. */ +std::string strError(int err); + +}} // namespace qpid + +#endif // _sys_StrError_h diff --git a/cpp/src/qpid/sys/posix/StrError.cpp b/cpp/src/qpid/sys/posix/StrError.cpp new file mode 100644 index 0000000000..deb2fca7eb --- /dev/null +++ b/cpp/src/qpid/sys/posix/StrError.cpp @@ -0,0 +1,44 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/StrError.h" + +// Ensure we get the POSIX verion of strerror_r +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 +#include <string.h> +#undef _XOPEN_SOURCE +#else +#include <string.h> +#endif + + +namespace qpid { +namespace sys { + +std::string strError(int err) { + char buf[512]; + //POSIX strerror_r doesn't return the buffer + ::strerror_r(err, buf, sizeof(buf)); + return std::string(buf); +} + +}} diff --git a/cpp/src/qpid/sys/posix/check.h b/cpp/src/qpid/sys/posix/check.h index 32fdc48077..f3031b7593 100644 --- a/cpp/src/qpid/sys/posix/check.h +++ b/cpp/src/qpid/sys/posix/check.h @@ -23,11 +23,12 @@ */ #include "qpid/Exception.h" + #include <cerrno> #include <assert.h> #include <stdio.h> -#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::strError(ERRNO))) +#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::sys::strError(ERRNO))) /** THROW QPID_POSIX_ERROR(errno) if RESULT is less than zero */ #define QPID_POSIX_CHECK(RESULT) \ |
