1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef INCLUDE_PERFETTO_EXT_BASE_GETOPT_H_ 18 #define INCLUDE_PERFETTO_EXT_BASE_GETOPT_H_ 19 20 // This is the header that should be included in all places that need getopt.h. 21 // This either routes on the sysroot getopt.h, for OSes that have one (all but 22 // Windows) or routes on the home-brewed getopt_compat.h. 23 24 #include "perfetto/base/build_config.h" 25 26 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) 27 #include "perfetto/ext/base/getopt_compat.h" 28 29 // getopt_compat.h puts everything in a nested namespace, to allow 30 // getopt_compat_unittest.cc to use both <getopt.h> and "getopt_compat.h" 31 // without collisions. 32 33 // Here we expose them into the root namespace, because we want offer a drop-in 34 // replacement to the various main.cc, which can't know about the nested 35 // namespace. 36 using ::perfetto::base::getopt_compat::optarg; 37 using ::perfetto::base::getopt_compat::opterr; 38 using ::perfetto::base::getopt_compat::optind; 39 using ::perfetto::base::getopt_compat::option; 40 using ::perfetto::base::getopt_compat::optopt; 41 constexpr auto getopt = ::perfetto::base::getopt_compat::getopt; 42 constexpr auto getopt_long = ::perfetto::base::getopt_compat::getopt_long; 43 constexpr auto no_argument = ::perfetto::base::getopt_compat::no_argument; 44 constexpr auto required_argument = 45 ::perfetto::base::getopt_compat::required_argument; 46 47 #else 48 #include <getopt.h> 49 #endif 50 51 #endif // INCLUDE_PERFETTO_EXT_BASE_GETOPT_H_ 52