1274955Ssvnmir//===- llvm/Support/Errc.h - Defines the llvm::errc enum --------*- C++ -*-===//
2274955Ssvnmir//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6274955Ssvnmir//
7274955Ssvnmir//===----------------------------------------------------------------------===//
8274955Ssvnmir//
9274955Ssvnmir// While std::error_code works OK on all platforms we use, there are some
10274955Ssvnmir// some problems with std::errc that can be avoided by using our own
11274955Ssvnmir// enumeration:
12274955Ssvnmir//
13274955Ssvnmir// * std::errc is a namespace in some implementations. That meas that ADL
14274955Ssvnmir//   doesn't work and it is sometimes necessary to write std::make_error_code
15274955Ssvnmir//   or in templates:
16274955Ssvnmir//   using std::make_error_code;
17274955Ssvnmir//   make_error_code(...);
18274955Ssvnmir//
19274955Ssvnmir//   with this enum it is safe to always just use make_error_code.
20274955Ssvnmir//
21274955Ssvnmir// * Some implementations define fewer names than others. This header has
22274955Ssvnmir//   the intersection of all the ones we support.
23274955Ssvnmir//
24274955Ssvnmir// * std::errc is just marked with is_error_condition_enum. This means that
25274955Ssvnmir//   common patters like AnErrorCode == errc::no_such_file_or_directory take
26274955Ssvnmir//   4 virtual calls instead of two comparisons.
27274955Ssvnmir//===----------------------------------------------------------------------===//
28274955Ssvnmir
29274955Ssvnmir#ifndef LLVM_SUPPORT_ERRC_H
30274955Ssvnmir#define LLVM_SUPPORT_ERRC_H
31274955Ssvnmir
32274955Ssvnmir#include <system_error>
33274955Ssvnmir
34274955Ssvnmirnamespace llvm {
35274955Ssvnmirenum class errc {
36274955Ssvnmir  argument_list_too_long = int(std::errc::argument_list_too_long),
37274955Ssvnmir  argument_out_of_domain = int(std::errc::argument_out_of_domain),
38274955Ssvnmir  bad_address = int(std::errc::bad_address),
39274955Ssvnmir  bad_file_descriptor = int(std::errc::bad_file_descriptor),
40274955Ssvnmir  broken_pipe = int(std::errc::broken_pipe),
41274955Ssvnmir  device_or_resource_busy = int(std::errc::device_or_resource_busy),
42274955Ssvnmir  directory_not_empty = int(std::errc::directory_not_empty),
43274955Ssvnmir  executable_format_error = int(std::errc::executable_format_error),
44274955Ssvnmir  file_exists = int(std::errc::file_exists),
45274955Ssvnmir  file_too_large = int(std::errc::file_too_large),
46274955Ssvnmir  filename_too_long = int(std::errc::filename_too_long),
47274955Ssvnmir  function_not_supported = int(std::errc::function_not_supported),
48274955Ssvnmir  illegal_byte_sequence = int(std::errc::illegal_byte_sequence),
49274955Ssvnmir  inappropriate_io_control_operation =
50274955Ssvnmir      int(std::errc::inappropriate_io_control_operation),
51274955Ssvnmir  interrupted = int(std::errc::interrupted),
52274955Ssvnmir  invalid_argument = int(std::errc::invalid_argument),
53274955Ssvnmir  invalid_seek = int(std::errc::invalid_seek),
54274955Ssvnmir  io_error = int(std::errc::io_error),
55274955Ssvnmir  is_a_directory = int(std::errc::is_a_directory),
56274955Ssvnmir  no_child_process = int(std::errc::no_child_process),
57274955Ssvnmir  no_lock_available = int(std::errc::no_lock_available),
58274955Ssvnmir  no_space_on_device = int(std::errc::no_space_on_device),
59274955Ssvnmir  no_such_device_or_address = int(std::errc::no_such_device_or_address),
60274955Ssvnmir  no_such_device = int(std::errc::no_such_device),
61274955Ssvnmir  no_such_file_or_directory = int(std::errc::no_such_file_or_directory),
62274955Ssvnmir  no_such_process = int(std::errc::no_such_process),
63274955Ssvnmir  not_a_directory = int(std::errc::not_a_directory),
64274955Ssvnmir  not_enough_memory = int(std::errc::not_enough_memory),
65341825Sdim  not_supported = int(std::errc::not_supported),
66274955Ssvnmir  operation_not_permitted = int(std::errc::operation_not_permitted),
67274955Ssvnmir  permission_denied = int(std::errc::permission_denied),
68274955Ssvnmir  read_only_file_system = int(std::errc::read_only_file_system),
69274955Ssvnmir  resource_deadlock_would_occur = int(std::errc::resource_deadlock_would_occur),
70274955Ssvnmir  resource_unavailable_try_again =
71274955Ssvnmir      int(std::errc::resource_unavailable_try_again),
72274955Ssvnmir  result_out_of_range = int(std::errc::result_out_of_range),
73274955Ssvnmir  too_many_files_open_in_system = int(std::errc::too_many_files_open_in_system),
74274955Ssvnmir  too_many_files_open = int(std::errc::too_many_files_open),
75274955Ssvnmir  too_many_links = int(std::errc::too_many_links)
76274955Ssvnmir};
77274955Ssvnmir
78274955Ssvnmirinline std::error_code make_error_code(errc E) {
79274955Ssvnmir  return std::error_code(static_cast<int>(E), std::generic_category());
80274955Ssvnmir}
81274955Ssvnmir}
82274955Ssvnmir
83274955Ssvnmirnamespace std {
84274955Ssvnmirtemplate <> struct is_error_code_enum<llvm::errc> : std::true_type {};
85274955Ssvnmir}
86274955Ssvnmir#endif
87