diff --git a/doc/index.html b/doc/index.html index f6eb28e..3e7b50f 100644 --- a/doc/index.html +++ b/doc/index.html @@ -43,6 +43,22 @@ Acknowledgements + + + Headers + + + + <boost/system/error_code.hpp>
+ + <boost/system/system_error.hpp>
+ + <boost/system/cygwin_error.hpp>
+ + <boost/system/linux_error.hpp>
+ + <boost/system/windows_error.hpp> +

Introduction

@@ -73,6 +89,10 @@ than via throwing exceptions. Otherwise, when errors are not exceptional occurrences and must be dealt with as they arise, programs become littered with try/catch blocks, unreadable, and very inefficient. The Boost System library supports both error reporting by exception and by error code.

+

In addition to portable errors codes and conditions supported by the +error_code.hpp header, system-specific headers support the Cygwin, Linux, +and Windows platforms. These headers are effectively no-ops if included for +platforms other than their intended target.

Design Rationale

Class error_code  and error_condition are designed as a value types so they can be copied @@ -117,7 +137,7 @@ Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt

Revised -September 14, 2007 +November 12, 2007

diff --git a/doc/reference.html b/doc/reference.html index 23d16a7..21b8489 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -38,6 +38,7 @@ Introduction
+ Macros
Header <boost/system/error_code.hpp>
Class error_category
   Class error_category synopsis
@@ -68,8 +69,51 @@

This reference documentation describes components that  programs may use to report error conditions originating from the operating system or other low-level application program interfaces.

-

System Library components do not change the value of +

Boost.System library components never change the value of errno.

+

Macros

+

Users may defined the following macros if desired. Sensible defaults are +provided, so users may ignore these macros if they prefer.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Macro NameDefaultEffect if defined
BOOST_WINDOWS_APIDefined if Windows is detected by Boost.System's automatic configuration + code, otherwise not defined.Implementation uses the Microsoft Windows native + application program interface (API).
BOOST_POSIX_APIDefined if Windows is not detected by Boost.System's automatic configuration + code.Implementation uses the POSIX native + application program interface (API).
BOOST_SYSTEM_DYN_LINKDefined if BOOST_ALL_DYN_LINK is defined, + otherwise not defined.Boost.System library is dynamically linked. If not defined, + static linking is assumed.
BOOST_SYSTEM_NO_LIBDefined if BOOST_ALL_NO_LIB is defined, + otherwise not defined.Boost.System library does not use the Boost auto-link + facility.
BOOST_SYSTEM_NO_DEPRECATEDNot defined.Deprecated features are excluded.

Header <boost/system/error_code.hpp>

<boost/system/error_code.hpp> synopsis

@@ -699,7 +743,7 @@ Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt

Revised -October 23, 2007 +November 12, 2007

