1 /* Copyright (C) 2010-2018 The RetroArch team 2 * 3 * --------------------------------------------------------------------------------------- 4 * The following license statement only applies to this file (getopt.h). 5 * --------------------------------------------------------------------------------------- 6 * 7 * Permission is hereby granted, free of charge, 8 * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation the rights to 10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef __LIBRETRO_SDK_COMPAT_GETOPT_H 24 #define __LIBRETRO_SDK_COMPAT_GETOPT_H 25 26 #if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H) 27 #include "../../../config.h" 28 #endif 29 30 /* Custom implementation of the GNU getopt_long for portability. 31 * Not designed to be fully compatible, but compatible with 32 * the features RetroArch uses. */ 33 34 #ifdef HAVE_GETOPT_LONG 35 #include <getopt.h> 36 #else 37 /* Avoid possible naming collisions during link since we 38 * prefer to use the actual name. */ 39 #define getopt_long(argc, argv, optstring, longopts, longindex) __getopt_long_retro(argc, argv, optstring, longopts, longindex) 40 41 #include <retro_common_api.h> 42 43 RETRO_BEGIN_DECLS 44 45 struct option 46 { 47 const char *name; 48 int has_arg; 49 int *flag; 50 int val; 51 }; 52 53 /* argv[] is declared with char * const argv[] in GNU, 54 * but this makes no sense, as non-POSIX getopt_long 55 * mutates argv (non-opts are moved to the end). */ 56 int getopt_long(int argc, char *argv[], 57 const char *optstring, const struct option *longopts, int *longindex); 58 extern char *optarg; 59 extern int optind, opterr, optopt; 60 61 RETRO_END_DECLS 62 63 /* If these are variously #defined, then we have bigger problems */ 64 #ifndef no_argument 65 #define no_argument 0 66 #define required_argument 1 67 #define optional_argument 2 68 #endif 69 70 /* HAVE_GETOPT_LONG */ 71 #endif 72 73 /* pragma once */ 74 #endif 75 76