1 /* 2 * Copyright (C) 2017 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 _LOG_GETOPT_H_ 18 #define _LOG_GETOPT_H_ 19 20 #ifndef __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 21 #ifndef __ANDROID_API__ 22 #define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1 23 #elif __ANDROID_API__ > 24 /* > Nougat */ 24 #define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1 25 #else 26 #define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 0 27 #endif 28 #endif 29 30 #if __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 31 32 #include <getopt.h> 33 #include <sys/cdefs.h> 34 35 struct getopt_context { 36 int opterr; 37 int optind; 38 int optopt; 39 int optreset; 40 const char* optarg; 41 FILE* optstderr; /* NULL defaults to stderr */ 42 /* private */ 43 const char* place; 44 int nonopt_start; 45 int nonopt_end; 46 int dash_prefix; 47 /* expansion space */ 48 int __extra__; 49 void* __stuff__; 50 }; 51 52 #define EMSG "" 53 #define NO_PREFIX (-1) 54 55 #define INIT_GETOPT_CONTEXT(context) \ 56 context = { 1, 1, '?', 0, NULL, NULL, EMSG, -1, -1, NO_PREFIX, 0, NULL } 57 58 __BEGIN_DECLS 59 int getopt_long_r(int nargc, char* const* nargv, const char* options, 60 const struct option* long_options, int* idx, 61 struct getopt_context* context); 62 63 __END_DECLS 64 65 #endif /* __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE */ 66 67 #endif /* !_LOG_GETOPT_H_ */ 68