diff --git a/include/boost/system/cygwin_error.hpp b/include/boost/system/cygwin_error.hpp new file mode 100644 index 0000000..15be3a6 --- /dev/null +++ b/include/boost/system/cygwin_error.hpp @@ -0,0 +1,56 @@ +// boost/system/cygwin_error.hpp -------------------------------------------// + +// Copyright Beman Dawes 2007 + +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See library home page at http://www.boost.org/libs/system + +#ifndef BOOST_CYGWIN_ERROR_HPP +#define BOOST_CYGWIN_ERROR_HPP + +// This header is effectively empty for compiles on operating systems where +// it is not applicable. + +# ifdef __CYGWIN__ + +#include + +namespace boost +{ + namespace system + { + // To construct an error_code after a API error: + // + // error_code( errno, system_category ) + + // User code should use the portable "posix" enums for POSIX errors; this + // allows such code to be portable to non-POSIX systems. For the non-POSIX + // errno values that POSIX-based systems typically provide in addition to + // POSIX values, use the system specific enums below. + + namespace cygwin_error + { + enum cygwin_errno + { + no_net = ENONET, + no_package = ENOPKG, + no_share = ENOSHARE + }; + } // namespace cygwin_error + + template<> struct is_error_code_enum + { static const bool value = true; }; + + namespace cygwin_error + { + inline error_code make_error_code( cygwin_errno e ) + { return error_code( e, system_category ); } + } + } +} + +#endif // __CYGWIN__ + +#endif // BOOST_CYGWIN_ERROR_HPP diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 3d333b1..df14fde 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -25,9 +25,9 @@ // TODO: undef these macros if not already defined #include -# ifdef BOOST_WINDOWS_API -# include -# endif +#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API) +# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined +#endif #include // must be the last #include @@ -143,6 +143,39 @@ namespace boost template<> struct is_error_condition_enum { static const bool value = true; }; + + // ----------------------------------------------------------------------// + + // Operating system specific interfaces --------------------------------// + + + // The interface is divided into general and system-specific portions to + // meet these requirements: + // + // * Code calling an operating system API can create an error_code with + // a single category (system_category), even for POSIX-like operating + // systems that return some POSIX errno values and some native errno + // values. This code should not have to pay the cost of distinguishing + // between categories, since it is not yet known if that is needed. + // + // * Users wishing to write system-specific code should be given enums for + // at least the common error cases. + // + // * System specific code should fail at compile time if moved to another + // operating system. + + // The system specific portions of the interface are located in headers + // with names reflecting the operating system. For example, + // + // + // + // + // + // These headers are effectively empty for compiles on operating systems + // where they are not applicable. + + // ----------------------------------------------------------------------// + // class error_category ------------------------------------------------// class error_category : public noncopyable @@ -448,230 +481,6 @@ namespace boost return s; } - // ----------------------------------------------------------------------// - - // Operating system specific interfaces --------------------------------// - - - // The interface is divided into general and system-specific portions to - // meet these requirements: - // - // * Code calling an operating system API can create an error_code with - // a single category (system_category), even for POSIX-like operating - // systems that return some POSIX errno values and some native errno - // values. This code should not have to pay the cost of distinguishing - // between categories, since it is not yet known if that is needed. - // - // * Users wishing to write system-specific code should be given enums for - // at least the common error cases. - // - // * System specific code should fail at compile time if moved to another - // operating system. - -#ifdef BOOST_POSIX_API - - // POSIX-based systems -------------------------------------------------// - - // To construct an error_code after a API error: - // - // error_code( errno, system_category ) - - // User code should use the portable "posix" enums for POSIX errors; this - // allows such code to be portable to non-POSIX systems. For the non-POSIX - // errno values that POSIX-based systems typically provide in addition to - // POSIX values, use the system specific enums below. - -# ifdef __CYGWIN__ - - namespace cygwin_error - { - enum cygwin_errno - { - no_net = ENONET, - no_package = ENOPKG, - no_share = ENOSHARE - }; - } // namespace cygwin_error - - template<> struct is_error_code_enum - { static const bool value = true; }; - - namespace cygwin_error - { - inline error_code make_error_code( cygwin_errno e ) - { return error_code( e, system_category ); } - } - -# elif defined(linux) || defined(__linux) || defined(__linux__) - - namespace linux_error - { - enum linux_errno - { - advertise_error = EADV, - bad_exchange = EBADE, - bad_file_number = EBADFD, - bad_font_format = EBFONT, - bad_request_code = EBADRQC, - bad_request_descriptor = EBADR, - bad_slot = EBADSLT, - channel_range = ECHRNG, - communication_error = ECOMM, - dot_dot_error = EDOTDOT, - exchange_full = EXFULL, - host_down = EHOSTDOWN, - is_named_file_type= EISNAM, - key_expired = EKEYEXPIRED, - key_rejected = EKEYREJECTED, - key_revoked = EKEYREVOKED, - level2_halt= EL2HLT, - level2_no_syncronized= EL2NSYNC, - level3_halt = EL3HLT, - level3_reset = EL3RST, - link_range = ELNRNG, - medium_type = EMEDIUMTYPE, - no_anode= ENOANO, - no_block_device = ENOTBLK, - no_csi = ENOCSI, - no_key = ENOKEY, - no_medium = ENOMEDIUM, - no_network = ENONET, - no_package = ENOPKG, - not_avail = ENAVAIL, - not_named_file_type= ENOTNAM, - not_recoverable = ENOTRECOVERABLE, - not_unique = ENOTUNIQ, - owner_dead = EOWNERDEAD, - protocol_no_supported = EPFNOSUPPORT, - remote_address_changed = EREMCHG, - remote_io_error = EREMOTEIO, - remote_object = EREMOTE, - restart_needed = ERESTART, - shared_library_access = ELIBACC, - shared_library_bad = ELIBBAD, - shared_library_execute = ELIBEXEC, - shared_library_max_ = ELIBMAX, - shared_library_section= ELIBSCN, - shutdown = ESHUTDOWN, - socket_type_not_supported = ESOCKTNOSUPPORT, - srmount_error = ESRMNT, - stream_pipe_error = ESTRPIPE, - too_many_references = ETOOMANYREFS, - too_many_users = EUSERS, - unattached = EUNATCH, - unclean = EUCLEAN - }; - } // namespace linux_error - -# ifndef BOOST_SYSTEM_NO_DEPRECATED - namespace Linux = linux_error; -# endif - - template<> struct is_error_code_enum - { static const bool value = true; }; - - namespace linux_error - { - inline error_code make_error_code( linux_errno e ) - { return error_code( e, system_category ); } - } - -# endif - - // TODO: Add more POSIX-based operating systems here - - -#elif defined(BOOST_WINDOWS_API) - - // Microsoft Windows ---------------------------------------------------// - - // To construct an error_code after a API error: - // - // error_code( ::GetLastError(), system_category ) - - namespace windows_error - { - enum windows_error_code - { - success = 0, - // These names and values are based on Windows winerror.h - invalid_function = ERROR_INVALID_FUNCTION, - file_not_found = ERROR_FILE_NOT_FOUND, - path_not_found = ERROR_PATH_NOT_FOUND, - too_many_open_files = ERROR_TOO_MANY_OPEN_FILES, - access_denied = ERROR_ACCESS_DENIED, - invalid_handle = ERROR_INVALID_HANDLE, - arena_trashed = ERROR_ARENA_TRASHED, - not_enough_memory = ERROR_NOT_ENOUGH_MEMORY, - invalid_block = ERROR_INVALID_BLOCK, - bad_environment = ERROR_BAD_ENVIRONMENT, - bad_format = ERROR_BAD_FORMAT, - invalid_access = ERROR_INVALID_ACCESS, - outofmemory = ERROR_OUTOFMEMORY, - invalid_drive = ERROR_INVALID_DRIVE, - current_directory = ERROR_CURRENT_DIRECTORY, - not_same_device = ERROR_NOT_SAME_DEVICE, - no_more_files = ERROR_NO_MORE_FILES, - write_protect = ERROR_WRITE_PROTECT, - bad_unit = ERROR_BAD_UNIT, - not_ready = ERROR_NOT_READY, - bad_command = ERROR_BAD_COMMAND, - crc = ERROR_CRC, - bad_length = ERROR_BAD_LENGTH, - seek = ERROR_SEEK, - not_dos_disk = ERROR_NOT_DOS_DISK, - sector_not_found = ERROR_SECTOR_NOT_FOUND, - out_of_paper = ERROR_OUT_OF_PAPER, - write_fault = ERROR_WRITE_FAULT, - read_fault = ERROR_READ_FAULT, - gen_failure = ERROR_GEN_FAILURE, - sharing_violation = ERROR_SHARING_VIOLATION, - lock_violation = ERROR_LOCK_VIOLATION, - wrong_disk = ERROR_WRONG_DISK, - sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED, - handle_eof = ERROR_HANDLE_EOF, - handle_disk_full= ERROR_HANDLE_DISK_FULL, - rem_not_list = ERROR_REM_NOT_LIST, - dup_name = ERROR_DUP_NAME, - bad_net_path = ERROR_BAD_NETPATH, - network_busy = ERROR_NETWORK_BUSY, - // ... - file_exists = ERROR_FILE_EXISTS, - cannot_make = ERROR_CANNOT_MAKE, - // ... - broken_pipe = ERROR_BROKEN_PIPE, - open_failed = ERROR_OPEN_FAILED, - buffer_overflow = ERROR_BUFFER_OVERFLOW, - disk_full= ERROR_DISK_FULL, - // ... - lock_failed = ERROR_LOCK_FAILED, - busy = ERROR_BUSY, - cancel_violation = ERROR_CANCEL_VIOLATION, - already_exists = ERROR_ALREADY_EXISTS - // ... - - // TODO: add more Windows errors - }; - - } // namespace windows - -# ifndef BOOST_SYSTEM_NO_DEPRECATED - namespace windows = windows_error; -# endif - - template<> struct is_error_code_enum - { static const bool value = true; }; - - namespace windows_error - { - inline error_code make_error_code( windows_error_code e ) - { return error_code( e, system_category ); } - } - -#else -# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined -#endif - } // namespace system } // namespace boost diff --git a/include/boost/system/linux_error.hpp b/include/boost/system/linux_error.hpp new file mode 100644 index 0000000..2e5d475 --- /dev/null +++ b/include/boost/system/linux_error.hpp @@ -0,0 +1,110 @@ +// boost/system/linux_error.hpp -------------------------------------------// + +// Copyright Beman Dawes 2007 + +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See library home page at http://www.boost.org/libs/system + +#ifndef BOOST_LINUX_ERROR_HPP +#define BOOST_LINUX_ERROR_HPP + +// This header is effectively empty for compiles on operating systems where +// it is not applicable. + +#if defined(linux) || defined(__linux) || defined(__linux__) + +#include + +namespace boost +{ + namespace system + { + // To construct an error_code after a API error: + // + // error_code( errno, system_category ) + + // User code should use the portable "posix" enums for POSIX errors; this + // allows such code to be portable to non-POSIX systems. For the non-POSIX + // errno values that POSIX-based systems typically provide in addition to + // POSIX values, use the system specific enums below. + + namespace linux_error + { + enum linux_errno + { + advertise_error = EADV, + bad_exchange = EBADE, + bad_file_number = EBADFD, + bad_font_format = EBFONT, + bad_request_code = EBADRQC, + bad_request_descriptor = EBADR, + bad_slot = EBADSLT, + channel_range = ECHRNG, + communication_error = ECOMM, + dot_dot_error = EDOTDOT, + exchange_full = EXFULL, + host_down = EHOSTDOWN, + is_named_file_type= EISNAM, + key_expired = EKEYEXPIRED, + key_rejected = EKEYREJECTED, + key_revoked = EKEYREVOKED, + level2_halt= EL2HLT, + level2_no_syncronized= EL2NSYNC, + level3_halt = EL3HLT, + level3_reset = EL3RST, + link_range = ELNRNG, + medium_type = EMEDIUMTYPE, + no_anode= ENOANO, + no_block_device = ENOTBLK, + no_csi = ENOCSI, + no_key = ENOKEY, + no_medium = ENOMEDIUM, + no_network = ENONET, + no_package = ENOPKG, + not_avail = ENAVAIL, + not_named_file_type= ENOTNAM, + not_recoverable = ENOTRECOVERABLE, + not_unique = ENOTUNIQ, + owner_dead = EOWNERDEAD, + protocol_no_supported = EPFNOSUPPORT, + remote_address_changed = EREMCHG, + remote_io_error = EREMOTEIO, + remote_object = EREMOTE, + restart_needed = ERESTART, + shared_library_access = ELIBACC, + shared_library_bad = ELIBBAD, + shared_library_execute = ELIBEXEC, + shared_library_max_ = ELIBMAX, + shared_library_section= ELIBSCN, + shutdown = ESHUTDOWN, + socket_type_not_supported = ESOCKTNOSUPPORT, + srmount_error = ESRMNT, + stream_pipe_error = ESTRPIPE, + too_many_references = ETOOMANYREFS, + too_many_users = EUSERS, + unattached = EUNATCH, + unclean = EUCLEAN + }; + } // namespace linux_error + +# ifndef BOOST_SYSTEM_NO_DEPRECATED + namespace Linux = linux_error; +# endif + + template<> struct is_error_code_enum + { static const bool value = true; }; + + namespace linux_error + { + inline error_code make_error_code( linux_errno e ) + { return error_code( e, system_category ); } + } + + } // namespace system +} // namespace boost + +#endif // Linux + +#endif // BOOST_LINUX_ERROR_HPP diff --git a/include/boost/system/windows_error.hpp b/include/boost/system/windows_error.hpp new file mode 100644 index 0000000..2fb212e --- /dev/null +++ b/include/boost/system/windows_error.hpp @@ -0,0 +1,118 @@ +// boost/system/windows_error.hpp ------------------------------------------// + +// Copyright Beman Dawes 2007 + +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See library home page at http://www.boost.org/libs/system + +#ifndef BOOST_WINDOWS_ERROR_HPP +#define BOOST_WINDOWS_ERROR_HPP + +// This header is effectively empty for compiles on operating systems where +// it is not applicable. + +#include + +#ifdef BOOST_WINDOWS_API + +#include +#include + +namespace boost +{ + namespace system + { + + // Microsoft Windows ---------------------------------------------------// + + // To construct an error_code after a API error: + // + // error_code( ::GetLastError(), system_category ) + + namespace windows_error + { + enum windows_error_code + { + success = 0, + // These names and values are based on Windows winerror.h + invalid_function = ERROR_INVALID_FUNCTION, + file_not_found = ERROR_FILE_NOT_FOUND, + path_not_found = ERROR_PATH_NOT_FOUND, + too_many_open_files = ERROR_TOO_MANY_OPEN_FILES, + access_denied = ERROR_ACCESS_DENIED, + invalid_handle = ERROR_INVALID_HANDLE, + arena_trashed = ERROR_ARENA_TRASHED, + not_enough_memory = ERROR_NOT_ENOUGH_MEMORY, + invalid_block = ERROR_INVALID_BLOCK, + bad_environment = ERROR_BAD_ENVIRONMENT, + bad_format = ERROR_BAD_FORMAT, + invalid_access = ERROR_INVALID_ACCESS, + outofmemory = ERROR_OUTOFMEMORY, + invalid_drive = ERROR_INVALID_DRIVE, + current_directory = ERROR_CURRENT_DIRECTORY, + not_same_device = ERROR_NOT_SAME_DEVICE, + no_more_files = ERROR_NO_MORE_FILES, + write_protect = ERROR_WRITE_PROTECT, + bad_unit = ERROR_BAD_UNIT, + not_ready = ERROR_NOT_READY, + bad_command = ERROR_BAD_COMMAND, + crc = ERROR_CRC, + bad_length = ERROR_BAD_LENGTH, + seek = ERROR_SEEK, + not_dos_disk = ERROR_NOT_DOS_DISK, + sector_not_found = ERROR_SECTOR_NOT_FOUND, + out_of_paper = ERROR_OUT_OF_PAPER, + write_fault = ERROR_WRITE_FAULT, + read_fault = ERROR_READ_FAULT, + gen_failure = ERROR_GEN_FAILURE, + sharing_violation = ERROR_SHARING_VIOLATION, + lock_violation = ERROR_LOCK_VIOLATION, + wrong_disk = ERROR_WRONG_DISK, + sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED, + handle_eof = ERROR_HANDLE_EOF, + handle_disk_full= ERROR_HANDLE_DISK_FULL, + rem_not_list = ERROR_REM_NOT_LIST, + dup_name = ERROR_DUP_NAME, + bad_net_path = ERROR_BAD_NETPATH, + network_busy = ERROR_NETWORK_BUSY, + // ... + file_exists = ERROR_FILE_EXISTS, + cannot_make = ERROR_CANNOT_MAKE, + // ... + broken_pipe = ERROR_BROKEN_PIPE, + open_failed = ERROR_OPEN_FAILED, + buffer_overflow = ERROR_BUFFER_OVERFLOW, + disk_full= ERROR_DISK_FULL, + // ... + lock_failed = ERROR_LOCK_FAILED, + busy = ERROR_BUSY, + cancel_violation = ERROR_CANCEL_VIOLATION, + already_exists = ERROR_ALREADY_EXISTS + // ... + + // TODO: add more Windows errors + }; + + } // namespace windows + +# ifndef BOOST_SYSTEM_NO_DEPRECATED + namespace windows = windows_error; +# endif + + template<> struct is_error_code_enum + { static const bool value = true; }; + + namespace windows_error + { + inline error_code make_error_code( windows_error_code e ) + { return error_code( e, system_category ); } + } + + } // namespace system +} // namespace boost + +#endif // BOOST_WINDOWS_API + +#endif // BOOST_WINDOWS_ERROR_HPP diff --git a/test/system_error_test.cpp b/test/system_error_test.cpp index 27fec0a..4cbdbd0 100644 --- a/test/system_error_test.cpp +++ b/test/system_error_test.cpp @@ -42,7 +42,7 @@ namespace BOOST_CHECK( ex.code().category() == system_category ); # ifdef BOOST_WINDOWS_API LANGID language_id; -# ifndef __MINGW32__ +# if !defined(__MINGW32__) && !defined(__CYGWIN__) language_id = ::GetUserDefaultUILanguage(); # else language_id = 0x0409; // Assume US English